'.$this->l('upgrade complete. Please check your front-office (try to make an order, check theme)').'
")
.show("slow");
$("#dbCreateResultCheck")
.hide("slow");
$("#infoStep").html("restoreFiles '.$this->l('click to restore files').'");
prepareNextButton("#restoreFiles",{});
}
function doAjaxRequest(action, nextParams){
// myNext, used when json is not available but response is correct
myNext = nextParams;
req = $.ajax({
type:"POST",
url : "'.($this->standalone? __PS_BASE_URI__ . trim($this->adminDir,DIRECTORY_SEPARATOR).'/autoupgrade/ajax-upgradetab.php' : str_replace('index','ajax-tab',$currentIndex)).'",
async: true,
data : {
dir:"'.trim($this->adminDir,DIRECTORY_SEPARATOR).'",
ajaxMode : "1",
token : "'.$this->token.'",
tab : "'.get_class($this).'",
action : action,
params : nextParams
},
success : function(res,textStatus,jqXHR)
{
if(eval("typeof nextParams") == "undefined")
{
nextParams = {typeResult : "json"};
}
if (nextParams.typeResult == "xml")
{
res = handleXMLResult(res,nextParams);
// res.next = xmlRes;
// if xml, we keep the next params
// nextParams = xmlRes;
// console.info(nextParams);
// res.status = xmlRes.status;
}
else
{
try{
res = $.parseJSON(res);
nextParams = res.nextParams;
}
catch(e){
res = {status : "error"};
alert("error during "+action);
/*
nextParams = {
error:"0",
next:"cancelUpgrade",
nextDesc:"Error detected during ["+action+"] step, reverting...",
nextQuickInfo:[],
status:"ok",
"stepDone":true
}
*/
}
}
if (res.status == "ok")
{
$("#"+action).addClass("done");
if (res.stepDone)
$("#"+action).addClass("stepok");
// if a function "after[action name]" exists, it should be called.
// This is used for enabling restore buttons for example
funcName = "after"+ucFirst(action);
if (typeof funcName == "string" &&
eval("typeof " + funcName) == "function") {
eval(funcName+"()");
}
handleSuccess(res,nextParams.typeResult);
}
else
{
// display progression
$("#"+action).addClass("done");
$("#"+action).addClass("steperror");
handleError(res);
}
},
error: function(res,textStatus,jqXHR)
{
if (textStatus == "timeout" && action == "download")
{
updateInfoStep("'.$this->l('Your server can\'t download the file. Please upload it first by ftp in your admin/autoupgrade directory').'");
}
else
{
updateInfoStep("[Server Error] Status message : " + textStatus);
}
}
});
};
/**
* prepareNextButton make the button button_selector available, and update the nextParams values
*
* @param button_selector $button_selector
* @param nextParams $nextParams
* @return void
*/
function prepareNextButton(button_selector, nextParams)
{
$(button_selector).unbind();
$(button_selector).click(function(e){
e.preventDefault();
$("#currentlyProcessing").show();
';
if (defined('_PS_MODE_DEV_') AND _PS_MODE_DEV_)
$js .= 'addQuickInfo(["[DEV] request : "+$(this).attr("id")]);';
$js .= '
action = button_selector.substr(1);
res = doAjaxRequest(action, nextParams);
});
}
/**
* handleSuccess
* res = {error:, next:, nextDesc:, nextParams:, nextQuickInfo:,status:"ok"}
* @param res $res
* @return void
*/
function handleSuccess(res)
{
updateInfoStep(res.nextDesc);
if (res.next != "")
{
addQuickInfo(res.nextQuickInfo);
$("#"+res.next).addClass("nextStep");
if (manualMode)
{
prepareNextButton("#"+res.next,res.nextParams);
alert("manually go to "+res.next+" button ");
}
else
{
// @TODO :
// 1) instead of click(), call a function.
doAjaxRequest(res.next,res.nextParams);
// 2) remove all step link (or show them only in dev mode)
// 3) when steps link displayed, they should change color when passed
}
}
else
{
// Way To Go, end of upgrade process
addQuickInfo(["End of upgrade process"]);
}
}
// res = {nextParams, NextDesc}
function handleError(res)
{
// display error message in the main process thing
updateInfoStep(res.nextDesc);
addQuickInfo(res.nextQuickInfo);
// In case the rollback button has been desactivated, just re-enable it
prepareNextButton("#rollback",res.nextParams);
// ask if you want to rollback
// @TODO !!!
if (confirm(res.NextDesc+"\r\r'.$this->l('Do you want to rollback ?').'"))
{
if (manualMode)
alert("'.$this->l('Please go manually go to rollback button').'");
else
{
$("#rollback").click();
}
}
}
';
// ajax to check md5 files
$js.= '$(document).ready(function(){
$.ajax({
type:"POST",
url : "'.($this->standalone? __PS_BASE_URI__ . trim($this->adminDir,DIRECTORY_SEPARATOR).'/autoupgrade/ajax-upgradetab.php' : str_replace('index','ajax-tab',$currentIndex)).'",
async: true,
data : {
dir:"'.trim($this->adminDir,DIRECTORY_SEPARATOR).'",
token : "'.$this->token.'",
tab : "'.get_class($this).'",
action : "checkFilesVersion",
params : {}
},
success : function(res,textStatus,jqXHR)
{
res = $.parseJSON(res);
answer = res.nextParams;
$("#checkPrestaShopFilesVersion").html("
"+answer.msg+" ");
$("#checkPrestaShopFilesVersion").append("
'.$this->l('See or hide the list').'");
$("#checkPrestaShopFilesVersion").append("
");
$("#changedList").html("
");
$(answer.result).each(function(k,v){
$("#changedList ul").append("- "+v+"
");
});
$("#toggleChangedList").bind("click",function(e){e.preventDefault();$("#changedList").toggle();});
}
,
error: function(res,textStatus,jqXHR)
{
if (textStatus == "timeout" && action == "download")
{
updateInfoStep("'.$this->l('Your server can\'t download the file. Please upload it first by ftp in your admin/autoupgrade directory').'");
}
else
{
updateInfoStep("[Server Error] Status message : " + textStatus);
}
}
})
});';
return $js;
}
private function _cleanUp($path)
{
// as we need theses files for restore operation, we can't remove them.
// They will be overwritten
$skipDirs = array('backups', 'pclzip', 'autoupgrade', '.', '..', '.svn');
$skipFiles = array('autoload.php', 'init.php', 'settings.inc.php', 'config.inc.php', 'Tools.php', 'AdminUpgrade.php');
$skipFiles[] = $this->standalone?'ajax-upgradetab.php':'ajax-tab.php';
if (is_dir($path))
{
$fp = opendir($path);
while ($file = readdir($fp))
{
if (!in_array($file, $skipDirs) AND !$this->_skipFile('', $path.$file, 'backup'))
{
$fullpath = $path.$file;
if (is_dir($fullpath))
$this->_cleanUp($fullpath.'/');
else
{
if (!in_array($file, $skipFiles))
{
unlink($fullpath);
}
}
}
}
closedir($fp);
/* fortunately not empty dir won't be removed by the following */
@rmdir($path);
}
else
if (!$this->_skipFile($file, '', 'backup')) unlink($path);
return true;
}
/**
* @desc extract a zip file to the given directory
* @return bool success
* we need a copy of it to be able to restore without keeping Tools and Autoload stuff
*/
private static function ZipExtract($fromFile, $toDir)
{
if (!file_exists($toDir))
if (!@mkdir($toDir,0777))
{
$this->next = 'error';
$this->nextDesc = sprintf($this->l('unable to create directory %s'),$toDir);
return false;
}
if (class_exists('ZipArchive', false))
{
$zip = new ZipArchive();
if ($zip->open($fromFile) === true AND $zip->extractTo($toDir) AND $zip->close())
return true;
return false;
}
else
{
if (!class_exists('PclZip',false))
require_once($this->prodRootDir.'/tools/pclzip/pclzip.lib.php');
$zip = new PclZip($fromFile);
$list = $zip->extract(PCLZIP_OPT_PATH, $toDir);
foreach ($list as $extractedFile)
if ($extractedFile['status'] != 'ok')
return false;
return true;
}
}
private function _listArchivedFiles()
{
if (!empty($this->nextParams['backupFilesFilepath']))
{
if (class_exists('ZipArchive', false))
{
$files=array();
if ($zip = zip_open($this->currentParams['backupFilesFilepath']))
{
while ($entry=zip_read($zip))
$files[] = zip_entry_name($entry);
zip_close($zip);
}
}
else
{
require_once($this->prodRootDir.'/tools/pclzip/pclzip.lib.php');
if ($zip = new PclZip($this->currentParams['backupFilesFilepath']))
return $zip->listContent();
}
}
return false;
}
/**
* bool _skipFile : check whether a file is in backup or restore skip list
*
* @param type $file : current file or directory name eg:'.svn' , 'settings.inc.php'
* @param type $fullpath : current file or directory fullpath eg:'/home/web/www/prestashop/img'
* @param type $way : 'backup' , 'upgrade'
*/
private function _skipFile($file,$fullpath,$way='backup')
{
$fullpath = str_replace('\\','/', $fullpath); // wamp compliant
$rootpath = str_replace('\\','/', $this->prodRootDir);
switch ($way)
{
case 'backup':
if (in_array($file, $this->backupIgnoreFiles))
return true;
foreach($this->backupIgnoreAbsoluteFiles as $path)
if ($file == 'img')
if (strpos($fullpath, $rootpath.$path) !== false)
return true;
break;
case 'upgrade':
if (in_array($file, $this->excludeFilesFromUpgrade))
return true;
foreach ($this->excludeAbsoluteFilesFromUpgrade as $path)
if (strpos($fullpath, $rootpath.$path) !== false)
return true;
break;
// default : if it's not a backup or an upgrade, juste skip the file
default:
return false;
}
}
}