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

Add ability to switch to manual upgrade mode on ajax failure - 404 error.

parent 57c8fee1
No related branches found
No related tags found
No related merge requests found
<?php
if(!defined('OSTSCPINC') || !$thisstaff || !$thisstaff->isAdmin()) die('Access Denied');
//See if we need to switch the mode of upgrade...e.g from ajax (default) to manual
if(($mode = $ost->get_var('m', $_GET)) && $mode!=$upgrader->getMode()) {
//Set Persistent mode/
$upgrader->setMode($mode);
//Log warning about ajax calls - most likely culprit is AcceptPathInfo directive.
if($mode=='manual')
$ost->logWarning('Ajax calls are failing',
'Make sure your server has AcceptPathInfo directive set to "ON" or get technical help');
}
$action=$upgrader->getNextAction();
?>
<h2>osTicket Upgrade</h2>
......@@ -9,7 +20,7 @@ $action=$upgrader->getNextAction();
<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><?php echo $action ?></h2>
<h2 id="task"><?php echo $action ?></h2>
<p>The upgrade wizard will now attempt to upgrade your database and core settings!</p>
<ul>
<li>Database enhancements</li>
......@@ -20,8 +31,9 @@ $action=$upgrader->getNextAction();
<form method="post" action="upgrade.php" id="upgrade">
<?php csrf_token(); ?>
<input type="hidden" name="s" value="upgrade">
<input type="hidden" id="mode" name="m" value="<?php echo $upgrader->getMode(); ?>">
<input type="hidden" name="sh" value="<?php echo $upgrader->getSchemaSignature(); ?>">
<input class="btn" type="submit" name="submit" value="Do It Now!">
<input class="btn" type="submit" name="submit" value="Upgrade Now!">
</form>
</div>
</div>
......@@ -33,9 +45,11 @@ $action=$upgrader->getNextAction();
</div>
<div class="clear"></div>
<div id="upgrading">
<h4><?php echo $action; ?></h4>
<h4 id="action"><?php echo $action; ?></h4>
Please wait... while we upgrade your osTicket installation!
<div id="msg" style="font-weight: bold;padding-top:10px;">Smile!</div>
<div id="msg" style="font-weight: bold;padding-top:10px;">
<?php echo sprintf("%s - Relax!", $thisstaff->getFirstName()); ?>
</div>
</div>
</div>
<div class="clear"></div>`
<div class="clear"></div>
jQuery(function($) {
$("#overlay").css({
opacity : 0.3,
top : 0,
......@@ -12,18 +12,21 @@ jQuery(function($) {
top : ($(window).height() / 3),
left : ($(window).width() / 2 - 160)
});
$('form#upgrade').submit(function(e) {
e.preventDefault();
var form = $(this);
$('input[type=submit]', this).attr('disabled', 'disabled');
$('#overlay, #upgrading').show();
doTasks('upgrade.php',form.serialize());
return false;
});
if($('input#mode', form).val() == 'manual') {
return true;
} else {
e.preventDefault();
autoUpgrade('upgrade.php',form.serialize());
return false;
}
});
function doTasks(url, data) {
function autoUpgrade(url, data) {
function _lp(count) {
$.ajax({
type: 'POST',
......@@ -33,26 +36,34 @@ jQuery(function($) {
data: data,
dataType: 'text',
success: function(res) {
if (res) {
$('#loading #msg').html(res);
}
$('#main #task').html(res);
$('#upgrading #action').html(res);
$('#upgrading #msg').html('Still busy... smile #'+count);
},
statusCode: {
200: function() {
setTimeout(function() { _lp(count+1); }, 2);
setTimeout(function() { _lp(count+1); }, 200);
},
201: function() {
$('#loading #msg').html("We're done... cleaning up!");
$('#upgrading #msg').html("Cleaning up!...");
setTimeout(function() { location.href =url+'?c='+count+'&r='+Math.floor((Math.random()*100)+1); }, 3000);
}
},
error: function() {
$('#loading #msg').html("Something went wrong");
setTimeout(function() { location.href =url+'?c='+count+'&r='+Math.floor((Math.random()*100)+1); }, 1000);
error: function(jqXHR, textStatus, errorThrown) {
$('#upgrading #action').html('Error occurred. Aborting...');
switch(jqXHR.status) {
case 404:
$('#upgrading #msg').html("Manual upgrade required (ajax failed)");
setTimeout(function() { location.href =url+'?m=manual&c='+count+'&r='+Math.floor((Math.random()*100)+1); }, 2000);
break;
default:
$('#upgrading #msg').html("Something went wrong");
setTimeout(function() { location.href =url+'?c='+count+'&r='+Math.floor((Math.random()*100)+1); }, 2000);
}
}
});
};
_lp(0);
_lp(1);
}
});
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