diff --git a/include/ajax.upgrader.php b/include/ajax.upgrader.php new file mode 100644 index 0000000000000000000000000000000000000000..1582b7a8c490af2c26f70e4b48f857e758239686 --- /dev/null +++ b/include/ajax.upgrader.php @@ -0,0 +1,65 @@ +<?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()); + } +} +?> diff --git a/scp/ajax.php b/scp/ajax.php index 2310fc67ae9102ab1df3865b45c816ae26595cb0..3237da53fe982d14a3b3e4a6aed6a4bc2ed02bca 100644 --- a/scp/ajax.php +++ b/scp/ajax.php @@ -66,7 +66,8 @@ $dispatcher = patterns('', url_post('^(?P<tid>\d+)/lock/(?P<id>\d+)/release', 'releaseLock'), url_get('^lookup', 'lookup'), url_get('^search', 'search') - )) + )), + url_post('^/upgrader', array('ajax.upgrader.php:UpgraderAjaxAPI', 'upgrade')) ); # Call the respective function