PageRenderTime 24ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/documentation/examples/umil_manual_example.php

https://github.com/phpbb/umil
PHP | 176 lines | 100 code | 29 blank | 47 comment | 9 complexity | cce6b65bd46ede61708951e51ab2edd1 MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. * @author Username (Joe Smith) joesmith@example.org
  5. * @package umil
  6. * @copyright (c) 2008 phpBB Group
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /*
  11. * This is only an example of an install/update file using the manual method of UMIL.
  12. * You should probably use the umil_auto method unless you are willing to handle installation, uninstallation, and updating yourself
  13. *
  14. * This does exactly the same thing as umil_auto_example, but does not have the uninstall or version selection options
  15. */
  16. /**
  17. * @ignore
  18. */
  19. define('IN_PHPBB', true);
  20. $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
  21. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  22. include($phpbb_root_path . 'common.' . $phpEx);
  23. // Start session management
  24. $user->session_begin();
  25. $auth->acl($user->data);
  26. $user->setup('mods/umil_auto_example');
  27. if (!file_exists($phpbb_root_path . 'umil/umil.' . $phpEx))
  28. {
  29. trigger_error('Please download the latest UMIL (Unified MOD Install Library) from: <a href="http://www.phpbb.com/mods/umil/">phpBB.com/mods/umil</a>', E_USER_ERROR);
  30. }
  31. // We only allow a founder install this MOD
  32. if ($user->data['user_type'] != USER_FOUNDER)
  33. {
  34. if ($user->data['user_id'] == ANONYMOUS)
  35. {
  36. login_box('', 'LOGIN');
  37. }
  38. trigger_error('NOT_AUTHORISED');
  39. }
  40. if (!class_exists('umil'))
  41. {
  42. include($phpbb_root_path . 'umil/umil.' . $phpEx);
  43. }
  44. // If you want a completely stand alone version (able to use UMIL without messing with any of the language stuff) send true, otherwise send false
  45. $umil = new umil(true);
  46. if (confirm_box(true))
  47. {
  48. // Install the base 0.3.0 version
  49. if (!$umil->config_exists('test_version'))
  50. {
  51. // Lets add a config setting named test_enable and set it to true
  52. $umil->config_add('test_enable', true);
  53. // We must handle the version number ourselves.
  54. $umil->config_add('test_version', '0.3.0');
  55. }
  56. switch ($config['test_version'])
  57. {
  58. // Update to 0.3.1
  59. case '0.3.0' :
  60. // Now to add some permission settings. Showing both the one at a time and "multicall" options
  61. $umil->permission_add('a_test_mod', true);
  62. $umil->permission_add(array(
  63. array('f_test_mod', false),
  64. array('u_test_mod', true),
  65. ));
  66. // How about we give some default permissions then as well?
  67. $umil->permission_set(array(
  68. // Global Role permissions
  69. array('ROLE_ADMIN_FULL', 'a_test_mod'),
  70. array('ROLE_USER_FULL', 'u_test_mod'),
  71. // Global Group permissions
  72. array('GUESTS', 'u_test_mod', 'group'),
  73. // Local Permissions
  74. array('ROLE_FORUM_STANDARD', 'f_test_mod'),
  75. ));
  76. // No breaks
  77. // Update to 0.7.0
  78. case '0.3.1' :
  79. // Lets change our test_enable to false
  80. $umil->config_update('test_enable', false);
  81. // Lets remove some of those permission settings we added before
  82. $umil->permission_remove(array(
  83. array('f_test_mod', false),
  84. array('u_test_mod', true),
  85. ));
  86. // Now to add a table (this uses the layout from develop/create_schema_files.php and from phpbb_db_tools)
  87. $umil->table_add('phpbb_test', array(
  88. 'COLUMNS' => array(
  89. 'test_id' => array('UINT', NULL, 'auto_increment'),
  90. 'test_text' => array('VCHAR_UNI', ''),
  91. 'test_bool' => array('BOOL', 0),
  92. ),
  93. 'PRIMARY_KEY' => 'test_id',
  94. 'KEYS' => array(
  95. 'test_bool' => array('INDEX', 'test_bool'),
  96. ),
  97. ));
  98. // Update to 0.9.0
  99. case '0.7.0' :
  100. // Lets add a new column to the phpbb_test table named test_time
  101. $umil->table_column_add('phpbb_test', 'test_time', array('TIMESTAMP', 0));
  102. // Lets make the test_time column we just added an index
  103. $umil->table_index_add('phpbb_test', 'test_time', 'test_time');
  104. // Alright, now lets add some modules to the ACP
  105. $umil->module_add(array(
  106. // First, lets add a new category named ACP_CAT_TEST_MOD to ACP_CAT_DOT_MODS
  107. array('acp', 'ACP_CAT_DOT_MODS', 'ACP_CAT_TEST_MOD'),
  108. // Now we will add the settings and features modes from the acp_board module to the ACP_CAT_TEST_MOD category using the "automatic" method.
  109. array('acp', 'ACP_CAT_TEST_MOD', array(
  110. 'module_basename' => 'board',
  111. 'modes' => array('settings', 'features'),
  112. ),
  113. ),
  114. // Now we will add the avatar mode from acp_board to the ACP_CAT_TEST_MOD category using the "manual" method.
  115. array('acp', 'ACP_CAT_TEST_MOD', array(
  116. 'module_basename' => 'board',
  117. 'module_langname' => 'ACP_AVATAR_SETTINGS',
  118. 'module_mode' => 'avatar',
  119. 'module_auth' => 'acl_a_board',
  120. ),
  121. ),
  122. ));
  123. // Update to 0.9.1
  124. case '0.9.0' :
  125. // This is done in the custom function from umil_auto_example
  126. $sql_ary = array(
  127. 'test_text' => 'This is a test message.',
  128. 'test_bool' => 1,
  129. 'test_time' => time(),
  130. );
  131. $sql = 'INSERT INTO ' . $table_prefix . 'test ' . $db->sql_build_array('INSERT', $sql_ary);
  132. $db->sql_query($sql);
  133. // Update to 1.0.0
  134. case '0.9.1' :
  135. }
  136. // We must handle the version number ourselves.
  137. $umil->config_update('test_version', '1.0.0');
  138. // We are done
  139. trigger_error('Done!');
  140. }
  141. else
  142. {
  143. confirm_box(false, 'INSTALL_TEST_MOD');
  144. }
  145. // Shouldn't get here.
  146. redirect($phpbb_root_path . $user->page['page_name']);
  147. ?>