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

Add upgrade capabilities to the setup wizard

parent a3b6e39e
Branches
Tags
No related merge requests found
Showing
with 490 additions and 248 deletions
<?php
/*********************************************************************
cleanup.php
Cleanup script called via ajax to migrate attachments.
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:
**********************************************************************/
session_start();
if($_GET['c']>10) { //When Done send 304 - nothing else to do.
$_SESSION['s']='done';
session_write_close();
header("HTTP/1.1 304 Not Modified");
exit;
}
echo "Cleaning up...".time();
?>
...@@ -70,7 +70,7 @@ form .row span { width: 600px; color: #666666; } ...@@ -70,7 +70,7 @@ form .row span { width: 600px; color: #666666; }
#overlay { display: none; position: fixed; background: #000; z-index: 2000; } #overlay { display: none; position: fixed; background: #000; z-index: 2000; }
#loading { padding: 10px 10px 10px 60px; width: 300px; height: 100px; background: url('../images/ajax-loader.gif?1312925608') 10px 50% no-repeat white; position: fixed; display: none; z-index: 3000; } #loading { padding: 10px 10px 10px 60px; width: 400px; height: 150px; background: url('../images/ajax-loader.gif?1312925608') 10px 50% no-repeat white; position: fixed; display: none; z-index: 3000; }
#loading h4 { margin: 3px 0 0 0; padding: 0; color: #d80; } #loading h4 { margin: 3px 0 0 0; padding: 0; color: #d80; }
.tip { display: inline-block; width: 16px; height: 16px; outline: none; text-decoration: none; color: #d80; } .tip { display: inline-block; width: 16px; height: 16px; outline: none; text-decoration: none; color: #d80; }
......
...@@ -21,8 +21,8 @@ Class SetupWizard { ...@@ -21,8 +21,8 @@ Class SetupWizard {
'mysql' => '4.4'); 'mysql' => '4.4');
//Version info - same as the latest version. //Version info - same as the latest version.
var $version ='1.7-rc1'; var $version ='1.7-dpr2';
var $version_verbose='1.7 RC 1'; var $version_verbose='1.7 DPR 2';
//Errors //Errors
var $errors=array(); var $errors=array();
...@@ -31,18 +31,18 @@ Class SetupWizard { ...@@ -31,18 +31,18 @@ Class SetupWizard {
$this->errors=array(); $this->errors=array();
} }
function load_sql_file($file, $prefix, $debug=false) { function load_sql_file($file, $prefix, $abort=true, $debug=false) {
if(!file_exists($file) || !($schema=file_get_contents($file))) if(!file_exists($file) || !($schema=file_get_contents($file)))
return $this->abort('Error accessing SQL file'); return $this->abort('Error accessing SQL file '.basename($file));
return $this->load_sql($schema, $prefix, $debug); return $this->load_sql($schema, $prefix, $abort, $debug);
} }
/* /*
load SQL schema - assumes MySQL && existing connection load SQL schema - assumes MySQL && existing connection
*/ */
function load_sql($schema, $prefix, $debug=false) { function load_sql($schema, $prefix, $abort=true, $debug=false) {
# Strip comments and remarks # Strip comments and remarks
$schema=preg_replace('%^\s*(#|--).*$%m','',$schema); $schema=preg_replace('%^\s*(#|--).*$%m','',$schema);
...@@ -57,7 +57,8 @@ Class SetupWizard { ...@@ -57,7 +57,8 @@ Class SetupWizard {
foreach($statements as $k=>$sql) { foreach($statements as $k=>$sql) {
if(!mysql_query($sql)) { if(!mysql_query($sql)) {
if($debug) echo "[$sql]=>".mysql_error(); if($debug) echo "[$sql]=>".mysql_error();
return $this->abort("[$sql] - ".mysql_error()); if($abort)
return $this->abort("[$sql] - ".mysql_error());
} }
} }
...@@ -96,15 +97,18 @@ Class SetupWizard { ...@@ -96,15 +97,18 @@ Class SetupWizard {
@error is a mixed var. @error is a mixed var.
*/ */
function abort($error) { function abort($error) {
$this->onError($error);
return false; // Always false... It's an abort.
}
function setError($error) {
if($error && is_array($error)) if($error && is_array($error))
$this->errors = array_merge($this->errors,$error); $this->errors = array_merge($this->errors,$error);
elseif($error) elseif($error)
$this->errors[] = $error; $this->errors[] = $error;
//Always returns FALSE.
return false;
} }
function getErrors(){ function getErrors(){
...@@ -112,91 +116,271 @@ Class SetupWizard { ...@@ -112,91 +116,271 @@ Class SetupWizard {
return $this->errors; return $this->errors;
} }
/* Access and user validation*/ function onError($error) {
return $this->setError($error);
function getThisUser() {
} }
} }
class Upgrader extends SetupWizard { class Upgrader extends SetupWizard {
var $prefix; var $prefix;
var $sqldir;
var $signature;
function Upgrader($prefix) { function Upgrader($signature, $prefix, $sqldir) {
$this->signature = $signature;
$this->shash = substr($signature, 0, 8);
$this->prefix = $prefix; $this->prefix = $prefix;
$this->sqldir = $sqldir;
$this->errors = array(); $this->errors = array();
//Init persistent state of upgrade.
$this->state = &$_SESSION['ost_upgrader'][$this->getShash()]['state'];
//Init the task Manager.
if(!isset($_SESSION['ost_upgrader'][$this->getShash()]))
$_SESSION['ost_upgrader'][$this->getShash()]['tasks']=array();
//Tasks to perform - saved on the session.
$this->tasks = &$_SESSION['ost_upgrader'][$this->getShash()]['tasks'];
}
function onError($error) {
$this->setError($error);
$this->setState('aborted');
}
function isUpgradable() {
return (!$this->isAborted() && $this->getNextPatch());
}
function isAborted() {
return !strcasecmp($this->getState(), 'aborted');
}
function getSchemaSignature() {
return $this->signature;
}
function getShash() {
return $this->shash;
} }
function getTablePrefix() { function getTablePrefix() {
return $this->prefix; return $this->prefix;
} }
/* upgrade magic related to the given version */ function getSQLDir() {
function upgradeTo($version) { return $this->sqldir;
}
$errors = array(); function getState() {
switch($version) { return $this->state;
case '1.7-RC1': }
//TODO: latest upgrade logic.
break; function setState($state) {
case '1.6 ST': $this->state = $state;
//TODO: refactor code from 1.6 ST. }
break;
case '1.6 RC5': function getNextPatch() {
//TODO: refactor code from 1.6 ST.
if(!($patch=glob($this->getSQLDir().$this->getShash().'-*.patch.sql')))
return null;
return $patch[0];
}
function getThisPatch() {
if(!($patch=glob($this->getSQLDir().'*-'.$this->getShash().'.patch.sql')))
return null;
return $patch[0];
}
function getNextVersion() {
if(!$patch=$this->getNextPatch())
return '(Latest)';
if(preg_match('/\*(.*)\*/', file_get_contents($patch), $matches))
$info=$matches[0];
else
$info=substr(basename($patch), 9, 8);
return $info;
}
function getNextAction() {
$action='Upgrade osTicket to '.$this->getVersion();
if($this->getNumPendingTasks() && ($task=$this->getNextTask())) {
$action = $task['desc'];
if($task['status']) //Progress report...
$action.=' ('.$task['status'].')';
} elseif($this->isUpgradable() && ($nextversion = $this->getNextVersion())) {
$action = "Upgrade to $nextversion";
}
return $action;
}
function getNextStepInfo() {
if(($patches=$this->getPatches()))
return $patches[0];
if(($hooks=$this->getScriptedHooks()))
return $hooks[0]['desc'];
return null;
}
function getPatches($ToSignature) {
$signature = $this->getSignature();
$patches = array();
while(($patch=glob($this->getSQLDir().substr($signature,0,8).'-*.patch.sql')) && $i++) {
$patches = array_merge($patches, $patch);
if(!($signature=substr(basename($patch[0]), 10, 8)) || !strncasecmp($signature, $ToSignature, 8))
break; break;
default:
//XXX: escape version
return $this->abort('Trying to upgrade unknown version '.$version);
} }
if($errors) return $patches;
return $this->abort($errors); }
return true; function getNumPendingTasks() {
return count($this->getPendingTasks());
} }
/* function getPendingTasks() {
Do base upgrade
Does fall-through upgrade until we reach the current version. $pending=array();
We're assumming the user - is upgrading upgradable version of osTicket! if(($tasks=$this->getTasks())) {
@version - version number to upgrade from! foreach($tasks as $k => $task) {
*/ if(!$task['done'])
function upgradeFrom($version) { $pending[$k] = $task;
}
if(!$version || $this->getErrors()) }
return $pending;
}
function getTasks() {
return $this->tasks;
}
function getNextTask() {
if(!($tasks=$this->getPendingTasks()))
return null;
return current($tasks);
}
function removeTask($tId) {
if(isset($this->tasks[$tId]))
unset($this->tasks[$tId]);
return (!$this->tasks[$tId]);
}
function setTaskStatus($tId, $status) {
if(isset($this->tasks[$tId]))
$this->tasks[$tId]['status'] = $status;
}
function doTasks() {
if(!($tasks=$this->getPendingTasks()))
return true; //Nothing to do.
foreach($tasks as $k => $task) {
if(call_user_func(array($this, $task['func']), $k)===0) {
$this->tasks[$k]['done'] = true;
} else { //Task has pending items to process.
break;
}
}
return (!$this->getPendingTasks());
}
function upgrade() {
if($this->getPendingTasks() || !($patch=$this->getNextPatch()))
return false;
if(!$this->load_sql_file($patch, $this->getTablePrefix()))
return false; return false;
//TODO: Log the upgrade
//Load up post install tasks.
$shash = substr(basename($patch), 9, 8);
$phash = substr(basename($patch), 0, 17);
if(!strcasecmp($version,$this->getVersion())) $tasks=array();
return true; $tasks[] = array('func' => 'sometask',
'desc' => 'Some Task.... blah');
//XXX: Note FALLTHROUGH (we only break on error) and uppercase cases. switch($phash) { //Add patch specific scripted tasks.
switch(strtoupper($version)) { case 'xxxx': //V1.6 ST- 1.7 *
case 'OLD': //Upgrade old versions to 1.6 ST. $tasks[] = array('func' => 'migrateAttachments2DB',
if(!$this->upgradeTo('1.6 RC5')) break; 'desc' => 'Migrating attachments to database, it might take a while depending on the number of files.');
/* FALLTHROUGH */
case '1.6 RC5': //Upgrade 1.6 RC5 to 1.6 ST
if(!$this->upgradeTo('1.6 ST')) break;
/* FALLTHROUGH */
case '1.6 ST': //Upgrade 1.6 ST to to 1.7 RC1
if(!$this->upgradeTo('1.7-RC1')) break;
/* LAST CASE IS NOT FALLTHROUGH */
break; break;
default: //Catch all - Upgrading older versions 1.3+
return $this->upgradeFrom('OLD');
} }
//XXX: Set errors???
$tasks[] = array('func' => 'cleanup',
return (!$this->getErrors()); 'desc' => 'Post-upgrade cleanup!');
//Load up tasks - NOTE: writing directly to the session - back to the future majic.
$_SESSION['ost_upgrader'][$shash]['tasks'] = $tasks;
$_SESSION['ost_upgrader'][$shash]['state'] = 'upgrade';
//clear previous patch info -
unset($_SESSION['ost_upgrader'][$this->getSHash()]);
return true;
} }
function cleanup() { /************* TASKS **********************/
//FIXME: cleanup logic here. function sometask($tId) {
$this->setTaskStatus($tId, 'Doing... '.time(). ' #'.$_SESSION['sometask']);
sleep(2); sleep(2);
$_SESSION['sometask']+=1;
if($_SESSION['sometask']<4)
return 22;
return true; $_SESSION['sometask']=0;
return 0; //Change to 1 for testing...
}
function cleanup($tId=0) {
$file=$this->getSQLDir().$this->getSchemaSignature().'-cleanup.sql';
if(!file_exists($file)) //No cleanup script.
return 0;
//We have a cleanup script ::XXX: Don't abort on error?
if($this->load_sql_file($file, $this->getTablePrefix(), false, true))
return 0;
//XXX: ???
return false;
}
function migrateAttachments2DB($tId=0) {
echo "Process attachments here - $tId";
return 0;
} }
} }
...@@ -297,7 +481,7 @@ class Installer extends SetupWizard { ...@@ -297,7 +481,7 @@ class Installer extends SetupWizard {
$this->errors['err']='Unable to read config file. Permission denied! (#2)'; $this->errors['err']='Unable to read config file. Permission denied! (#2)';
elseif(!($fp = @fopen($this->getConfigFile(),'r+'))) elseif(!($fp = @fopen($this->getConfigFile(),'r+')))
$this->errors['err']='Unable to open config file for writing. Permission denied! (#3)'; $this->errors['err']='Unable to open config file for writing. Permission denied! (#3)';
elseif(!$this->load_sql_file($schemaFile,$vars['prefix'],$debug)) elseif(!$this->load_sql_file($schemaFile,$vars['prefix'], true, $debug))
$this->errors['err']='Error parsing SQL schema! Get help from developers (#4)'; $this->errors['err']='Error parsing SQL schema! Get help from developers (#4)';
if(!$this->errors) { if(!$this->errors) {
......
/* v1.7-DPR2-P2 */
UPDATE `%TABLE_PREFIX%sla` UPDATE `%TABLE_PREFIX%sla`
SET `created` = NOW(), SET `created` = NOW(),
`updated` = NOW() `updated` = NOW()
......
/* v1.7-DPR1 (P1) */
UPDATE `%TABLE_PREFIX%email_template` UPDATE `%TABLE_PREFIX%email_template`
SET `ticket_overlimit_subj` = 'Open Tickets Limit Reached' SET `ticket_overlimit_subj` = 'Open Tickets Limit Reached'
WHERE `tpl_id` = 1 AND `cfg_id` = 1; WHERE `tpl_id` = 1 AND `cfg_id` = 1;
......
...@@ -6,17 +6,18 @@ if(!defined('SETUPINC')) die('Kwaheri!'); ...@@ -6,17 +6,18 @@ if(!defined('SETUPINC')) die('Kwaheri!');
<div id="intro"> <div id="intro">
<p>Upgrade aborted due to errors. Any errors at this stage are fatal. Please note the error(s), if any, when contacting us.<p> <p>Upgrade aborted due to errors. Any errors at this stage are fatal. Please note the error(s), if any, when contacting us.<p>
<?php <?php
if($_SESSION['upgrader']['errors']) { if($upgrader && ($errors=$upgrader->getErrors())) {
$errors=$_SESSION['upgrader']['errors'];
if($errors['err']) if($errors['err'])
echo sprintf('<b><font color="red">%s</font></b>',$errors['err']); echo sprintf('<b><font color="red">%s</font></b>',$errors['err']);
echo '<ul class="error">'; echo '<ul class="error">';
unset($errors['err']); unset($errors['err']);
foreach($errors as $k=>$error) foreach($errors as $k => $error)
echo sprintf('<li>%s</li>',$error); echo sprintf('<li>%s</li>',$error);
echo '</ul>'; echo '</ul>';
} ?> } else {
echo '<b><font color="red">Internal error occurred - get technical help.</font></b>';
}
?>
<p>Please, refer to the <a target="_blank" href="http://osticket.com/wiki/Upgrade_and_Migration">Upgrade Guide</a> on the wiki for more information.</p> <p>Please, refer to the <a target="_blank" href="http://osticket.com/wiki/Upgrade_and_Migration">Upgrade Guide</a> on the wiki for more information.</p>
</div> </div>
<p><strong>Need Help?</strong> We provide <a target="_blank" href="http://osticket.com/support/professional_services.php"><u>professional upgrade services</u></a> and commercial support. <a target="_blank" href="http://osticket.com/support/">Contact us</a> today for expedited help.</p> <p><strong>Need Help?</strong> We provide <a target="_blank" href="http://osticket.com/support/professional_services.php"><u>professional upgrade services</u></a> and commercial support. <a target="_blank" href="http://osticket.com/support/">Contact us</a> today for expedited help.</p>
......
<?php
if(!defined('SETUPINC')) die('Kwaheri!');
$msg = $_SESSION['ost_upgrader']['msg'];
?>
<div id="main">
<h1>Attachments Migration</h1>
<p>We're almost done! We're now migrating attachments to the database, it might take a while dending on the number of files in your database.<p>
<p style="color:#FF7700;font-weight:bold;">We have to migrate files in batches for technical reasons.</p>
<p>Please don't cancel or close the browser.</p>
<div id="bar">
<form method="post" action="upgrade.php" id="attachments">
<input type="hidden" name="s" value="cleanup">
<input class="btn" type="submit" name="submit" value="Next Batch">
</form>
</div>
</div>
<div id="sidebar">
<h3>Upgrade Tips</h3>
<p>1. Be patient the process will take a few minutes.</p>
<p>2. If you experience any problems, you can always restore your files/dabase backup.</p>
<p>3. We can help, feel free to <a href="http://osticket.com/support/" target="_blank">contact us </a> for professional help.</p>
</div>
<div id="overlay"></div>
<div id="loading">
<h4>Moving attachments</h4>
<br>
Please wait... while we migrate attachments!
<br><br>
<div id="msg" style="font-weight: bold;"><?php echo Format::htmlchars($msg); ?></div>
</div>
<?php
if(!defined('SETUPINC')) die('Kwaheri!');
?>
<div id="main">
<h1>osTicket Upgrade</h1>
<div id="intro">
<p>We're almost done! Please don't cancel or close the browser, any errors at this stage will be fatal.</p>
</div>
<h2>Cleanup: Step 2 of 2</h2>
<p>The upgrade wizard will now attempt to do post upgrade cleanup. It might take a while dending on the size of your database. </p>
<ul>
<li>Setting Changes</li>
<li>Attachment Migration</li>
<li>Database Optimization</li>
</ul>
<div id="bar">
<form method="post" action="upgrade.php" id="cleanup">
<input type="hidden" name="s" value="cleanup">
<input class="btn" type="submit" name="submit" value="Do It Now!">
</form>
</div>
</div>
<div id="sidebar">
<h3>Upgrade Tips</h3>
<p>1. Be patient the process will take a couple of seconds.</p>
<p>2. If you experience any problems, you can always restore your files/dabase backup.</p>
<p>3. We can help, feel free to <a href="http://osticket.com/support/" target="_blank">contact us </a> for professional help.</p>
</div>
<div id="overlay"></div>
<div id="loading">
<h4>Doing serious stuff!</h4>
<br>
Please wait... while we do post-upgrade cleanup!
<br><br>
<div id="msg" style="font-weight: bold;"></div>
</div>
<?php
if(!defined('SETUPINC')) die('Kwaheri!');
?>
<div id="main">
<h1>osTicket Upgrade</h1>
<div id="intro">
<p>Thank you for taking the time to upgrade your osTicket intallation!</p>
<p>Please don't cancel or close the browser, any errors at this
stage will be fatal.</p>
</div>
<h2>Base upgrade: Step 1 of 2</h2>
<p>The upgrade wizard will now attempt to upgrade your database and core settings!</p>
<ul>
<li>Database enhancements</li>
<li>New and updated features</li>
<li>Enhance settings and security</li>
</ul>
<div id="bar">
<form method="post" action="upgrade.php" id="upgrade">
<input type="hidden" name="s" value="upgrade">
<input class="btn" type="submit" name="submit" value="Do It Now!">
</form>
</div>
</div>
<div id="sidebar">
<h3>Upgrade Tips</h3>
<p>1. Be patient the process will take a couple of seconds.</p>
<p>2. If you experience any problems, you can always restore your files/dabase backup.</p>
<p>3. We can help, feel free to <a href="http://osticket.com/support/" target="_blank">contact us </a> for professional help.</p>
</div>
<div id="overlay"></div>
<div id="loading">
<h4>Doing serious stuff!</h4>
Please wait... while we upgrade your osTicket installation!
<div id="udb"><br><b>Smile!</b></div>
</div>
<?php
if(!defined('SETUPINC')) die('Kwaheri!');
?>
<div id="main">
<h1>osTicket Upgrade!</h1>
<font color="red"><b><?php echo $errors['err']; ?></b></font>
<div id="intro">
<p>Thank you for being a loyal osTicket user!</p>
<p>The upgrade wizard will guide you every step of the way in the upgrade process. While we try to ensure that the upgrade process is straightforward and painless, we can't guarantee it will be the case for every user.</p>
</div>
<h2>Getting ready!</h2>
<p>Before we begin, we'll check your server configuration to make sure you meet the minimum requirements to run the latest version of osTicket.</p>
<h3>Prerequisites: <font color="red"><?php echo $errors['prereq']; ?></font></h3>
These items are necessary in order to use osTicket the latest version of osTicket.
<ul class="progress">
<li class="<? echo $upgrader->check_php()?'yes':'no'; ?>">
PHP v4.3 or greater - (<small><b><?php echo PHP_VERSION; ?></b></small>)</li>
<li class="<? echo $upgrader->check_mysql()?'yes':'no'; ?>">
MySQL v4.4 or greater - (<small><b><?php echo extension_loaded('mysql')?'module loaded':'missing!'; ?></b></small>)</li>
</ul>
<h3>Higly Recommended:</h3>
We hightly recommend that you follow the steps below.
<ul>
<li>Take osTicket offline momentarily during upgrade.</li>
<li>Backup the current database, if you haven't done so already.</li>
<li>Be patient the upgrade process will take a couple of seconds.</li>
</ul>
<div id="bar">
<form method="post" action="upgrade.php" id="prereq">
<input type="hidden" name="s" value="prereq">
<input class="btn" type="submit" name="submit" value="Start Upgrade Now &raquo;">
</form>
</div>
</div>
<div id="sidebar">
<h3>Upgrade Tips</h3>
<p>1. Remember to backup your osTicket database</p>
<p>2. Take osTicket offline momentarily</p>
<p>3. If you experience any problems, you can always restore your files/dabase backup.</p>
<p>4. We can help, feel free to <a href="http://osticket.com/support/" target="_blank">contact us </a> for professional help.</p>
</div>
<div id="overlay"></div>
<div id="loading">
<h4>Doing stuff!</h4>
Please wait... while we upgrade your osTicket installation!
<div id="udb"></div>
</div>
<?php <?php
if(!defined('SETUPINC')) die('Kwaheri!'); if(!defined('SETUPINC') || !$upgrader) die('Kwaheri!');
$action=$upgrader->getNextAction();
?> ?>
<div id="main"> <div id="main">
<h1>osTicket Upgrade!</h1> <h1>osTicket Upgrade</h1>
<font color="red"><b><?php echo $errors['err']; ?></b></font>
<div id="intro"> <div id="intro">
<p>Thank you for being a loyal osTicket user!</p> <p>Thank you for taking the time to upgrade your osTicket intallation!</p>
<p>The upgrade wizard will guide you every step of the way in the upgrade process. While we try to ensure that the upgrade process is straightforward and painless, we can't guarantee it will be the case for every user.</p> <p>Please don't cancel or close the browser, any errors at this
stage will be fatal.</p>
</div> </div>
<h2>Getting ready!</h2> <h2><?php echo $action ?></h2>
<p>Before we begin, we'll check your server configuration to make sure you meet the minimum requirements to run the latest version of osTicket.</p> <p>The upgrade wizard will now attempt to upgrade your database and core settings!</p>
<h3>Prerequisites: <font color="red"><?php echo $errors['prereq']; ?></font></h3>
These items are necessary in order to use osTicket the latest version of osTicket.
<ul class="progress">
<li class="<? echo $upgrader->check_php()?'yes':'no'; ?>">
PHP v4.3 or greater - (<small><b><?php echo PHP_VERSION; ?></b></small>)</li>
<li class="<? echo $upgrader->check_mysql()?'yes':'no'; ?>">
MySQL v4.4 or greater - (<small><b><?php echo extension_loaded('mysql')?'module loaded':'missing!'; ?></b></small>)</li>
</ul>
<h3>Higly Recommended:</h3>
We hightly recommend that you follow the steps below.
<ul> <ul>
<li>Take osTicket offline momentarily during upgrade.</li> <li>Database enhancements</li>
<li>Backup the current database, if you haven't done so already.</li> <li>New and updated features</li>
<li>Be patient the upgrade process will take a couple of seconds.</li> <li>Enhance settings and security</li>
</ul> </ul>
<div id="bar"> <div id="bar">
<form method="post" action="upgrade.php" id="upgrade"> <form method="post" action="upgrade.php" id="upgrade">
<input type="hidden" name="s" value="prereq"> <input type="hidden" name="s" value="upgrade">
<input class="btn" type="submit" name="submit" value="Start Upgrade Now &raquo;"> <input type="hidden" name="sh" value="<?php echo $upgrader->getSchemaSignature(); ?>">
<input class="btn" type="submit" name="submit" value="Do It Now!">
</form> </form>
</div> </div>
</div> </div>
<div id="sidebar"> <div id="sidebar">
<h3>Upgrade Tips</h3> <h3>Upgrade Tips</h3>
<p>1. Remember to backup your osTicket database</p> <p>1. Be patient the process will take a couple of seconds.</p>
<p>2. Take osTicket offline momentarily</p> <p>2. If you experience any problems, you can always restore your files/dabase backup.</p>
<p>3. If you experience any problems, you can always restore your files/dabase backup.</p> <p>3. We can help, feel free to <a href="http://osticket.com/support/" target="_blank">contact us </a> for professional help.</p>
<p>4. We can help, feel free to <a href="http://osticket.com/support/" target="_blank">contact us </a> for professional help.</p>
</div> </div>
<div id="overlay"></div> <div id="overlay"></div>
<div id="loading"> <div id="loading">
<h4>Doing stuff!</h4> <h4><?php echo $action; ?></h4>
Please wait... while we upgrade your osTicket installation! Please wait... while we upgrade your osTicket installation!
<div id="udb"></div> <div id="msg" style="font-weight: bold;padding-top:10px;">Smile!</div>
</div> </div>
...@@ -13,30 +13,30 @@ jQuery(function($) { ...@@ -13,30 +13,30 @@ jQuery(function($) {
left : ($(window).width() / 2 - 160) left : ($(window).width() / 2 - 160)
}); });
$('form#install, form#upgrade, form#attachments').submit(function(e) { $('form#install').submit(function(e) {
$('input[type=submit]', this).attr('disabled', 'disabled'); $('input[type=submit]', this).attr('disabled', 'disabled');
$('#overlay, #loading').show(); $('#overlay, #loading').show();
return true; return true;
}); });
$('form#cleanup').submit(function(e) { $('form#upgrade').submit(function(e) {
e.preventDefault(); e.preventDefault();
var form = $(this); var form = $(this);
$('input[type=submit]', this).attr('disabled', 'disabled'); $('input[type=submit]', this).attr('disabled', 'disabled');
$('#overlay, #loading').show(); $('#overlay, #loading').show();
doCleanup('upgrade',form.attr('action')); doTasks('upgrade.php',form.serialize());
return false; return false;
}); });
function doTasks(url, data) {
function doCleanup(type,url) {
function _lp(count) { function _lp(count) {
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: 'cleanup.php', url: 'p.php',
async: true, async: true,
cache: false, cache: false,
data: {c:count,type:type}, data: data,
dataType: 'text', dataType: 'text',
success: function(res) { success: function(res) {
if (res) { if (res) {
...@@ -45,16 +45,17 @@ jQuery(function($) { ...@@ -45,16 +45,17 @@ jQuery(function($) {
}, },
statusCode: { statusCode: {
200: function() { 200: function() {
setTimeout(function() { _lp(count+1); },2); setTimeout(function() { _lp(count+1); }, 2);
}, },
304: function() { 304: function() {
$('#loading #msg').html("We're done... "); $('#loading #msg').html("We're done... cleaning up!");
setTimeout(function() { location.href =url;},1000); setTimeout(function() { location.href =url;}, 3000);
} }
}, },
error: function(){ error: function() {
alert("Something went wrong"); $('#loading #msg').html("Something went wrong");
setTimeout(function() { location.href =url;}, 1000);
} }
}); });
}; };
......
<?php
/*********************************************************************
upgrader.php
osTicket Upgrader Helper - called via ajax.
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:
**********************************************************************/
function staffLoginPage($msg) {
Http::response(403, $msg?$msg:'Access Denied');
exit;
}
require '../scp/staff.inc.php';
if(!$thisstaff or !$thisstaff->isadmin()) {
staffLoginPage('Admin Access Required!');
exit;
}
define('SETUPINC', true);
define('INC_DIR', './inc/');
define('SQL_DIR', INC_DIR.'sql/');
require_once INC_DIR.'class.setup.php';
$upgrader = new Upgrader($cfg->getSchemaSignature(), TABLE_PREFIX, SQL_DIR);
//Just report the next action on the first call.
if(!$_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() && $cfg->isUpgradePending()) {
//Just reporting done...with tasks - break in between patches!
header("HTTP/1.1 304 Not Modified");
exit;
}
} elseif($cfg->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(!$cfg->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());
?>
...@@ -57,5 +57,4 @@ require_once(INCLUDE_DIR.'class.validator.php'); ...@@ -57,5 +57,4 @@ require_once(INCLUDE_DIR.'class.validator.php');
require_once(INCLUDE_DIR.'class.format.php'); require_once(INCLUDE_DIR.'class.format.php');
require_once(INCLUDE_DIR.'class.misc.php'); require_once(INCLUDE_DIR.'class.misc.php');
require_once(INCLUDE_DIR.'mysql.php'); require_once(INCLUDE_DIR.'mysql.php');
?> ?>
...@@ -13,5 +13,84 @@ ...@@ -13,5 +13,84 @@
vim: expandtab sw=4 ts=4 sts=4: vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/ **********************************************************************/
die('Upgrade NOT supported for v1.7 DPR.'); function staffLoginPage($msg) {
$_SESSION['_staff']['auth']['dest']=THISPAGE;
$_SESSION['_staff']['auth']['msg']=$msg;
header('Location: ../scp/login.php');
exit;
}
require '../scp/staff.inc.php';
if(!$thisstaff or !$thisstaff->isadmin()) {
staffLoginPage('Admin Access Required!');
exit;
}
define('SETUPINC', true);
define('INC_DIR', './inc/');
define('SQL_DIR', INC_DIR.'sql/');
require_once INC_DIR.'class.setup.php';
//$_SESSION['ost_upgrader']=null;
$upgrader = new Upgrader($cfg->getSchemaSignature(), TABLE_PREFIX, SQL_DIR);
$wizard=array();
$wizard['title']='osTicket Upgrade Wizard';
$wizard['tagline']='Upgrading osTicket to v'.$upgrader->getVersionVerbose();
$wizard['logo']='logo-upgrade.png';
$wizard['menu']=array('Upgrade Guide'=>'http://osticket.com/wiki/Upgrade_and_Migration',
'Get Professional Help'=>'http://osticket.com/support');
$errors=array();
if($_POST && $_POST['s'] && !$upgrader->isAborted()) {
switch(strtolower($_POST['s'])) {
case 'prereq':
//XXX: check if it's upgradable version??
if(!$cfg->isUpgradePending())
$errors['err']=' Nothing to do! System already upgraded to the current version';
elseif($upgrader->check_prereq())
$upgrader->setState('upgrade');
else
$errors['prereq']='Minimum requirements not met!';
break;
case 'upgrade': //Manual upgrade.... when JS (ajax) is not supported.
if($upgrader->getNumPendingTasks()) {
$upgrader->doTasks();
} elseif($cfg->isUpgradePending() && $upgrader->isUpgradable()) {
$upgrader->upgrade();
} elseif(!$cfg->isUpgradePending()) {
$upgrader->setState('done');
}
if(($errors=$upgrader->getErrors())) {
$upgrader->setState('aborted');
}
break;
default:
$errors['err']='Unknown action!';
}
}
switch(strtolower($upgrader->getState())) {
case 'aborted':
$inc='upgrade-aborted.inc.php';
break;
case 'upgrade':
$inc='upgrade.inc.php';
break;
case 'done':
$inc='upgrade-done.inc.php';
break;
default:
$inc='upgrade-prereq.inc.php';
if($upgrader->isAborted())
$inc='upgrade-aborted.inc.php';
elseif(!$cfg->isUpgradePending())
$errors['err']='Nothing to do! System already upgraded to the latest version';
}
require(INC_DIR.'header.inc.php');
require(INC_DIR.$inc);
require(INC_DIR.'footer.inc.php');
?> ?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment