Skip to content
Snippets Groups Projects
Commit 0933adb2 authored by Peter Rotich's avatar Peter Rotich
Browse files

Add upgrader support to AJAX interface

parent f02fbbe1
No related branches found
No related tags found
No related merge requests found
<?php
/*********************************************************************
ajax.upgrader.php
AJAX interface for Upgrader
Peter Rotich <peter@osticket.com>
Copyright (c) 2006-2012 osTicket
http://www.osticket.com
Released under the GNU General Public License WITHOUT ANY WARRANTY.
See LICENSE.TXT for details.
vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/
if(!defined('INCLUDE_DIR')) die('403');
require_once INCLUDE_DIR.'class.upgrader.php';
class UpgraderAjaxAPI extends AjaxController {
function upgrade() {
global $thisstaff, $ost;
if(!$thisstaff or !$thisstaff->isAdmin() or !$ost)
Http::response(403, 'Access Denied');
$upgrader = new Upgrader($ost->getDBSignature(), TABLE_PREFIX, PATCH_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->getNumPendingTasks()) {
if($upgrader->doTasks() && !$upgrader->getNumPendingTasks() && $ost->isUpgradePending()) {
//Just reporting done...with tasks - break in between patches!
header("HTTP/1.1 304 Not Modified");
exit;
}
} elseif($ost->isUpgradePending() && $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;
}
} elseif(!$ost->isUpgradePending()) {
$upgrader->setState('done');
session_write_close();
header("HTTP/1.1 304 Not Modified");
exit;
}
if($upgrader->isAborted() || $upgrader->getErrors()) {
Http::response(416, "We have a problem ... wait a sec.");
exit;
}
Http::response(200, $upgrader->getNextAction());
}
}
?>
...@@ -66,7 +66,8 @@ $dispatcher = patterns('', ...@@ -66,7 +66,8 @@ $dispatcher = patterns('',
url_post('^(?P<tid>\d+)/lock/(?P<id>\d+)/release', 'releaseLock'), url_post('^(?P<tid>\d+)/lock/(?P<id>\d+)/release', 'releaseLock'),
url_get('^lookup', 'lookup'), url_get('^lookup', 'lookup'),
url_get('^search', 'search') url_get('^search', 'search')
)) )),
url_post('^/upgrader', array('ajax.upgrader.php:UpgraderAjaxAPI', 'upgrade'))
); );
# Call the respective function # Call the respective function
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment