PageRenderTime 27ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/dbtech/vbactivity/includes/class_install.php

https://gitlab.com/elasa/vb-elasa.ir
PHP | 270 lines | 142 code | 39 blank | 89 comment | 17 complexity | c6661ed3699bafbbffda169ad9f85c85 MD5 | raw file
  1. <?php
  2. /*======================================================================*\
  3. || #################################################################### ||
  4. || # ---------------------------------------------------------------- # ||
  5. || # Copyright ©2013 Fillip Hannisdal AKA Revan/NeoRevan/Belazor # ||
  6. || # All Rights Reserved. # ||
  7. || # This file may not be redistributed in whole or significant part. # ||
  8. || # ---------------------------------------------------------------- # ||
  9. || # You are not allowed to use this on your server unless the files # ||
  10. || # you downloaded were done so with permission. # ||
  11. || # ---------------------------------------------------------------- # ||
  12. || #################################################################### ||
  13. \*======================================================================*/
  14. @set_time_limit(0);
  15. ignore_user_abort(1);
  16. // #############################################################################
  17. // Core installer class
  18. /**
  19. * Handles everything to do with Activity.
  20. */
  21. class DBTech_Install
  22. {
  23. /**
  24. * The vB_Database_Alter_MySQL object
  25. *
  26. * @public vB_Database_Alter_MySQL
  27. */
  28. protected static $db_alter = NULL;
  29. /**
  30. * The vB_Registry object
  31. *
  32. * @public vB_Registry
  33. */
  34. protected static $vbulletin = NULL;
  35. /**
  36. * The vB_Database object
  37. *
  38. * @public vB_Database
  39. */
  40. protected static $db = NULL;
  41. /**
  42. * Path to the installer files
  43. *
  44. * @protected string
  45. */
  46. protected static $installpath = '';
  47. /**
  48. * Product ID
  49. *
  50. * @protected string
  51. */
  52. protected static $productid = '';
  53. protected static $hightrafficengine = '';
  54. /**
  55. * Initialises the installer and ensures we have
  56. * all the classes we need
  57. *
  58. * @param string Path to the installer files
  59. * @param string Product ID we are setting
  60. */
  61. public static function init($installpath, $productid = '')
  62. {
  63. global $db, $vbulletin;
  64. if (!is_dir($installpath))
  65. {
  66. // Wrong install path
  67. self::error($installpath . ' is not a directory. Please upload all files that came with the product.');
  68. }
  69. // Install path is valid
  70. self::$installpath = $installpath;
  71. if (!file_exists(DIR . '/includes/xml/bitfield_' . $productid . '.xml') AND $productid)
  72. {
  73. // Missing bitfields
  74. self::error('bitfield_' . $productid . '.xml not found in directory ' . DIR . '/includes/xml/');
  75. }
  76. // Get the high concurrency table engine (innodb support check)
  77. self::get_high_concurrency_table_engine($db);
  78. // Grab the DBAlter class
  79. require_once(DIR . '/includes/class_dbalter.php');
  80. // Set some important variables
  81. self::$db_alter = new vB_Database_Alter_MySQL($db);
  82. self::$db =& $db;
  83. self::$vbulletin =& $vbulletin;
  84. self::$productid = $productid;
  85. }
  86. /**
  87. * Installs / Upgrades to a version
  88. *
  89. * @param integer Version number to install
  90. * @param string Textual representation of the version
  91. */
  92. public static function install($version, $fullversion)
  93. {
  94. global $vbulletin, $code, $arr;
  95. // To avoid any h4x0rz
  96. //$version = intval($version);
  97. if (!file_exists(self::$installpath . '/' . $version . '.php'))
  98. {
  99. // Missing version file
  100. self::error($version . '.php not found in directory ' . self::$installpath);
  101. }
  102. // Run the install
  103. self::report('<strong>Updating Version Number To</strong>:', $fullversion, 'finalise');
  104. echo '<ul>';
  105. require_once(self::$installpath . '/' . $version . '.php');
  106. echo '</ul>';
  107. if (self::$productid)
  108. {
  109. $shortname = self::$productid;
  110. require_once(DIR . '/includes/class_bitfield_builder.php');
  111. if (vB_Bitfield_Builder::build(false) !== false)
  112. {
  113. $myobj =& vB_Bitfield_Builder::init();
  114. $myobj->data = $myobj->fetch(DIR . '/includes/xml/bitfield_' . $shortname . '.xml', false, true);
  115. }
  116. else
  117. {
  118. echo "<strong>error</strong>\n";
  119. print_r(vB_Bitfield_Builder::fetch_errors());
  120. }
  121. $groupinfo = array();
  122. foreach ((array)$myobj->data['ugp']["{$shortname}permissions"] AS $permtitle => $permvalue)
  123. {
  124. if (empty($permvalue['group']))
  125. {
  126. continue;
  127. }
  128. if (!empty($permvalue['install']))
  129. {
  130. foreach ($permvalue['install'] AS $gid)
  131. {
  132. $groupinfo["$gid"]["{$shortname}permissions"] += $permvalue['value'];
  133. }
  134. }
  135. }
  136. foreach ($groupinfo as $usergroupid => $permissions)
  137. {
  138. $perms = $permissions["{$shortname}permissions"];
  139. self::$db->query_write("
  140. UPDATE " . TABLE_PREFIX . "usergroup
  141. SET {$shortname}permissions = $perms
  142. WHERE usergroupid = $usergroupid
  143. ");
  144. }
  145. build_forum_permissions();
  146. }
  147. // Update settings
  148. build_options();
  149. vBulletinHook::build_datastore(self::$db);
  150. }
  151. /**
  152. * Uninstalls the product
  153. */
  154. public static function uninstall()
  155. {
  156. if (!file_exists(self::$installpath . '/uninstall.php'))
  157. {
  158. // Missing version file
  159. self::error('uninstall.php not found in directory ' . self::$installpath);
  160. }
  161. echo '<ul>';
  162. require_once(self::$installpath . '/uninstall.php');
  163. echo '</ul>';
  164. }
  165. /**
  166. * Print out an informational notice
  167. *
  168. * @param string What we were doing
  169. * @param string What the action returned
  170. * @param string What type of message we are printing
  171. */
  172. public static function report($action, $message, $type = 'action')
  173. {
  174. if ($type == 'action')
  175. {
  176. // During install
  177. echo '<li><strong>' . $action . ':</strong> <em>' . TABLE_PREFIX . $message . '</em></li>';
  178. }
  179. else
  180. {
  181. // Finalise
  182. echo '<p>' . $action . ' ' . $message . '</p>';
  183. }
  184. vbflush();
  185. usleep(500000);
  186. }
  187. /**
  188. * Something went boom, print a message.
  189. *
  190. * @param string Error message
  191. */
  192. public static function error($message = '')
  193. {
  194. print_dots_stop();
  195. print_cp_message('<strong>Installation Failed</strong><br />Sorry, the product encountered an error during installation. More information is provided below to help address the issue.<br /><br />' . $message);
  196. }
  197. /**
  198. * Determine if we can use InnoDB
  199. *
  200. * @param string Error message
  201. */
  202. public static function get_high_concurrency_table_engine($db)
  203. {
  204. if (self::$hightrafficengine)
  205. {
  206. return self::$hightrafficengine;
  207. }
  208. if (defined('SKIPDB'))
  209. {
  210. self::$hightrafficengine = 'MyISAM';
  211. return self::$hightrafficengine;
  212. }
  213. $set = $db->query('SHOW ENGINES');
  214. while ($row = $db->fetch_array($set))
  215. {
  216. if (
  217. strcasecmp($row['Engine'], 'innodb') == 0 AND
  218. (
  219. (strcasecmp($row['Support'], 'yes') == 0) OR
  220. (strcasecmp($row['Support'], 'default') == 0)
  221. )
  222. )
  223. {
  224. self::$hightrafficengine = 'InnoDB';
  225. return self::$hightrafficengine;
  226. }
  227. }
  228. self::$hightrafficengine = 'MyISAM';
  229. return self::$hightrafficengine;
  230. }
  231. }