retrieve_sys('nq_admin_updatecheck',3600, TRUE)) { // See when we last checked for an admin update list($last_time, $dont_check_update, $last_ver) = explode(',',$tempData); if ($last_ver != $e107info['e107_version']) { $dont_check_update = FALSE; // Do proper check on version change } } } if (!$dont_check_update) { if ($sql->db_Select('plugin', 'plugin_version, plugin_path', 'plugin_installflag=1')) { while ($row = $sql->db_Fetch()) { // Mark plugins for update which have a specific update file, or a plugin.php file to check if(is_readable(e_PLUGIN.$row['plugin_path'].'/'.$row['plugin_path'].'_update_check.php') || is_readable(e_PLUGIN.$row['plugin_path'].'/plugin.php')) { $dbupdateplugs[$row['plugin_path']] = $row['plugin_version']; } } } // Read in each update file - this will add an entry to the $dbupdatep array if a potential update exists foreach ($dbupdateplugs as $path => $ver) { $fname = e_PLUGIN.$path.'/'.$path.'_update_check.php'; if (is_readable($fname)) include_once($fname); } // List of potential updates if (defined('TEST_UPDATE')) { $dbupdate['test_code'] = 'Test update routine'; } $dbupdate['core_prefs'] = LAN_UPDATE_13; // Prefs check $dbupdate['706_to_800'] = LAN_UPDATE_8.' .706 '.LAN_UPDATE_9.' .8'; $dbupdate['70x_to_706'] = LAN_UPDATE_8.' .70x '.LAN_UPDATE_9.' .706'; } // End if (!$dont_check_update) /** * Master routine to call to check for updates */ function update_check() { global $ns, $dont_check_update, $e107info; $update_needed = FALSE; if ($dont_check_update === FALSE) { global $dbupdate, $dbupdatep, $e107cache; // See which core functions need update foreach($dbupdate as $func => $rmks) { if (function_exists('update_'.$func)) { if (!call_user_func('update_'.$func, FALSE)) { $update_needed = TRUE; continue; } } } // Now check plugins foreach($dbupdatep as $func => $rmks) { if (function_exists('update_'.$func)) { if (!call_user_func('update_'.$func, FALSE)) { $update_needed = TRUE; continue; } } } $e107cache->set_sys('nq_admin_updatecheck', time().','.($update_needed ? '2,' : '1,').$e107info['e107_version'], TRUE); } else { $update_needed = ($dont_check_update == '2'); } if ($update_needed === TRUE) { require_once (e_HANDLER.'form_handler.php'); $frm = new e_form(); $txt = "
"; require_once (e_HANDLER.'message_handler.php'); $emessage = &eMessage::getInstance(); $emessage->add($txt); } } require_once(e_HANDLER.'e_upgrade_class.php'); // $upg = new e_upgrade; //TODO Enable this before release!! // $upg->checkSiteTheme(); // $upg->checkAllPlugins(); //-------------------------------------------- // Check current prefs against latest list //-------------------------------------------- function update_core_prefs($type='') { global $pref, $e107info; $admin_log = e107::getAdminLog(); $do_save = FALSE; $should = get_default_prefs(); $just_check = $type == 'do' ? FALSE : TRUE; // TRUE if we're just seeing if an update is needed foreach ($should as $k => $v) { if ($k && !array_key_exists($k,$pref)) { if ($just_check) return update_needed('Missing pref: '.$k); $pref[$k] = $v; $admin_log->logMessage($k.' => '.$v, E_MESSAGE_NODISPLAY, E_MESSAGE_INFO); $do_save = TRUE; } } if ($do_save) { save_prefs(); $admin_log->logMessage(LAN_UPDATE_14.$e107info['e107_version'], E_MESSAGE_NODISPLAY, E_MESSAGE_INFO); $admin_log->flushMessages('UPDATE_03',E_LOG_INFORMATIVE); //$admin_log->log_event('UPDATE_03',LAN_UPDATE_14.$e107info['e107_version'].'[!br!]'.implode(', ',$accum),E_LOG_INFORMATIVE,''); // Log result of actual update } return $just_check; } if (defined('TEST_UPDATE')) { //-------------------------------------------- // Test routine - to activate, define TEST_UPDATE //-------------------------------------------- function update_test_code($type='') { global $sql,$ns, $pref; $just_check = $type == 'do' ? FALSE : TRUE; // TRUE if we're just seeing whether an update is needed //--------------**************--------------- // Add your test code in here //--------------**************--------------- //--------------**************--------------- // End of test code //--------------**************--------------- return $just_check; } } // End of test routine //-------------------------------------------- // Upgrade later versions of 0.7.x to 0.8 //-------------------------------------------- function update_706_to_800($type='') { global $ns, $pref, $e107info; global $sysprefs, $eArrayStorage; //$mes = new messageLog; // Combined logging and message displaying handler //$mes = e107::getMessage(); $mes = e107::getAdminLog(); // Used for combined logging and message displaying $sql = e107::getDb(); $sql2 = e107::getDb('sql2'); $tp = e107::getParser(); // List of unwanted $pref values which can go $obs_prefs = array('frontpage_type','rss_feeds', 'log_lvcount', 'zone', 'upload_allowedfiletype', 'real', 'forum_user_customtitle', 'utf-compatmode','frontpage_method','standards_mode','image_owner','im_quality', 'signup_option_timezone', 'modules', 'plug_sc', 'plug_bb', 'plug_status', 'plug_latest', 'subnews_hide_news', 'upload_storagetype' ); // List of DB tables not required (includes a few from 0.6xx) $obs_tables = array('flood', 'headlines', 'stat_info', 'stat_counter', 'stat_last', 'session'); // List of DB tables newly required (defined in core_sql.php) (The existing dblog table gets renamed) $new_tables = array('admin_log', 'audit_log', 'dblog', 'news_rewrite', 'core_media', 'mail_recipients', 'mail_content'); // List of core prefs that need to be converted from serialized to e107ArrayStorage. $serialized_prefs = array("'emote'", "'menu_pref'", "'search_prefs'", "'emote_default'"); // List of changed DB tables (defined in core_sql.php) // (primarily those which have changed significantly; for the odd field write some explicit code - it'll run faster) $changed_tables = array('user', 'dblog', 'admin_log', 'userclass_classes', 'banlist', 'menus', 'plugin', 'news', 'news_category', 'online', 'page', 'links', 'comments'); // List of changed DB tables from core plugins (defined in pluginname_sql.php file) // key = plugin directory name. Data = comma-separated list of tables to check // (primarily those which have changed significantly; for the odd field write some explicit code - it'll run faster) $pluginChangedTables = array('linkwords' => 'linkwords', 'featurebox' => 'featurebox', 'links_page' => 'links_page', 'poll' => 'polls', 'content' => 'pcontent' ); $setCorePrefs = array( //modified prefs during upgrade. 'adminstyle' => 'infopanel', 'admintheme' => 'jayya' ); $do_save = TRUE; foreach($setCorePrefs as $k=>$v) { $pref[$k] = $v; } // List of changed menu locations. $changeMenuPaths = array( array('oldpath' => 'siteinfo_menu', 'newpath' => 'siteinfo', 'menu' => 'sitebutton_menu'), array('oldpath' => 'siteinfo_menu', 'newpath' => 'siteinfo', 'menu' => 'compliance_menu'), array('oldpath' => 'siteinfo_menu', 'newpath' => 'siteinfo', 'menu' => 'powered_by_menu'), array('oldpath' => 'siteinfo_menu', 'newpath' => 'siteinfo', 'menu' => 'sitebutton_menu'), array('oldpath' => 'siteinfo_menu', 'newpath' => 'siteinfo', 'menu' => 'counter_menu'), array('oldpath' => 'siteinfo_menu', 'newpath' => 'siteinfo', 'menu' => 'latestnews_menu'), array('oldpath' => 'compliance_menu', 'newpath' => 'siteinfo', 'menu' => 'compliance_menu'), array('oldpath' => 'powered_by_menu', 'newpath' => 'siteinfo', 'menu' => 'powered_by_menu'), array('oldpath' => 'sitebutton_menu', 'newpath' => 'siteinfo', 'menu' => 'sitebutton_menu'), array('oldpath' => 'counter_menu', 'newpath' => 'siteinfo', 'menu' => 'counter_menu'), array('oldpath' => 'usertheme_menu', 'newpath' => 'user_menu', 'menu' => 'usertheme_menu'), array('oldpath' => 'userlanguage_menu', 'newpath' => 'user_menu', 'menu' => 'userlanguage_menu'), array('oldpath' => 'lastseen_menu', 'newpath' => 'online', 'menu' => 'lastseen_menu') ); // List of DB tables (key) and field (value) which need changing to accommodate IPV6 addresses $ip_upgrade = array('download_requests' => 'download_request_ip', 'submitnews' => 'submitnews_ip', 'tmp' => 'tmp_ip', 'chatbox' => 'cb_ip' ); $db_parser = new db_table_admin; // Class to read table defs and process them $do_save = FALSE; // Set TRUE to update prefs when update complete $updateMessages = array(); // Used to log actions for the admin log - TODO: will go once all converted to new class $just_check = $type == 'do' ? FALSE : TRUE; // TRUE if we're just seeing whether an update is needed if (!$just_check) { $mes->logMessage(LAN_UPDATE_14.$e107info['e107_version'], E_MESSAGE_NODISPLAY); } // Check that custompages have been imported from current theme.php file if(!array_key_exists('sitetheme_custompages',$pref)) { $th = e107::getSingleton('themeHandler'); $tmp = $th->getThemeInfo($pref['sitetheme']); if(is_array($tmp['custompages'])) { if ($just_check) return update_needed(); $pref['sitetheme_custompages'] = $tmp['custompages']; $do_save = TRUE; } } // Check notify prefs $notify_prefs = $sysprefs -> get('notify_prefs'); $notify_prefs = $eArrayStorage -> ReadArray($notify_prefs); $nt_changed = 0; if(vartrue($notify_prefs['event'])) { foreach ($notify_prefs['event'] as $e => $d) { if (isset($d['type'])) { if ($just_check) return update_needed('Notify pref: '.$e.' outdated'); switch ($d['type']) { case 'main' : $notify_prefs['event'][$e]['class'] = e_UC_MAINADMIN; break; case 'class' : // Should already have class defined break; case 'email' : $notify_prefs['event'][$e]['class'] = 'email'; break; case 'off' : // Need to disable default : $notify_prefs['event'][$e]['class'] = e_UC_NOBODY; // Just disable if we don't know what else to do } $nt_changed++; unset($notify_prefs['event'][$e]['type']); } } } if ($nt_changed) { $s_prefs = $tp -> toDB($notify_prefs); $s_prefs = $eArrayStorage -> WriteArray($s_prefs); // Could we use $sysprefs->set($s_prefs,'notify_prefs') instead - avoids caching problems ???? $status = ($sql -> db_Update("core", "e107_value='".$s_prefs."' WHERE e107_name='notify_prefs'") === FALSE) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR; $message = str_replace('--COUNT--',$nt_changed,LAN_UPDATE_20); $mes->logMessage($message, $status); } $statusTexts = array(E_MESSAGE_SUCCESS => 'Success', E_MESSAGE_ERROR => 'Fail', E_MESSAGE_INFO => 'Info'); if (isset($pref['forum_user_customtitle']) && !isset($pref['signup_option_customtitle'])) { if ($just_check) return update_needed(); $pref['signup_option_customtitle'] = $pref['forum_user_customtitle']; unset($pref['forum_user_customtitle']); $mes->logMessage(LAN_UPDATE_20.'customtitle', E_MESSAGE_SUCCESS); $do_save = TRUE; } // convert all serialized core prefs to e107 ArrayStorage; $serialz_qry = "SUBSTRING( e107_value,1,5)!='array' AND e107_value !='' "; $serialz_qry .= "AND e107_name IN (".implode(",",$serialized_prefs).") "; if(e107::getDb()->db_Select("core", "*", $serialz_qry)) { if ($just_check) return update_needed(); while ($row = e107::getDb()->db_Fetch(MYSQL_ASSOC)) { $status = e107::getDb('sql2')->db_Update('core',"e107_value=\"".convert_serialized($row['e107_value'])."\" WHERE e107_name='".$row['e107_name']."'"); $mes->logMessage(LAN_UPDATE_22.$row['e107_name'], $status); } } //@TODO de-serialize the user_prefs also. // Move the maximum online counts from menu prefs to a separate pref - 'history' $menuConfig = e107::getConfig('menu'); if ($menuConfig->get('most_members_online') || $menuConfig->get('most_guests_online') || $menuConfig->get('most_online_datestamp')) { $status = E_MESSAGE_SUCCESS; if ($just_check) return update_needed('Move online counts from menupref'); $newPrefs = e107::getConfig('history'); foreach (array('most_members_online', 'most_guests_online', 'most_online_datestamp') as $v) { if (FALSE === $newPrefs->get($v, FALSE)) { if (FALSE !== $menuConfig->get($v, FALSE)) { $newPrefs->set($v,$menuConfig->get($v)); } else { $newPrefs->set($v, 0); } } $menuConfig->remove($v); } $result = $newPrefs->save(false, true, false); if ($result === TRUE) { $resultMessage = 'Historic member counts updated'; } elseif ($result === FALSE) { $resultMessage = 'moving historic member counts'; $status = E_MESSAGE_ERROR; } else { // No change $resultMessage = 'Historic member counts already updated'; $status = E_MESSAGE_INFO; } $result = $menuConfig->save(false, true, false); // Save updated menuprefs - without the counts //$updateMessages[] = $statusTexts[$status].': '.$resultMessage; // Admin log message $mes->logMessage($resultMessage,$status); // User message } // ++++++++ Modify Menu Paths +++++++. if(varset($changeMenuPaths)) { foreach($changeMenuPaths as $val) { $qry = "SELECT menu_path FROM `#menus` WHERE menu_name = '".$val['menu']."' AND (menu_path='".$val['oldpath']."' || menu_path='".$val['oldpath']."/' ) LIMIT 1"; if($sql->db_Select_gen($qry)) { if ($just_check) return update_needed('Menu path changed required: '.$val['menu'].' '); $updqry = "menu_path='".$val['newpath']."/' WHERE menu_name = '".$val['menu']."' AND (menu_path='".$val['oldpath']."' || menu_path='".$val['oldpath']."/' ) "; $status = $sql->db_Update('menus', $updqry) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR; $mes->logMessage(LAN_UPDATE_23.''.$val['menu'].' : '.$val['oldpath'].' => '.$val['newpath'], $status); // LAN_UPDATE_25; // catch_error($sql); } } } // Leave this one here.. just in case.. //delete record for online_extended_menu (now only using one online menu) if($sql->db_Select('menus', '*', "menu_path='online_extended_menu' || menu_path='online_extended_menu/'")) { if ($just_check) return update_needed(); $row=$sql->db_Fetch(); //if online_extended is activated, we need to activate the new 'online' menu, and delete this record if($row['menu_location']!=0) { $status = $sql->db_Update('menus', "menu_name='online_menu', menu_path='online/' WHERE menu_path='online_extended_menu' || menu_path='online_extended_menu/' ") ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR; $mes->logMessage(LAN_UPDATE_23."online_menu : online/", $status); } else { //else if the menu is not active //we need to delete the online_extended menu row, and change the online_menu to online $sql->db_Delete('menus', " menu_path='online_extended_menu' || menu_path='online_extended_menu/' "); $mes->logMessage(LAN_UPDATE_31, E_MESSAGE_SUCCESS); } catch_error($sql); } //change menu_path for online_menu (if it still exists) if($sql->db_Select('menus', 'menu_path', "menu_path='online_menu' || menu_path='online_menu/'")) { if ($just_check) return update_needed(); $status = $sql->db_Update('menus', "menu_path='online/' WHERE menu_path='online_menu' || menu_path='online_menu/' ") ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR; $mes->logMessage(LAN_UPDATE_23."online_menu : online/", $status); catch_error($sql); } //--------------------------------------------------------- // Comments - split user field //--------------------------------------------------------- if($sql->db_Field('comments','comment_author')) { if ($just_check) return update_needed('Comment table author field update'); if ((!$sql->db_Field('comments','comment_author_id')) // Check to see whether new fields already added - maybe data copy failed part way through && (!$sql->db_Select_gen("ALTER TABLE `#comments` ADD COLUMN comment_author_id int(10) unsigned NOT NULL default '0' AFTER `comment_author`, ADD COLUMN comment_author_name varchar(100) NOT NULL default '' AFTER `comment_author_id`"))) { // Flag error // $commentMessage = LAN_UPDAXXTE_34; $mes->logMessage(LAN_UPDATE_21."comments", E_MESSAGE_ERROR); } else { if (FALSE ===$sql->db_Update('comments',"comment_author_id=SUBSTRING_INDEX(`comment_author`,'.',1), comment_author_name=SUBSTRING(`comment_author` FROM POSITION('.' IN `comment_author`)+1)")) { // Flag error $mes->logMessage(LAN_UPDATE_21.'comments', E_MESSAGE_ERROR); } else { // Delete superceded field - comment_author if (!$sql->db_Select_gen("ALTER TABLE `#comments` DROP COLUMN `comment_author`")) { // Flag error $mes->logMessage(LAN_UPDATE_24.'comments - comment_author', E_MESSAGE_ERROR); } } } $mes->logMessage(LAN_UPDATE_21.'comments', E_MESSAGE_SUCCESS); } // Add index to download history if (FALSE !== ($temp = addIndexToTable('download_requests', 'download_request_datestamp', $just_check, $updateMessages))) { if ($just_check) { return update_needed($temp); } } // Extra index to tmp table if (FALSE !== ($temp = addIndexToTable('tmp', 'tmp_time', $just_check, $updateMessages))) { if ($just_check) { return update_needed($temp); } } // Extra index to rss table (if used) if (FALSE !== ($temp = addIndexToTable('rss', 'rss_name', $just_check, $updateMessages, TRUE))) { if ($just_check) { return update_needed($temp); } } // Front page prefs (logic has changed) if (!isset($pref['frontpage_force'])) { // Just set basic options; no real method of converting the existing if ($just_check) return update_needed('Change front page prefs'); $pref['frontpage_force'] = array(e_UC_PUBLIC => ''); $pref['frontpage'] = array(e_UC_PUBLIC => 'news.php'); // $_pdateMessages[] = LAN_UPDATE_38; //FIXME $mes->logMessage(LAN_UPDATE_20."frontpage",E_MESSAGE_SUCCESS); $do_save = TRUE; } if ($sql->db_Table_exists('newsfeed')) { // Need to extend field newsfeed_url varchar(250) NOT NULL default '' if ($sql->db_Query("SHOW FIELDS FROM ".MPREFIX."newsfeed LIKE 'newsfeed_url'")) { $row = $sql -> db_Fetch(); if (str_replace('varchar', 'char', strtolower($row['Type'])) != 'char(250)') { if ($just_check) return update_needed('Update newsfeed field definition'); $status = $sql->db_Select_gen("ALTER TABLE `".MPREFIX."newsfeed` MODIFY `newsfeed_url` VARCHAR(250) NOT NULL DEFAULT '' ") ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR; //$updateMessages[] = LAN_UPDATE_40; $mes->logMessage(LAN_UPDATE_21."newsfeed",$status); // catch_error($sql); } } } //TODO use generic function for this update. if ($sql->db_Table_exists('download')) { // Need to extend field download_url varchar(255) NOT NULL default '' if ($sql->db_Query("SHOW FIELDS FROM ".MPREFIX."download LIKE 'download_url'")) { $row = $sql -> db_Fetch(); if (str_replace('varchar', 'char', strtolower($row['Type'])) != 'char(255)') { if ($just_check) return update_needed('Update download table field definition'); $sql->db_Select_gen("ALTER TABLE `#download` MODIFY `download_url` VARCHAR(255) NOT NULL DEFAULT '' "); //$updateMessages[] = LAN_UPDATE_52; //FIXME $mes->logMessage(LAN_UPDATE_52, E_MESSAGE_SUCCESS); catch_error($sql); } } } //TODO use generic function for this update. if ($sql->db_Table_exists('download_mirror')) { // Need to extend field download_url varchar(255) NOT NULL default '' if ($sql->db_Select_gen("SHOW FIELDS FROM ".MPREFIX."download_mirror LIKE 'mirror_url'")) { $row = $sql -> db_Fetch(); if (str_replace('varchar', 'char', strtolower($row['Type'])) != 'char(255)') { if ($just_check) return update_needed('Update download mirror table field definition'); $sql->db_Select_gen("ALTER TABLE `".MPREFIX."download_mirror` MODIFY `mirror_url` VARCHAR(255) NOT NULL DEFAULT '' "); $mes->logMessage(LAN_UPDATE_53, E_MESSAGE_SUCCESS); catch_error($sql); } } } // Check need for user timezone before we delete the field if (varsettrue($pref['signup_option_timezone'])) { if ($sql->db_Field('user', 'user_timezone', '', TRUE) && !$sql->db_Field('user_extended','user_timezone','',TRUE)) { if ($just_check) return update_needed('Move user timezone info'); if (!copy_user_timezone()) { // Error doing the transfer //$updateMessages[] = LAN_UPDATE_42; $mes->logMessage(LAN_UPDATE_42, E_MESSAGE_ERROR); return FALSE; } //$updateMessages[] = LAN_UPDATE_41; $mes->logMessage(LAN_UPDATE_41); } } // Tables defined in core_sql.php //--------------------------------- if ($sql->db_Table_exists('dblog') && !$sql->db_Table_exists('admin_log')) { if ($just_check) return update_needed('Rename dblog to admin_log'); $sql->db_Select_gen('ALTER TABLE `'.MPREFIX.'dblog` RENAME `'.MPREFIX.'admin_log`'); catch_error($sql); //$updateMessages[] = LAN_UPDATE_43; $mes->logMessage(LAN_UPDATE_43, E_MESSAGE_SUCCESS); } // Next bit will be needed only by the brave souls who used an early CVS - probably delete before release if ($sql->db_Table_exists('rl_history') && !$sql->db_Table_exists('dblog')) { if ($just_check) return update_needed('Rename rl_history to dblog'); $sql->db_Select_gen('ALTER TABLE `'.MPREFIX.'rl_history` RENAME `'.MPREFIX.'dblog`'); //$updateMessages[] = LAN_UPDATE_44; $mes->logMessage(LAN_UPDATE_44, E_MESSAGE_SUCCESS); catch_error($sql); } // New tables required (list at top. Definitions in core_sql.php) foreach ($new_tables as $nt) { if (!$sql->db_Table_exists($nt)) { if ($just_check) return update_needed('Add table: '.$nt); // Get the definition $defs = $db_parser->get_table_def($nt,e_ADMIN.'sql/core_sql.php'); if (count($defs)) // **** Add in table here { $status = $sql->db_Select_gen('CREATE TABLE `'.MPREFIX.$defs[0][1].'` ('.$defs[0][2].') TYPE='.$defs[0][3]) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR; // $updateMessages[] = LAN_UPDATE_45.$defs[0][1]; $mes->logMessage(LAN_UPDATE_27.$defs[0][1], $status); // catch_error($sql); } else { // error parsing defs file $mes->logMessage(LAN_UPDATE_46.$defs[0][1], E_MESSAGE_ERROR); } unset($defs); } } // Tables whose definition needs changing significantly $debugLevel = E107_DBG_SQLDETAILS; foreach ($changed_tables as $ct) { $req_defs = $db_parser->get_table_def($ct,e_ADMIN."sql/core_sql.php"); $req_fields = $db_parser->parse_field_defs($req_defs[0][2]); // Required definitions if ($debugLevel) { $mes->logMessage("Required table structure: