PageRenderTime 56ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/e107_admin/update_routines.php

https://github.com/CasperGemini/e107
PHP | 1904 lines | 1261 code | 261 blank | 382 comment | 170 complexity | fc71cb72f37def5cde5ddf149c4ebfd4 MD5 | raw file
Possible License(s): GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. + ----------------------------------------------------------------------------+
  4. | e107 website system
  5. |
  6. | Copyright (C) 2008-2010 e107 Inc (e107.org)
  7. | http://e107.org
  8. |
  9. |
  10. | Released under the terms and conditions of the
  11. | GNU General Public License (http://gnu.org).
  12. |
  13. | $URL$
  14. | $Revision$
  15. | $Id$
  16. | $Author$
  17. +----------------------------------------------------------------------------+
  18. */
  19. /**
  20. * @package e107
  21. * @subpackage admin
  22. * @version $Id$;
  23. *
  24. * Update routines from older e107 versions to current.
  25. *
  26. * Also links to plugin update routines.
  27. *
  28. * 2-stage process - routines identify whether update is required, and then execute as instructed.
  29. */
  30. // [debug=8] shows the operations on major table update
  31. require_once('../class2.php');
  32. require_once(e_HANDLER.'db_table_admin_class.php');
  33. include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_e107_update.php');
  34. // Modified update routine - combines checking and update code into one block per function
  35. // - reduces code size typically 30%.
  36. // - keeping check and update code together should improve clarity/reduce mis-types etc
  37. // @todo: how do we handle update of multi-language tables?
  38. // If following line uncommented, enables a test routine
  39. // define('TEST_UPDATE',TRUE);
  40. $update_debug = TRUE; // TRUE gives extra messages in places
  41. //$update_debug = TRUE; // TRUE gives extra messages in places
  42. if (defined('TEST_UPDATE')) $update_debug = TRUE;
  43. if (!defined('LAN_UPDATE_8')) { define('LAN_UPDATE_8', ''); }
  44. if (!defined('LAN_UPDATE_9')) { define('LAN_UPDATE_9', ''); }
  45. // Determine which installed plugins have an update file - save the path and the installed version in an array
  46. $dbupdateplugs = array(); // Array of paths to installed plugins which have a checking routine
  47. $dbupdatep = array(); // Array of plugin upgrade actions (similar to $dbupdate)
  48. $dbupdate = array(); // Array of core upgrade actions
  49. global $e107cache;
  50. if (is_readable(e_ADMIN.'ver.php'))
  51. {
  52. include(e_ADMIN.'ver.php');
  53. }
  54. $mes = e107::getMessage();
  55. // If $dont_check_update is both defined and TRUE on entry, a check for update is done only once per 24 hours.
  56. $dont_check_update = varset($dont_check_update, FALSE);
  57. if ($dont_check_update === TRUE)
  58. {
  59. $dont_check_update = FALSE;
  60. if ($tempData = $e107cache->retrieve_sys('nq_admin_updatecheck',3600, TRUE))
  61. { // See when we last checked for an admin update
  62. list($last_time, $dont_check_update, $last_ver) = explode(',',$tempData);
  63. if ($last_ver != $e107info['e107_version'])
  64. {
  65. $dont_check_update = FALSE; // Do proper check on version change
  66. }
  67. }
  68. }
  69. if (!$dont_check_update)
  70. {
  71. /*
  72. if ($sql->db_Select('plugin', 'plugin_id, plugin_version, plugin_path', 'plugin_installflag=1'))
  73. {
  74. while ($row = $sql->db_Fetch())
  75. { // Mark plugins for update which have a specific update file, or a plugin.php file to check
  76. if(is_readable(e_PLUGIN.$row['plugin_path'].'/'.$row['plugin_path'].'_update_check.php') || is_readable(e_PLUGIN.$row['plugin_path'].'/plugin.php') || is_readable(e_PLUGIN.$row['plugin_path'].'/'.$row['plugin_path'].'_setup.php'))
  77. {
  78. $dbupdateplugs[$row['plugin_path']] = $row['plugin_version'];
  79. //TODO - Add support for {plugins}_setup.php upgrade check and routine.
  80. }
  81. }
  82. }
  83. */
  84. if($dbupdateplugs = e107::getConfig('core')->get('plug_installed'))
  85. {
  86. // Read in each update file - this will add an entry to the $dbupdatep array if a potential update exists
  87. foreach ($dbupdateplugs as $path => $ver)
  88. {
  89. if(!is_file(e_PLUGIN.$path."/plugin.xml"))
  90. {
  91. $fname = e_PLUGIN.$path.'/'.$path.'_update_check.php'; // DEPRECATED - left for BC only.
  92. if (is_readable($fname)) include_once($fname);
  93. }
  94. $fname = e_PLUGIN.$path.'/'.$path.'_setup.php';
  95. if (is_readable($fname))
  96. {
  97. $dbupdatep[$path] = $path ; // ' 0.7.x forums '.LAN_UPDATE_9.' 0.8 forums';
  98. include_once($fname);
  99. }
  100. }
  101. }
  102. // List of potential updates
  103. if (defined('TEST_UPDATE'))
  104. {
  105. $dbupdate['test_code'] = 'Test update routine';
  106. }
  107. // set 'master' to true to prevent other upgrades from running before it is complete.
  108. $dbupdate['706_to_800'] = array('master'=>true, 'title'=>LAN_UPDATE_8.' 1.x '.LAN_UPDATE_9.' 2.0','message'=> LAN_UPDATE_29);
  109. $dbupdate['core_prefs'] = array('master'=>true, 'title'=>LAN_UPDATE_13); // Prefs check
  110. // $dbupdate['70x_to_706'] = LAN_UPDATE_8.' .70x '.LAN_UPDATE_9.' .706';
  111. } // End if (!$dont_check_update)
  112. // New in v2.x ------------------------------------------------
  113. class e107Update
  114. {
  115. var $core = array();
  116. var $updates = 0;
  117. var $disabled = 0;
  118. function __construct($core=null)
  119. {
  120. $mes = e107::getMessage();
  121. $this->core = $core;
  122. if(varset($_POST['update_core']) && is_array($_POST['update_core']))
  123. {
  124. $func = key($_POST['update_core']);
  125. $message = $this->updateCore($func);
  126. }
  127. if(varset($_POST['update']) && is_array($_POST['update'])) // Do plugin updates
  128. {
  129. $func = key($_POST['update']);
  130. $this->updatePlugin($func);
  131. }
  132. if(vartrue($message))
  133. {
  134. $mes->addSuccess($message);
  135. }
  136. $this->renderForm();
  137. }
  138. function updateCore($func='')
  139. {
  140. $mes = e107::getMessage();
  141. // foreach($this->core as $func => $data)
  142. // {
  143. if(function_exists('update_'.$func)) // Legacy Method.
  144. {
  145. $installed = call_user_func("update_".$func);
  146. //?! (LAN_UPDATE == $_POST[$func])
  147. if(varsettrue($_POST['update_core'][$func]) && !$installed)
  148. {
  149. if(function_exists("update_".$func))
  150. {
  151. $message = LAN_UPDATE_7." ".$data['title'];
  152. $error = call_user_func("update_".$func, "do");
  153. if($error != '')
  154. {
  155. $mes->add($message, E_MESSAGE_ERROR);
  156. $mes->add($error, E_MESSAGE_ERROR);
  157. }
  158. else
  159. {
  160. $mes->add($message, E_MESSAGE_SUCCESS);
  161. }
  162. }
  163. }
  164. }
  165. else
  166. {
  167. $mes->addDebug("could run 'update_".$func);
  168. }
  169. //}
  170. }
  171. function updatePlugin($path)
  172. {
  173. e107::getPlugin()->install_plugin_xml($path, 'upgrade');
  174. }
  175. function plugins()
  176. {
  177. if(!$list = e107::getPlugin()->updateRequired())
  178. {
  179. return;
  180. }
  181. $frm = e107::getForm();
  182. $text = "";
  183. foreach($list as $path=>$val)
  184. {
  185. $text .= "<tr>
  186. <td>".$val['@attributes']['name']."</td>
  187. <td>".$frm->admin_button('update['.$path.']', LAN_UPDATE, 'warning', '', 'disabled='.$this->disabled)."</td>
  188. </tr>";
  189. }
  190. return $text;
  191. }
  192. function core()
  193. {
  194. $frm = e107::getForm();
  195. $mes = e107::getMessage();
  196. $text = "";
  197. foreach($this->core as $func => $data)
  198. {
  199. if(function_exists("update_".$func))
  200. {
  201. $text .= "<tr><td>".$data['title']."</td>";
  202. if(call_user_func("update_".$func))
  203. {
  204. $text .= "<td>".ADMIN_TRUE_ICON."</td>";
  205. }
  206. else
  207. {
  208. if(vartrue($data['message']))
  209. {
  210. $mes->addInfo($data['message']);
  211. }
  212. $this->updates ++;
  213. $text .= "<td>".$frm->admin_button('update_core['.$func.']', LAN_UPDATE, 'warning', '', "id=e-{$func}&disabled=".$this->disabled)."</td>";
  214. if($data['master'] == true)
  215. {
  216. $this->disabled = 1;
  217. }
  218. }
  219. $text .= "</tr>\n";
  220. }
  221. }
  222. return $text;
  223. }
  224. function renderForm()
  225. {
  226. $ns = e107::getRender();
  227. $mes = e107::getMessage();
  228. $caption = LAN_UPDATE;
  229. $text = "
  230. <form method='post' action='".e_SELF."'>
  231. <fieldset id='core-e107-update'>
  232. <legend>{$caption}</legend>
  233. <table class='table adminlist'>
  234. <colgroup>
  235. <col style='width: 60%' />
  236. <col style='width: 40%' />
  237. </colgroup>
  238. <thead>
  239. <tr>
  240. <th>".LAN_UPDATE_55."</th>
  241. <th class='last'>".LAN_UPDATE_2."</th>
  242. </tr>
  243. </thead>
  244. <tbody>
  245. ";
  246. $text .= $this->core();
  247. $text .= $this->plugins();
  248. $text .= "
  249. </tbody>
  250. </table>
  251. </fieldset>
  252. </form>
  253. ";
  254. $ns->tablerender("Updates",$mes->render() . $text);
  255. }
  256. }
  257. /**
  258. * Master routine to call to check for updates
  259. */
  260. function update_check()
  261. {
  262. $ns = e107::getRender();
  263. $e107cache = e107::getCache();
  264. $sql = e107::getDb();
  265. $mes = e107::getMessage();
  266. global $dont_check_update, $e107info;
  267. global $dbupdate, $dbupdatep, $e107cache;
  268. $update_needed = FALSE;
  269. if ($dont_check_update === FALSE)
  270. {
  271. foreach($dbupdate as $func => $rmks) // See which core functions need update
  272. {
  273. if (function_exists('update_'.$func))
  274. {
  275. if (!call_user_func('update_'.$func, FALSE))
  276. {
  277. $update_needed = TRUE;
  278. break;
  279. }
  280. }
  281. }
  282. // Now check plugins - XXX DEPRECATED
  283. foreach($dbupdatep as $func => $rmks)
  284. {
  285. if (function_exists('update_'.$func))
  286. {
  287. if (!call_user_func('update_'.$func, FALSE))
  288. {
  289. $update_needed = TRUE;
  290. break;
  291. }
  292. }
  293. }
  294. // New in v2.x
  295. if(e107::getPlugin()->updateRequired('boolean'))
  296. {
  297. $update_needed = TRUE;
  298. }
  299. // $e107cache->set_sys('nq_admin_updatecheck', time().','.($update_needed ? '2,' : '1,').$e107info['e107_version'], TRUE);
  300. }
  301. else
  302. {
  303. $update_needed = ($dont_check_update == '2');
  304. }
  305. if ($update_needed === TRUE)
  306. {
  307. $frm = e107::getForm();
  308. $txt = "
  309. <form method='post' action='".e_ADMIN_ABS."e107_update.php'>
  310. <div>
  311. ".ADLAN_120."
  312. ".$frm->admin_button('e107_system_update', LAN_UPDATE, 'other')."
  313. </div>
  314. </form>
  315. ";
  316. $mes->addInfo($txt);
  317. }
  318. }
  319. //XXX to be reworked eventually - for checking remote 'new versions' of plugins and installed theme.
  320. // require_once(e_HANDLER.'e_upgrade_class.php');
  321. // $upg = new e_upgrade;
  322. // $upg->checkSiteTheme();
  323. // $upg->checkAllPlugins();
  324. //--------------------------------------------
  325. // Check current prefs against latest list
  326. //--------------------------------------------
  327. function update_core_prefs($type='')
  328. {
  329. global $e107info; // $pref, $pref must be kept as global
  330. $pref = e107::getConfig('core', true, true)->getPref();
  331. $admin_log = e107::getAdminLog();
  332. $do_save = FALSE;
  333. $should = get_default_prefs();
  334. $just_check = $type == 'do' ? FALSE : TRUE; // TRUE if we're just seeing if an update is needed
  335. foreach ($should as $k => $v)
  336. {
  337. if ($k && !array_key_exists($k,$pref))
  338. {
  339. if ($just_check) return update_needed('Missing pref: '.$k);
  340. $pref[$k] = $v;
  341. $admin_log->logMessage($k.' => '.$v, E_MESSAGE_NODISPLAY, E_MESSAGE_INFO);
  342. $do_save = TRUE;
  343. }
  344. }
  345. if ($do_save)
  346. {
  347. //save_prefs();
  348. e107::getConfig('core')->setPref($pref)->save();
  349. $admin_log->logMessage(LAN_UPDATE_14.$e107info['e107_version'], E_MESSAGE_NODISPLAY, E_MESSAGE_INFO);
  350. $admin_log->flushMessages('UPDATE_03',E_LOG_INFORMATIVE);
  351. //$admin_log->log_event('UPDATE_03',LAN_UPDATE_14.$e107info['e107_version'].'[!br!]'.implode(', ',$accum),E_LOG_INFORMATIVE,''); // Log result of actual update
  352. }
  353. return $just_check;
  354. }
  355. if (defined('TEST_UPDATE'))
  356. {
  357. //--------------------------------------------
  358. // Test routine - to activate, define TEST_UPDATE
  359. //--------------------------------------------
  360. function update_test_code($type='')
  361. {
  362. global $sql,$ns, $pref;
  363. $just_check = $type == 'do' ? FALSE : TRUE; // TRUE if we're just seeing whether an update is needed
  364. //--------------**************---------------
  365. // Add your test code in here
  366. //--------------**************---------------
  367. //--------------**************---------------
  368. // End of test code
  369. //--------------**************---------------
  370. return $just_check;
  371. }
  372. } // End of test routine
  373. //--------------------------------------------
  374. // Upgrade later versions of 0.7.x to 0.8
  375. //--------------------------------------------
  376. function update_706_to_800($type='')
  377. {
  378. global $pref, $e107info;
  379. global $sysprefs, $eArrayStorage;
  380. //$mes = new messageLog; // Combined logging and message displaying handler
  381. //$mes = e107::getMessage();
  382. $log = e107::getAdminLog(); // Used for combined logging and message displaying
  383. $sql = e107::getDb();
  384. $sql2 = e107::getDb('sql2');
  385. $tp = e107::getParser();
  386. $ns = e107::getRender();
  387. e107::getCache()->clearAll('db');
  388. e107::getCache()->clearAll('system');
  389. // List of unwanted $pref values which can go
  390. $obs_prefs = array('frontpage_type','rss_feeds', 'log_lvcount', 'zone', 'upload_allowedfiletype', 'real', 'forum_user_customtitle',
  391. 'utf-compatmode','frontpage_method','standards_mode','image_owner','im_quality', 'signup_option_timezone',
  392. 'modules', 'plug_sc', 'plug_bb', 'plug_status', 'plug_latest', 'subnews_hide_news', 'upload_storagetype'
  393. );
  394. // List of DB tables not required (includes a few from 0.6xx)
  395. $obs_tables = array('flood', 'headlines', 'stat_info', 'stat_counter', 'stat_last', 'session', 'preset', 'tinymce');
  396. // List of DB tables newly required (defined in core_sql.php) (The existing dblog table gets renamed)
  397. // No Longer required. - automatically checked against core_sql.php.
  398. // $new_tables = array('audit_log', 'dblog', 'news_rewrite', 'core_media', 'core_media_cat','cron', 'mail_recipients', 'mail_content');
  399. // List of core prefs that need to be converted from serialized to e107ArrayStorage.
  400. $serialized_prefs = array("'emote'", "'menu_pref'", "'search_prefs'", "'emote_default'", "'pm_prefs'");
  401. $create_dir = array(e_MEDIA,e_SYSTEM,e_CACHE,e_CACHE_CONTENT,e_CACHE_IMAGE, e_CACHE_DB, e_LOG, e_BACKUP, e_CACHE_URL, e_TEMP, e_IMPORT);
  402. foreach($create_dir as $dr)
  403. {
  404. if(!is_dir($dr))
  405. {
  406. mkdir($dr, 0755);
  407. }
  408. }
  409. // List of changed DB tables (defined in core_sql.php)
  410. // No Longer required. - automatically checked against core_sql.php.
  411. // (primarily those which have changed significantly; for the odd field write some explicit code - it'll run faster)
  412. // $changed_tables = array('user', 'dblog', 'admin_log', 'userclass_classes', 'banlist', 'menus',
  413. // 'plugin', 'news', 'news_category', 'online', 'page', 'links', 'comments');
  414. // List of changed DB tables from core plugins (defined in pluginname_sql.php file)
  415. // key = plugin directory name. Data = comma-separated list of tables to check
  416. // (primarily those which have changed significantly; for the odd field write some explicit code - it'll run faster)
  417. // No Longer required. - automatically checked by db-verify
  418. /* $pluginChangedTables = array('linkwords' => 'linkwords',
  419. 'featurebox' => 'featurebox',
  420. 'links_page' => 'links_page',
  421. 'poll' => 'polls',
  422. 'content' => 'pcontent'
  423. );
  424. */
  425. /*
  426. $setCorePrefs = array( //modified prefs during upgrade.
  427. 'adminstyle' => 'infopanel',
  428. 'admintheme' => 'bootstrap',
  429. 'admincss' => 'admin_style.css',
  430. 'resize_dimensions' => array(
  431. 'news-image' => array('w' => 250, 'h' => 250),
  432. 'news-bbcode' => array('w' => 250, 'h' => 250),
  433. 'page-bbcode' => array('w' => 250, 'h' => 250)
  434. )
  435. );
  436. */
  437. $do_save = TRUE;
  438. // List of changed menu locations.
  439. $changeMenuPaths = array(
  440. array('oldpath' => 'siteinfo_menu', 'newpath' => 'siteinfo', 'menu' => 'sitebutton_menu'),
  441. array('oldpath' => 'siteinfo_menu', 'newpath' => 'siteinfo', 'menu' => 'compliance_menu'),
  442. array('oldpath' => 'siteinfo_menu', 'newpath' => 'siteinfo', 'menu' => 'powered_by_menu'),
  443. array('oldpath' => 'siteinfo_menu', 'newpath' => 'siteinfo', 'menu' => 'sitebutton_menu'),
  444. array('oldpath' => 'siteinfo_menu', 'newpath' => 'siteinfo', 'menu' => 'counter_menu'),
  445. array('oldpath' => 'siteinfo_menu', 'newpath' => 'siteinfo', 'menu' => 'latestnews_menu'),
  446. array('oldpath' => 'compliance_menu', 'newpath' => 'siteinfo', 'menu' => 'compliance_menu'),
  447. array('oldpath' => 'powered_by_menu', 'newpath' => 'siteinfo', 'menu' => 'powered_by_menu'),
  448. array('oldpath' => 'sitebutton_menu', 'newpath' => 'siteinfo', 'menu' => 'sitebutton_menu'),
  449. array('oldpath' => 'counter_menu', 'newpath' => 'siteinfo', 'menu' => 'counter_menu'),
  450. array('oldpath' => 'usertheme_menu', 'newpath' => 'user', 'menu' => 'usertheme_menu'),
  451. array('oldpath' => 'userlanguage_menu', 'newpath' => 'user', 'menu' => 'userlanguage_menu'),
  452. array('oldpath' => 'lastseen_menu', 'newpath' => 'online', 'menu' => 'lastseen_menu'),
  453. array('oldpath' => 'other_news_menu', 'newpath' => 'news', 'menu' => 'other_news_menu'),
  454. array('oldpath' => 'other_news_menu', 'newpath' => 'news', 'menu' => 'other_news2_menu'),
  455. array('oldpath' => 'user_menu', 'newpath' => 'user', 'menu' => 'usertheme_menu'),
  456. array('oldpath' => 'user_menu', 'newpath' => 'user', 'menu' => 'userlanguage_menu'),
  457. array('oldpath' => 'poll_menu', 'newpath' => 'poll', 'menu' => 'poll_menu'),
  458. array('oldpath' => 'banner_menu', 'newpath' => 'banner', 'menu' => 'banner_menu'),
  459. array('oldpath' => 'online_menu', 'newpath' => 'online', 'menu' => 'online_menu'),
  460. );
  461. // List of DB tables (key) and field (value) which need changing to accommodate IPV6 addresses
  462. $ip_upgrade = array('download_requests' => 'download_request_ip',
  463. 'submitnews' => 'submitnews_ip',
  464. 'tmp' => 'tmp_ip',
  465. 'chatbox' => 'cb_ip'
  466. );
  467. $db_parser = new db_table_admin; // Class to read table defs and process them
  468. $do_save = FALSE; // Set TRUE to update prefs when update complete
  469. $updateMessages = array(); // Used to log actions for the admin log - TODO: will go once all converted to new class
  470. $just_check = $type == 'do' ? FALSE : TRUE; // TRUE if we're just seeing whether an update is needed
  471. // if (!$just_check)
  472. // {
  473. // foreach(vartrue($setCorePrefs) as $k=>$v)
  474. // {
  475. // $pref[$k] = $v;
  476. // }
  477. // }
  478. if (!$just_check)
  479. {
  480. $log->logMessage(LAN_UPDATE_14.$e107info['e107_version'], E_MESSAGE_NODISPLAY);
  481. }
  482. $statusTexts = array(E_MESSAGE_SUCCESS => 'Success', E_MESSAGE_ERROR => 'Fail', E_MESSAGE_INFO => 'Info');
  483. if (isset($pref['forum_user_customtitle']) && !isset($pref['signup_option_customtitle']))
  484. {
  485. if ($just_check) return update_needed('pref: forum_user_customtitle needs to be renamed');
  486. $pref['signup_option_customtitle'] = $pref['forum_user_customtitle'];
  487. unset($pref['forum_user_customtitle']);
  488. $log->logMessage(LAN_UPDATE_20.'customtitle', E_MESSAGE_SUCCESS);
  489. $do_save = TRUE;
  490. }
  491. // convert all serialized core prefs to e107 ArrayStorage;
  492. $serialz_qry = "SUBSTRING( e107_value,1,5)!='array' AND e107_value !='' ";
  493. $serialz_qry .= "AND e107_name IN (".implode(",",$serialized_prefs).") ";
  494. if(e107::getDb()->select("core", "*", $serialz_qry))
  495. {
  496. if ($just_check) return update_needed('Convert serialized core prefs');
  497. while ($row = e107::getDb()->fetch(MYSQL_ASSOC))
  498. {
  499. $status = e107::getDb('sql2')->update('core',"e107_value=\"".convert_serialized($row['e107_value'])."\" WHERE e107_name='".$row['e107_name']."'") ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
  500. $log->addDebug(LAN_UPDATE_22.$row['e107_name'].": ". $status);
  501. }
  502. }
  503. if(e107::getDb()->select("core", "*", "e107_name='pm_prefs' LIMIT 1"))
  504. {
  505. if ($just_check) return update_needed('Rename the pm prefs');
  506. e107::getDb()->update("core", "e107_name='plugin_pm' WHERE e107_name = 'pm_prefs'");
  507. }
  508. //@TODO de-serialize the user_prefs also.
  509. // Banlist
  510. if(!$sql->field('banlist','banlist_id'))
  511. {
  512. if ($just_check) return update_needed('Banlist table requires updating.');
  513. $sql->gen("ALTER TABLE #banlist DROP PRIMARY KEY");
  514. $sql->gen("ALTER TABLE `#banlist` ADD `banlist_id` INT( 11 ) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST");
  515. }
  516. // Move the maximum online counts from menu prefs to a separate pref - 'history'
  517. e107::getCache()->clearAll('system');
  518. $menuConfig = e107::getConfig('menu',true,true);
  519. if ($menuConfig->get('most_members_online') || $menuConfig->get('most_guests_online') || $menuConfig->get('most_online_datestamp'))
  520. {
  521. $status = E_MESSAGE_DEBUG;
  522. if ($just_check) return update_needed('Move online counts from menupref');
  523. $newPrefs = e107::getConfig('history');
  524. foreach (array('most_members_online', 'most_guests_online', 'most_online_datestamp') as $v)
  525. {
  526. if (FALSE === $newPrefs->get($v, FALSE))
  527. {
  528. if (FALSE !== $menuConfig->get($v, FALSE))
  529. {
  530. $newPrefs->set($v,$menuConfig->get($v));
  531. }
  532. else
  533. {
  534. $newPrefs->set($v, 0);
  535. }
  536. }
  537. $menuConfig->remove($v);
  538. }
  539. $result = $newPrefs->save(false, true, false);
  540. if ($result === TRUE)
  541. {
  542. $resultMessage = 'Historic member counts updated';
  543. $result = $menuConfig->save(false, true, false); // Only re-save if successul.
  544. }
  545. elseif ($result === FALSE)
  546. {
  547. $resultMessage = 'moving historic member counts';
  548. $status = E_MESSAGE_ERROR;
  549. }
  550. else
  551. { // No change
  552. $resultMessage = 'Historic member counts already updated';
  553. $status = E_MESSAGE_INFO;
  554. }
  555. // $result = $menuConfig->save(false, true, false); // Save updated menuprefs - without the counts - don't delete them if it fails.
  556. //$updateMessages[] = $statusTexts[$status].': '.$resultMessage; // Admin log message
  557. $log->logMessage($resultMessage,$status); // User message
  558. }
  559. // ++++++++ Modify Menu Paths +++++++.
  560. if(varset($changeMenuPaths))
  561. {
  562. foreach($changeMenuPaths as $val)
  563. {
  564. $qry = "SELECT menu_path FROM `#menus` WHERE menu_name = '".$val['menu']."' AND (menu_path='".$val['oldpath']."' || menu_path='".$val['oldpath']."/' ) LIMIT 1";
  565. if($sql->gen($qry))
  566. {
  567. if ($just_check) return update_needed('Menu path changed required: '.$val['menu'].' ');
  568. $updqry = "menu_path='".$val['newpath']."/' WHERE menu_name = '".$val['menu']."' AND (menu_path='".$val['oldpath']."' || menu_path='".$val['oldpath']."/' ) ";
  569. $status = $sql->update('menus', $updqry) ? E_MESSAGE_DEBUG : E_MESSAGE_ERROR;
  570. $log->logMessage(LAN_UPDATE_23.'<b>'.$val['menu'].'</b> : '.$val['oldpath'].' => '.$val['newpath'], $status); // LAN_UPDATE_25;
  571. // catch_error($sql);
  572. }
  573. }
  574. }
  575. // Leave this one here.. just in case..
  576. //delete record for online_extended_menu (now only using one online menu)
  577. if($sql->db_Select('menus', '*', "menu_path='online_extended_menu' || menu_path='online_extended_menu/'"))
  578. {
  579. if ($just_check) return update_needed("The Menu table needs to have some paths corrected in its data.");
  580. $row=$sql->db_Fetch();
  581. //if online_extended is activated, we need to activate the new 'online' menu, and delete this record
  582. if($row['menu_location']!=0)
  583. {
  584. $status = $sql->update('menus', "menu_name='online_menu', menu_path='online/' WHERE menu_path='online_extended_menu' || menu_path='online_extended_menu/' ") ? E_MESSAGE_DEBUG : E_MESSAGE_ERROR;
  585. $log->logMessage(LAN_UPDATE_23."<b>online_menu</b> : online/", $status);
  586. }
  587. else
  588. { //else if the menu is not active
  589. //we need to delete the online_extended menu row, and change the online_menu to online
  590. $sql->delete('menus', " menu_path='online_extended_menu' || menu_path='online_extended_menu/' ");
  591. $log->logMessage(LAN_UPDATE_31, E_MESSAGE_DEBUG);
  592. }
  593. catch_error($sql);
  594. }
  595. //change menu_path for online_menu (if it still exists)
  596. if($sql->db_Select('menus', 'menu_path', "menu_path='online_menu' || menu_path='online_menu/'"))
  597. {
  598. if ($just_check) return update_needed('change menu_path for online menu');
  599. $status = $sql->update('menus', "menu_path='online/' WHERE menu_path='online_menu' || menu_path='online_menu/' ") ? E_MESSAGE_DEBUG : E_MESSAGE_ERROR;
  600. $log->logMessage(LAN_UPDATE_23."<b>online_menu</b> : online/", $status);
  601. catch_error($sql);
  602. }
  603. if (!$just_check)
  604. {
  605. // Alert Admin to delete deprecated menu folders.
  606. $chgPath = array();
  607. foreach($changeMenuPaths as $cgpArray)
  608. {
  609. if(is_dir(e_PLUGIN.$cgpArray['oldpath']))
  610. {
  611. if(!in_array($cgpArray['oldpath'],$chgPath))
  612. {
  613. $chgPath[] = $cgpArray['oldpath'];
  614. }
  615. }
  616. }
  617. //TODO LAN
  618. if(count($chgPath))
  619. {
  620. $log->addWarning('Before continuing, please manually delete the following outdated folders from your system: ');
  621. array_unique($chgPath);
  622. asort($chgPath);
  623. foreach($chgPath as $cgp)
  624. {
  625. $log->addWarning(e_PLUGIN_ABS."<b>".$cgp."</b>");
  626. }
  627. }
  628. }
  629. //---------------------------------------------------------
  630. // Comments - split user field
  631. //---------------------------------------------------------
  632. if($sql->db_Field('comments','comment_author'))
  633. {
  634. if ($just_check) return update_needed('Comment table author field update');
  635. if ((!$sql->db_Field('comments','comment_author_id')) // Check to see whether new fields already added - maybe data copy failed part way through
  636. && (!$sql->gen("ALTER TABLE `#comments`
  637. ADD COLUMN comment_author_id int(10) unsigned NOT NULL default '0' AFTER `comment_author`,
  638. ADD COLUMN comment_author_name varchar(100) NOT NULL default '' AFTER `comment_author_id`")))
  639. {
  640. // Flag error
  641. // $commentMessage = LAN_UPDAXXTE_34;
  642. $log->logMessage(LAN_UPDATE_21."comments", E_MESSAGE_ERROR);
  643. }
  644. else
  645. {
  646. if (FALSE ===$sql->update('comments',"comment_author_id=SUBSTRING_INDEX(`comment_author`,'.',1), comment_author_name=SUBSTRING(`comment_author` FROM POSITION('.' IN `comment_author`)+1)"))
  647. {
  648. // Flag error
  649. $log->logMessage(LAN_UPDATE_21.'comments', E_MESSAGE_ERROR);
  650. }
  651. else
  652. { // Delete superceded field - comment_author
  653. if (!$sql->gen("ALTER TABLE `#comments` DROP COLUMN `comment_author`"))
  654. {
  655. // Flag error
  656. $log->logMessage(LAN_UPDATE_24.'comments - comment_author', E_MESSAGE_ERROR);
  657. }
  658. }
  659. }
  660. $log->logMessage(LAN_UPDATE_21.'comments', E_MESSAGE_DEBUG);
  661. }
  662. // Add index to download history
  663. // Deprecated by db-verify-class
  664. // if (FALSE !== ($temp = addIndexToTable('download_requests', 'download_request_datestamp', $just_check, $updateMessages)))
  665. // {
  666. // if ($just_check)
  667. // {
  668. // return update_needed($temp);
  669. // }
  670. // }
  671. // Extra index to tmp table
  672. // Deprecated by db-verify-class
  673. // if (FALSE !== ($temp = addIndexToTable('tmp', 'tmp_time', $just_check, $updateMessages)))
  674. // {
  675. // if ($just_check)
  676. // {
  677. // return update_needed($temp);
  678. // }
  679. // }
  680. // Extra index to rss table (if used)
  681. // Deprecated by db-verify-class
  682. // if (FALSE !== ($temp = addIndexToTable('rss', 'rss_name', $just_check, $updateMessages, TRUE)))
  683. // {
  684. // if ($just_check)
  685. // {
  686. // return update_needed($temp);
  687. // }
  688. // }
  689. // Front page prefs (logic has changed)
  690. if (!isset($pref['frontpage_force'])) // Just set basic options; no real method of converting the existing
  691. {
  692. if ($just_check) return update_needed('Change front page prefs');
  693. $pref['frontpage_force'] = array(e_UC_PUBLIC => '');
  694. $fpdef = vartrue($pref['frontpage']['all']) == 'index.php' ? 'index.php' : 'news.php';
  695. $pref['frontpage'] = array(e_UC_PUBLIC => $fpdef);
  696. // $_pdateMessages[] = LAN_UPDATE_38; //FIXME
  697. $log->logMessage(LAN_UPDATE_20."frontpage",E_MESSAGE_DEBUG);
  698. $do_save = TRUE;
  699. }
  700. // Check need for user timezone before we delete the field
  701. if (varsettrue($pref['signup_option_timezone']))
  702. {
  703. if ($sql->db_Field('user', 'user_timezone', '', TRUE) && !$sql->db_Field('user_extended','user_timezone','',TRUE))
  704. {
  705. if ($just_check) return update_needed('Move user timezone info');
  706. if (!copy_user_timezone())
  707. { // Error doing the transfer
  708. //$updateMessages[] = LAN_UPDATE_42;
  709. $log->logMessage(LAN_UPDATE_42, E_MESSAGE_ERROR);
  710. return FALSE;
  711. }
  712. //$updateMessages[] = LAN_UPDATE_41;
  713. $log->logMessage(LAN_UPDATE_41, E_MESSAGE_DEBUG);
  714. }
  715. }
  716. // Tables defined in core_sql.php to be RENAMED.
  717. // Next bit will be needed only by the brave souls who used an early CVS - probably delete before release
  718. if ($sql->db_Table_exists('rl_history') && !$sql->db_Table_exists('dblog'))
  719. {
  720. if ($just_check) return update_needed('Rename rl_history to dblog');
  721. $sql->gen('ALTER TABLE `'.MPREFIX.'rl_history` RENAME `'.MPREFIX.'dblog`');
  722. //$updateMessages[] = LAN_UPDATE_44;
  723. $log->logMessage(LAN_UPDATE_44, E_MESSAGE_DEBUG);
  724. catch_error($sql);
  725. }
  726. //---------------------------------
  727. if ($sql->db_Table_exists('dblog') && !$sql->db_Table_exists('admin_log'))
  728. {
  729. if ($just_check) return update_needed('Rename dblog to admin_log');
  730. $sql->gen('ALTER TABLE `'.MPREFIX.'dblog` RENAME `'.MPREFIX.'admin_log`');
  731. catch_error($sql);
  732. //$updateMessages[] = LAN_UPDATE_43;
  733. $log->logMessage(LAN_UPDATE_43, E_MESSAGE_DEBUG);
  734. }
  735. // New tables required (list at top. Definitions in core_sql.php)
  736. // ALL DEPRECATED by db_verify class.. see below.
  737. /*
  738. foreach ($new_tables as $nt)
  739. {
  740. if (!$sql->db_Table_exists($nt))
  741. {
  742. if ($just_check) return update_needed('Add table: '.$nt);
  743. // Get the definition
  744. $defs = $db_parser->get_table_def($nt,e_ADMIN.'sql/core_sql.php');
  745. if (count($defs)) // **** Add in table here
  746. {
  747. $status = $sql->gen('CREATE TABLE `'.MPREFIX.$defs[0][1].'` ('.$defs[0][2].') TYPE='.$defs[0][3]) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
  748. // $updateMessages[] = LAN_UPDATE_45.$defs[0][1];
  749. $log->logMessage(LAN_UPDATE_27.$defs[0][1], $status);
  750. // catch_error($sql);
  751. }
  752. else
  753. { // error parsing defs file
  754. $log->logMessage(LAN_UPDATE_46.$defs[0][1], E_MESSAGE_ERROR);
  755. }
  756. unset($defs);
  757. }
  758. }
  759. // Tables whose definition needs changing significantly
  760. $debugLevel = E107_DBG_SQLDETAILS;
  761. foreach ($changed_tables as $ct)
  762. {
  763. $req_defs = $db_parser->get_table_def($ct,e_ADMIN."sql/core_sql.php");
  764. $req_fields = $db_parser->parse_field_defs($req_defs[0][2]); // Required definitions
  765. if ($debugLevel)
  766. {
  767. $log->logMessage("Required table structure: <br />".$db_parser->make_field_list($req_fields), E_MESSAGE_DEBUG);
  768. }
  769. if ((($actual_defs = $db_parser->get_current_table($ct)) === FALSE) || !is_array($actual_defs)) // Adds current default prefix
  770. {
  771. $log->logMessage("Couldn't get table structure: ".$ct, E_MESSAGE_DEBUG);
  772. }
  773. else
  774. {
  775. // echo $db_parser->make_table_list($actual_defs);
  776. $actual_fields = $db_parser->parse_field_defs($actual_defs[0][2]);
  777. if ($debugLevel)
  778. {
  779. $log->logMessage("Actual table structure: <br />".$db_parser->make_field_list($actual_fields), E_MESSAGE_DEBUG);
  780. }
  781. $diffs = $db_parser->compare_field_lists($req_fields,$actual_fields);
  782. if (count($diffs[0]))
  783. { // Changes needed
  784. if ($just_check) return update_needed("Field changes rqd; table: ".$ct);
  785. // Do the changes here
  786. if ($debugLevel)
  787. {
  788. $log->logMessage("List of changes found:<br />".$db_parser->make_changes_list($diffs), E_MESSAGE_DEBUG);
  789. }
  790. $qry = 'ALTER TABLE '.MPREFIX.$ct.' '.implode(', ',$diffs[1]);
  791. if ($debugLevel)
  792. {
  793. $log->logMessage("Update Query used: ".$qry, E_MESSAGE_DEBUG);
  794. }
  795. $status = $sql->gen($qry) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
  796. $log->logMessage(LAN_UPDATE_21.$ct, $status);
  797. catch_error($sql);
  798. }
  799. }
  800. }
  801. // Plugin tables whose definition needs changing significantly
  802. foreach ($pluginChangedTables as $plugName => $plugList)
  803. {
  804. if (plugInstalled($plugName))
  805. {
  806. $ttc = explode(',',$plugList);
  807. foreach ($ttc as $ct)
  808. {
  809. $sqlDefs = e_PLUGIN.$plugName.'/'.str_replace('_menu','',$plugName).'_sql.php'; // Filename containing definitions
  810. // echo "Looking at file: {$sqlDefs}, table {$ct}<br />";
  811. $req_defs = $db_parser->get_table_def($ct,$sqlDefs);
  812. if (!is_array($req_defs))
  813. {
  814. echo "Couldn't get definitions from file {$sqlDefs}<br />";
  815. continue;
  816. }
  817. $req_fields = $db_parser->parse_field_defs($req_defs[0][2]); // Required definitions
  818. if (E107_DBG_SQLDETAILS)
  819. {
  820. $message = "Required plugin table structure: <br />".$db_parser->make_field_list($req_fields);
  821. $log->logMessage($message, E_MESSAGE_DEBUG);
  822. }
  823. if ((($actual_defs = $db_parser->get_current_table($ct)) === FALSE) || !is_array($actual_defs)) // Adds current default prefix
  824. {
  825. // echo "Couldn't get table structure: {$ct}<br />";
  826. }
  827. else
  828. {
  829. // echo $db_parser->make_table_list($actual_defs);
  830. $actual_fields = $db_parser->parse_field_defs($actual_defs[0][2]);
  831. if (E107_DBG_SQLDETAILS)
  832. {
  833. $message= "Actual table structure: <br />".$db_parser->make_field_list($actual_fields);
  834. $log->logMessage($message, E_MESSAGE_DEBUG);
  835. }
  836. $diffs = $db_parser->compare_field_lists($req_fields,$actual_fields);
  837. if (count($diffs[0]))
  838. { // Changes needed
  839. if (E107_DBG_SQLDETAILS)
  840. {
  841. $message = "List of changes found:<br />".$db_parser->make_changes_list($diffs);
  842. $log->logMessage($message, E_MESSAGE_DEBUG);
  843. }
  844. if ($just_check) return update_needed("Field changes rqd; plugin table: ".$ct);
  845. // Do the changes here
  846. $qry = 'ALTER TABLE '.MPREFIX.$ct.' '.implode(', ',$diffs[1]);
  847. if (E107_DBG_SQLDETAILS)
  848. {
  849. $message = "Update Query used: ".$qry."<br />";
  850. $log->logMessage($message, E_MESSAGE_DEBUG);
  851. }
  852. $sql->gen($qry);
  853. $updateMessages[] = LAN_UPDATE_51.$ct;
  854. $log->logMessage(LAN_UPDATE_51.$ct, E_MESSAGE_SUCCESS);
  855. catch_error($sql);
  856. }
  857. }
  858. }
  859. }
  860. }
  861. */
  862. // Obsolete tables (list at top)
  863. $sql->mySQLtableList = false; // clear the cached table list.
  864. foreach ($obs_tables as $ot)
  865. {
  866. if ($sql->db_Table_exists($ot))
  867. {
  868. if ($just_check) return update_needed("Delete table: ".$ot);
  869. $status = $sql->gen('DROP TABLE `'.MPREFIX.$ot.'`') ? E_MESSAGE_DEBUG : E_MESSAGE_ERROR;
  870. $log->logMessage(LAN_UPDATE_25.$ot, $status);
  871. }
  872. }
  873. // Tables where IP address field needs updating to accommodate IPV6
  874. // Set to varchar(45) - just in case something uses the IPV4 subnet (see http://en.wikipedia.org/wiki/IPV6#Notation)
  875. foreach ($ip_upgrade as $t => $f)
  876. {
  877. if ($sql->db_Table_exists($t))
  878. { // Check for table - might add some core plugin tables in here
  879. if ($field_info = ($sql->db_Field($t, $f, '', TRUE)))
  880. {
  881. if (strtolower($field_info['Type']) != 'varchar(45)')
  882. {
  883. if ($just_check) return update_needed('Update IP address field '.$f.' in table '.$t);
  884. $status = $sql->gen("ALTER TABLE `".MPREFIX.$t."` MODIFY `{$f}` VARCHAR(45) NOT NULL DEFAULT '';") ? E_MESSAGE_DEBUG : E_MESSAGE_ERROR;
  885. $log->logMessage(LAN_UPDATE_26.$t.' - '.$f, $status);
  886. // catch_error($sql);
  887. }
  888. }
  889. else
  890. {
  891. // Got a strange error here
  892. }
  893. }
  894. }
  895. // Obsolete prefs (list at top)
  896. // Intentionally do this last - we may check some of them during the update
  897. $accum = array();
  898. foreach ($obs_prefs as $p)
  899. {
  900. if (isset($pref[$p]))
  901. {
  902. if ($just_check) return update_needed('Remove obsolete prefs');
  903. unset($pref[$p]);
  904. $do_save = TRUE;
  905. $log->addDebug('Removed obsolete pref: '.$p);
  906. // $accum[] = $p;
  907. }
  908. }
  909. /* -------------- Upgrade Entire Table Structure - Multi-Language Supported ----------------- */
  910. // ONLY ever add fields, never deletes.
  911. require_once(e_HANDLER."db_verify_class.php");
  912. $dbv = new db_verify;
  913. if($plugUpgradeReq = e107::getPlugin()->updateRequired())
  914. {
  915. $exclude = array_keys($plugUpgradeReq); // search xxxxx_setup.php and check for 'upgrade_required()' == true.
  916. }
  917. else
  918. {
  919. $exclude = false;
  920. }
  921. $dbv->compareAll($exclude); // core & plugins, but not plugins calling for an update with xxxxx_setup.php
  922. if(count($dbv->errors))
  923. {
  924. if ($just_check)
  925. {
  926. $mes = e107::getMessage();
  927. $log->addDebug(print_a($dbv->errors,true));
  928. return update_needed("Database Tables require updating.");
  929. }
  930. $dbv->compileResults();
  931. $dbv->runFix(); // Fix entire core database structure and plugins too.
  932. }
  933. // print_a($dbv->results);
  934. // print_a($dbv->fixList);
  935. //TODO - send notification messages to Log.
  936. if($sql->field('page','page_theme') && $sql->gen("SELECT * FROM #page WHERE page_theme != '' AND menu_title = '' LIMIT 1"))
  937. {
  938. if ($just_check)
  939. {
  940. return update_needed("Pages/Menus Table requires updating.");
  941. }
  942. if($sql->update('page',"menu_name = page_theme, menu_title = page_title, menu_text = page_text, menu_template='default', page_title = '', page_text = '' WHERE page_theme !='' AND menu_title = '' AND menu_text = '' "))
  943. {
  944. $sql->gen("ALTER TABLE `#page` DROP `page_theme`");
  945. $mes = e107::getMessage();
  946. $log->addDebug("Successfully updated pages/menus table to new format. ");
  947. }
  948. }
  949. if($sql->field('plugin','plugin_releaseUrl'))
  950. {
  951. if ($just_check) return update_needed('plugin_releaseUrl is deprecated and needs to be removed. ');
  952. if($sql->gen("ALTER TABLE `#plugin` DROP `plugin_releaseUrl`"))
  953. {
  954. $log->addDebug("Successfully removed plugin_releaseUrl. ");
  955. }
  956. }
  957. // --- Notify Prefs
  958. // $notify_prefs = $sysprefs -> get('notify_prefs');
  959. // $notify_prefs = $eArrayStorage -> ReadArray($notify_prefs);
  960. e107::getCache()->clearAll('system');
  961. $notify_prefs = e107::getConfig('notify',true,true)->getPref();
  962. $nt_changed = 0;
  963. if(vartrue($notify_prefs['event']))
  964. {
  965. foreach ($notify_prefs['event'] as $e => $d)
  966. {
  967. if (isset($d['type']))
  968. {
  969. if ($just_check) return update_needed('Notify pref: '.$e.' outdated');
  970. switch ($d['type'])
  971. {
  972. case 'main' :
  973. $notify_prefs['event'][$e]['class'] = e_UC_MAINADMIN;
  974. break;
  975. case 'class' : // Should already have class defined
  976. break;
  977. case 'email' :
  978. $notify_prefs['event'][$e]['class'] = 'email';
  979. break;
  980. case 'off' : // Need to disable
  981. default :
  982. $notify_prefs['event'][$e]['class'] = e_UC_NOBODY; // Just disable if we don't know what else to do
  983. }
  984. $nt_changed++;
  985. $notify_prefs['event'][$e]['legacy'] = 1;
  986. unset($notify_prefs['event'][$e]['type']);
  987. }
  988. }
  989. }
  990. if ($nt_changed)
  991. {
  992. $s_prefs = $tp -> toDB($notify_prefs);
  993. $s_prefs = $eArrayStorage -> WriteArray($s_prefs);
  994. // Could we use $sysprefs->set($s_prefs,'notify_prefs') instead - avoids caching problems ????
  995. $status = ($sql -> update("core", "e107_value='".$s_prefs."' WHERE e107_name='notify_prefs'") !== FALSE) ? E_MESSAGE_DEBUG : E_MESSAGE_ERROR;
  996. $message = str_replace('--COUNT--',$nt_changed,LAN_UPDATE_20);
  997. $log->logMessage($message, $status);
  998. }
  999. // --------------- Saved emails - copy across
  1000. if (!$just_check && $sql->db_Select('generic', '*', "gen_type='massmail'"))
  1001. {
  1002. if ($just_check) return update_needed('Copy across saved emails');
  1003. require_once(e_HANDLER.'mail_manager_class.php');
  1004. $mailHandler = new e107MailManager;
  1005. $i = 0;
  1006. while ($row = $sql->db_Fetch(MYSQL_ASSOC))
  1007. {
  1008. $mailRecord = array(
  1009. 'mail_create_date' => $row['gen_datestamp'],
  1010. 'mail_creator' => $row['gen_user_id'],
  1011. 'mail_title' => $row['gen_ip'],
  1012. 'mail_subject' => $row['gen_ip'],
  1013. 'mail_body' => $row['gen_chardata'],
  1014. 'mail_content_status' => MAIL_STATUS_SAVED
  1015. );
  1016. $mailHandler->mailtoDb($mailRecord, TRUE);
  1017. $mailHandler->saveEmail($mailRecord, TRUE);
  1018. $sql2->delete('generic', 'gen_id='.intval($row['gen_id'])); // Delete as we go in case operation fails part way through
  1019. $i++;
  1020. }
  1021. unset($mailHandler);
  1022. $log->logMessage(str_replace('--COUNT--', $i, LAN_UPDATE_28));
  1023. }
  1024. // ------------------- Populate Plugin Table With Changes ------------------
  1025. if (!isset($pref['shortcode_legacy_list']))
  1026. {
  1027. if ($just_check) return update_needed('Legacy shortcode conversion');
  1028. // Reset, legacy and new shortcode list will be generated in plugin update routine
  1029. $pref['shortcode_legacy_list'] = array();
  1030. $pref['shortcode_list'] = array();
  1031. save_prefs();
  1032. $ep = e107::getPlugin();
  1033. $ep->update_plugins_table($mode); // scan for e_xxx changes and save to plugin table.
  1034. $ep->save_addon_prefs($mode); // generate global e_xxx_list prefs from plugin table.
  1035. }
  1036. // This has to be done after the table is upgraded
  1037. if($sql->select('plugin', 'plugin_category', "plugin_category = ''"))
  1038. {
  1039. if ($just_check) return update_needed('Update plugin table');
  1040. require_once(e_HANDLER.'plugin_class.php');
  1041. $ep = new e107plugin;
  1042. $ep->update_plugins_table('update');
  1043. // $_pdateMessages[] = LAN_UPDATE_XX24;
  1044. // catch_error($sql);
  1045. }
  1046. //-- Media-manger import --------------------------------------------------
  1047. // Autogenerate filetypes.xml if not found.
  1048. if(!is_readable(e_SYSTEM."filetypes.xml"))
  1049. {
  1050. $data = '<?xml version="1.0" encoding="utf-8"?>
  1051. <e107Filetypes>
  1052. <class name="253" type="zip,gz,jpg,jpeg,png,gif,xml" maxupload="2M" />
  1053. </e107Filetypes>';
  1054. file_put_contents(e_SYSTEM."filetypes.xml",$data);
  1055. }
  1056. $root_media = str_replace(basename(e_MEDIA)."/","",e_MEDIA);
  1057. $user_media_dirs = array("images","avatars", "avatars/default", "avatars/upload", "files","temp","videos","icons");
  1058. // check for old paths and rename.
  1059. if(is_dir($root_media."images") || is_dir($root_media."temp"))
  1060. {
  1061. foreach($user_media_dirs as $md)
  1062. {
  1063. @rename($root_media.$md,e_MEDIA.$md);
  1064. }
  1065. }
  1066. // create sub-directories if they do not exist.
  1067. if(!is_dir(e_MEDIA."images") || !is_dir(e_MEDIA."temp") || !is_dir(e_AVATAR_UPLOAD) || !is_dir(e_AVATAR_DEFAULT) )
  1068. {
  1069. foreach($user_media_dirs as $md)
  1070. {
  1071. if(!is_dir(e_MEDIA.$md))
  1072. {
  1073. mkdir(e_MEDIA.$md);
  1074. }
  1075. }
  1076. }
  1077. // Move Avatars to new location
  1078. $av1 = e107::getFile()->get_files(e_FILE.'public/avatars','.jpg|.gif|.png|.GIF|.jpeg|.JPG|.PNG');
  1079. $av2 = e107::getFile()->get_files(e_IMAGE.'avatars','.jpg|.gif|.png|.GIF|.jpeg|.JPG|.PNG');
  1080. $avatar_images = array_merge($av1,$av2);
  1081. if(count($avatar_images))
  1082. {
  1083. if ($just_check) return update_needed('Avatar paths require updating.');
  1084. foreach($avatar_images as $av)
  1085. {
  1086. $apath = (strstr($av['path'],'public/')) ? e_AVATAR_UPLOAD : e_AVATAR_DEFAULT;
  1087. @rename($av['path'].$av['fname'], $apath. $av['fname']);
  1088. }
  1089. }
  1090. // -------------------------------
  1091. if (!e107::isInstalled('download') && $sql->gen("SELECT * FROM #links WHERE link_url LIKE 'download.php%' AND link_class != '".e_UC_NOBODY."' LIMIT 1"))
  1092. {
  1093. if ($just_check) return update_needed('Download Plugin needs to be installed.');
  1094. // e107::getSingleton('e107plugin')->install('download',array('nolinks'=>true));
  1095. e107::getSingleton('e107plugin')->refresh('download');
  1096. }
  1097. if (!e107::isInstalled('banner') && $sql->gen("SELECT * FROM #banner LIMIT 1"))
  1098. {
  1099. if ($just_check) return update_needed('Banner Table found, but plugin not installed. Needs to be refreshed.');
  1100. e107::getSingleton('e107plugin')->refresh('banner');
  1101. }
  1102. // ---------------------------------
  1103. $med = e107::getMedia();
  1104. // Media Category Update
  1105. if($sql->db_Field("core_media_cat","media_cat_nick"))
  1106. {
  1107. $count = $sql->gen("SELECT * FROM `#core_media_cat` WHERE media_cat_nick = '_common' ");
  1108. if($count ==1)
  1109. {
  1110. if ($just_check) return update_needed('Media-Manager Categories needs to be updated.');
  1111. $sql->update('core_media_cat', "media_cat_owner = media_cat_nick, media_cat_category = media_cat_nick WHERE media_cat_nick REGEXP '_common|news|page|_icon_16|_icon_32|_icon_48|_icon_64' ");
  1112. $sql->update('core_media_cat', "media_cat_owner = '_icon', media_cat_category = media_cat_nick WHERE media_cat_nick REGEXP '_icon_16|_icon_32|_icon_48|_icon_64' ");
  1113. $sql->update('core_media_cat', "media_cat_owner = 'download', media_cat_category='download_image' WHERE media_cat_nick = 'download' ");
  1114. $sql->update('core_media_cat', "media_cat_owner = 'download', media_cat_category='download_thumb' WHERE media_cat_nick = 'downloadthumb' ");
  1115. $sql->update('core_media_cat', "media_cat_owner = 'news', media_cat_category='news_thumb' WHERE media_cat_nick = 'newsthumb' ");
  1116. $log->addDebug("core-media-cat Categories and Ownership updated");
  1117. if($sql->gen("ALTER TABLE `".MPREFIX."core_media_cat` DROP `media_cat_nick`"))
  1118. {
  1119. $log->addDebug("core-media-cat `media_cat_nick` field removed.");
  1120. }
  1121. // $query = "INSERT INTO `".MPREFIX."core_media_cat` (`media_cat_id`, `media_cat_owner`, `media_cat_category`, `media_cat_title`, `media_cat_diz`, `media_cat_class`, `media_cat_image`, `media_cat_order`) VALUES
  1122. // (0, 'gallery', 'gallery_1', 'Gallery 1', 'Visible to the public at /gallery.php', 0, '', 0);
  1123. /// ";
  1124. //
  1125. // if(mysql_query($query))
  1126. // {
  1127. // $log->addDebug("Added core-media-cat Gallery.");
  1128. // }
  1129. }
  1130. }
  1131. // Media Update
  1132. $count = $sql->gen("SELECT * FROM `#core_media` WHERE media_category = 'newsthumb' OR media_category = 'downloadthumb' LIMIT 1 ");
  1133. if($count ==1)
  1134. {
  1135. if ($just_check) return update_needed('Media-Manager Data needs to be updated.');
  1136. $sql->update('core_media', "media_category='download_image' WHERE media_category = 'download' ");
  1137. $sql->update('core_media', "media_category='download_thumb' WHERE media_category = 'downloadthumb' ");
  1138. $sql->update('core_media', "media_category='news_thumb' WHERE media_category = 'newsthumb' ");
  1139. $log->addDebug("core-media Category names updated");
  1140. }
  1141. // Media Update - core media and core-file.
  1142. $count = $sql->gen("SELECT * FROM `#core_media` WHERE media_category = '_common' LIMIT 1 ");
  1143. if($count ==1)
  1144. {
  1145. if ($just_check) return update_needed('Media-Manager Category Data needs to be updated.');
  1146. $sql->update('core_media', "media_category='_common_image' WHERE media_category = '_common' ");
  1147. $log->addDebug("core-media _common Category updated");
  1148. }
  1149. // Media Update - core media and core-file. CATEGORY
  1150. $count = $sql->gen("SELECT * FROM `#core_media_cat` WHERE media_cat_category = '_common' LIMIT 1 ");
  1151. if($count ==1)
  1152. {
  1153. if ($just_check) return update_needed('Media-Manager Category Data needs to be updated.');
  1154. $sql->update('core_media_cat', "media_cat_category='_common_image' WHERE media_cat_category = '_common' ");
  1155. $sql->gen("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, '_common', '_common_file', '(Common Area)', 'Media in this category will be available in all areas of admin. ', 253, '', 0);");
  1156. $sql->gen("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'download', 'download_file', 'Download Files', '', 253, '', 0);");
  1157. $log->addDebug("core-media-cat _common Category updated");
  1158. }
  1159. $count = $sql->gen("SELECT * FROM `#core_media_cat` WHERE `media_cat_owner` = '_common' LIMIT 1 ");
  1160. if($count != 1)
  1161. {
  1162. if ($just_check) return update_needed('Add Media-Manager Categories and Import existing images.');
  1163. $e107_core_media_cat = array(
  1164. array('media_cat_id'=>0,'media_cat_owner'=>'_common','media_cat_category'=>'_common_image','media_cat_title'=>'(Common Images)','media_cat_sef'=>'','media_cat_diz'=>'Media in this category will be available in all areas of admin.','media_cat_class'=>'253','media_cat_image'=>'','media_cat_order'=>'0'),
  1165. array('media_cat_id'=>0,'media_cat_owner'=>'_common','media_cat_category'=>'_common_file','media_cat_title'=>'(Common Files)','media_cat_sef'=>'','media_cat_diz'=>'Media in this category will be available in all areas of admin.','media_cat_class'=>'253','media_cat_image'=>'','media_cat_order'=>'0'),
  1166. array('media_cat_id'=>0,'media_cat_owner'=>'news','media_cat_category'=>'news','media_cat_title'=>'News','media_cat_sef'=>'','media_cat_diz'=>'Will be available in the news area.','media_cat_class'=>'253','media_cat_image'=>'','media_cat_order'=>'1'),
  1167. array('media_cat_id'=>0,'media_cat_owner'=>'page','media_cat_category'=>'page','media_cat_title'=>'Custom Pages','media_cat_sef'=>'','media_cat_diz'=>'Will be available in the custom pages area of admin.','media_cat_class'=>'253','media_cat_image'=>'','media_cat_order'=>'0'),
  1168. array('media_cat_id'=>0,'media_cat_owner'=>'download','media_cat_category'=>'download_image','media_cat_title'=>'Download Images','media_cat_sef'=>'','media_cat_diz'=>'','media_cat_class'=>'253','media_cat_image'=>'','media_cat_order'=>'0'),
  1169. array('media_cat_id'=>0,'media_cat_owner'=>'download','media_cat_category'=>'download_thumb','media_cat_title'=>'Download Thumbnails','media_cat_sef'=>'','media_cat_diz'=>'','media_cat_class'=>'253','media_cat_image'=>'','media_cat_order'=>'0'),
  1170. array('media_cat_id'=>0,'media_cat_owner'=>'download','media_cat_category'=>'download_file','media_cat_title'=>'Download Files','media_cat_sef'=>'','media_cat_diz'=>'','media_cat_class'=>'253','media_cat_image'=>'','media_cat_order'=>'0'),
  1171. array('media_cat_id'=>0,'media_cat_owner'=>'news','media_cat_category'=>'news_thumb','media_cat_title'=>'News Thumbnails (Legacy)','media_cat_sef'=>'','media_cat_diz'=>'Legacy news thumbnails.','media_cat_class'=>'253','media_cat_image'=>'','media_cat_order'=>'1'),
  1172. );
  1173. foreach($e107_core_media_cat as $insert)
  1174. {
  1175. $sql->insert('core_media_cat', $insert);
  1176. }
  1177. // $sql->gen("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, '_common', '_common_image', '(Common Images)', '', 'Media in this category will be available in all areas of…

Large files files are truncated, but you can click here to view the full file