function updateSettings() { $fn = _upgrader_ . "/data/sql/core_setting_default.sql"; importSqlFile($fn); $new_setting = getSettingsArr('core_setting_default'); // Unset Old settings unset($core_cfg['core_version']); unset($learning_cfg['lms_version']); $core_cfg = getSettingsArr('core_setting'); $learning_cfg = getSettingsArr('learning_setting'); $conference_cfg = getSettingsArr('conference_setting'); $old_cfg = array_merge($core_cfg, $learning_cfg, $conference_cfg); // Update the platform url $https = isset($_SERVER["HTTPS"]) ? $_SERVER["HTTPS"] : FALSE; $base_url = ($https ? "https://" : "http://") . $_SERVER["HTTP_HOST"] . dirname($_SERVER['PHP_SELF']) . "/"; $base_url = preg_replace("/upgrade\\/\$/", "", $base_url); $default_cfg['url']['param_value'] = $base_url; // empty the core_setting $qtxt = "TRUNCATE TABLE core_setting"; $q = mysql_query($qtxt); if (!$q) { $GLOBALS['debug'] .= mysql_error() . "\n"; } // Store config (we'll keep only the core_setting table) foreach ($new_setting as $key => $val) { $fields = array(); foreach ($val as $fk => $fv) { if ($fk == 'param_value') { $fields[] = $fk . "='" . (isset($old_cfg[$fk]) ? $old_cfg[$fk][$fv] : $fv) . "'"; } else { $fields[] = $fk . "='" . $fv . "'"; } } $fields_qtxt = implode(', ', $fields); $qtxt = "INSERT INTO core_setting SET " . $fields_qtxt; $q = mysql_query($qtxt); if (!$q) { $GLOBALS['debug'] .= mysql_error() . "\n"; } } $qtxt = "DROP TABLE IF EXISTS `core_setting_default`;"; mysql_query($qtxt); }
require $fn; $func = 'preUpgrade' . $current_ver; if (function_exists($func)) { $GLOBALS['debug'] .= " <br/>" . "Execute pre-upgrade func: " . $func; $res = $func(); if (!$res) { $_SESSION['upgrade_ok'] = false; } } } if ($_SESSION['upgrade_ok']) { // --- sql upgrade ----------------------------------------------------------- $fn = _upgrader_ . '/data/upg_data/' . $current_ver . '_db.sql'; if (file_exists($fn)) { $GLOBALS['debug'] .= " <br/>" . "Upgrade db with file: " . $fn; $res = importSqlFile($fn); if (!$res['ok']) { $_SESSION['upgrade_ok'] = false; } } } if ($_SESSION['upgrade_ok']) { // --- post upgrade ---------------------------------------------------------- $fn = _upgrader_ . '/data/upg_data/' . $current_ver . '_post.php'; if (file_exists($fn)) { $GLOBALS['debug'] .= " <br/>" . "Source post-upgrade file: " . $fn; require $fn; $func = 'postUpgrade' . $current_ver; if (function_exists($func)) { $GLOBALS['debug'] .= " <br/>" . "Execute post-upgrade func: " . $func; $res = $func();
$sqlArray = file($fName, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); unlink($fName); //get version of backup file $lcVBup = '?.?'; foreach ($sqlArray as $qLine) { if ($qLine[0] != '-') { break; } if (preg_match('~LuxCal version:\\s*(\\d.\\d)~i', $qLine, $matches)) { //version found $lcVBup = $matches[1]; } } $calID = $selCal; //set destination calendar $count = importSqlFile($sqlArray); //import SQL file if ($count['cat'] > 0 and $count['use'] > 0 and $count['gro'] > 0 and $count['set'] > 0) { $resMsg[] = "<h5>Importing LuxCal calendar data successful</h5><br>"; $resMsg[] = "From file '{$_FILES['fName']['name']}' (LuxCal V{$lcVBup})"; $resMsg[] = "Into calendar '{$selCal}'"; $resMsg[] = "<br>"; $resMsg[] = "- Table events: {$count['eve']} records inserted"; $resMsg[] = "- Table users: {$count['use']} records inserted"; $resMsg[] = "- Table groups: {$count['gro']} records inserted"; $resMsg[] = "- Table categories: {$count['cat']} records inserted"; $resMsg[] = "- Table settings: {$count['set']} records inserted"; $lcVUpg = upgradeDb(); //upgrade db schema $resMsg[] = "<br>"; $resMsg[] = "Imported database upgraded from V{$lcVUpg} to V" . substr($lcV, 0, 3);
function restoreTables() { global $ax, $calID, $lcV, $dbType; echo "<fieldset><legend>{$ax['mdb_restore']}</legend>\n"; do { if (empty($_FILES['fName']['tmp_name'])) { echo "{$ax['mdb_noshow_restore']}\n"; break; //abort restore } if (substr($_FILES['fName']['name'], -4) != '.sql') { echo "{$ax['mdb_file_not_sql']}\n"; break; //abort restore } $buFile = $_FILES['fName']['tmp_name']; //get backup file name //Read SQL queries from $buFile $sqlArray = file($buFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); unlink($buFile); //check version of backup file foreach ($sqlArray as $qLine) { //search 1st comment block if ($qLine[0] != '-' or preg_match('~LuxCal version:\\s*(\\d.\\d)~i', $qLine, $matches)) { break; } } if (!empty($matches) and $matches[1] != substr($lcV, 0, 3)) { //version found but not matching echo "<span class='hired'>{$ax['mdb_no_bup_match']}</span><br>\n"; break; //abort restore } echo "{$ax['mdb_backup_file']}: '<strong>{$_FILES['fName']['name']}</strong>'<br><br>"; $count = importSqlFile($sqlArray); //import SQL file upgradeDb(); //recreate db schema echo "{$ax['mdb_restore_table']} 'events' - {$count['eve']} {$ax['mdb_inserted']}<br>\n{$ax['mdb_restore_table']} 'users' - {$count['use']} {$ax['mdb_inserted']}<br>\n{$ax['mdb_restore_table']} 'groups' - {$count['gro']} {$ax['mdb_inserted']}<br>\n{$ax['mdb_restore_table']} 'categories' - {$count['cat']} {$ax['mdb_inserted']}<br>\n{$ax['mdb_restore_table']} 'settings' - {$count['set']} {$ax['mdb_inserted']}<br>\n"; if ($count['cat'] > 0 and $count['use'] > 0 and $count['gro'] > 0 and $count['set'] > 0) { echo "<br><strong>{$ax['mdb_db_restored']}</strong><br>\n"; } } while (0); //end of: restore tables echo "</fieldset>\n"; }