function upgrade() { global $thisstaff, $ost; if (!$thisstaff or !$thisstaff->isAdmin() or !$ost) { Http::response(403, 'Access Denied'); } $upgrader = new Upgrader($ost->getDBSignature(), TABLE_PREFIX, SQL_DIR); //Just report the next action on the first call. if (!$_SESSION['ost_upgrader'] || !$_SESSION['ost_upgrader'][$upgrader->getShash()]['progress']) { $_SESSION['ost_upgrader'][$upgrader->getShash()]['progress'] = $upgrader->getNextAction(); Http::response(200, $upgrader->getNextAction()); exit; } if ($upgrader->isAborted()) { Http::response(416, "We have a problem ... wait a sec."); exit; } if ($upgrader->getNumPendingTasks() && $upgrader->doTasks()) { //More pending tasks - doTasks returns the number of pending tasks Http::response(200, $upgrader->getNextAction()); exit; } elseif ($ost->isUpgradePending()) { if ($upgrader->isUpgradable()) { $version = $upgrader->getNextVersion(); if ($upgrader->upgrade()) { //We're simply reporting progress here - call back will report next action' Http::response(200, "Upgraded to {$version} ... post-upgrade checks!"); exit; } } else { //Abort: Upgrade pending but NOT upgradable - invalid or wrong hash. $upgrader->abort(sprintf('Upgrade Failed: Invalid or wrong hash [%s]', $ost->getDBSignature())); } } elseif (!$ost->isUpgradePending()) { $upgrader->setState('done'); session_write_close(); Http::response(201, "We're done!"); exit; } if ($upgrader->isAborted() || $upgrader->getErrors()) { Http::response(416, "We have a problem ... wait a sec."); exit; } Http::response(200, $upgrader->getNextAction()); }
if (!$ost->isUpgradePending()) { $errors['err'] = ' Nothing to do! System already upgraded to the current version'; } elseif (!$upgrader->isUpgradable()) { $errors['err'] = 'The upgrader does NOT support upgrading from the current vesion!'; } elseif (!$upgrader->check_prereq()) { $errors['prereq'] = 'Minimum requirements not met! Refer to Release Notes for more information'; } elseif (!strcasecmp(basename(CONFIG_FILE), 'settings.php')) { $errors['err'] = 'Config file rename required to continue!'; } else { $upgrader->setState('upgrade'); } break; case 'upgrade': //Manual upgrade.... when JS (ajax) is not supported. if ($upgrader->getNumPendingTasks()) { $upgrader->doTasks(); } elseif ($ost->isUpgradePending() && $upgrader->isUpgradable()) { $upgrader->upgrade(); } elseif (!$ost->isUpgradePending()) { $upgrader->setState('done'); } if ($errors = $upgrader->getErrors()) { $upgrader->setState('aborted'); } break; default: $errors['err'] = 'Unknown action!'; } } switch (strtolower($upgrader->getState())) { case 'aborted':