Skip to content

Commit

Permalink
- bug fix if md5 is missing
Browse files Browse the repository at this point in the history
- upgrader.xml replaced by upgrader-1.5.xml
  • Loading branch information
Asenar committed May 23, 2012
1 parent 1021fb0 commit 105b41b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 58 deletions.
95 changes: 38 additions & 57 deletions modules/autoupgrade/AdminSelfUpgrade.php
@@ -1,6 +1,6 @@
<?php
/*
* 2007-2012 PrestaShop
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
Expand All @@ -19,8 +19,8 @@
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2012 PrestaShop SA
* @version Release: $Revision: 14113 $
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 13424 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
Expand Down Expand Up @@ -622,7 +622,7 @@ public function init()
$this->excludeFilesFromUpgrade[] = '..';
$this->excludeFilesFromUpgrade[] = '.svn';
// do not copy install, neither settings.inc.php in case it would be present
$this->excludeAbsoluteFilesFromUpgrade[] = "/install";
$this->excludeFilesFromUpgrade[] = 'install';
$this->excludeFilesFromUpgrade[] = 'settings.inc.php';
// this will exclude autoupgrade dir from admin, and autoupgrade from modules
$this->excludeFilesFromUpgrade[] = 'autoupgrade';
Expand All @@ -636,10 +636,7 @@ public function init()


if ($this->keepDefaultTheme)
{
$this->excludeAbsoluteFilesFromUpgrade[] = "/themes/prestashop";
$this->excludeAbsoluteFilesFromUpgrade[] = "/themes/default";
}

}

Expand All @@ -663,18 +660,11 @@ public function postProcess()

if (Tools::isSubmit('deletebackup'))
{
$res = true;
$name = Tools::getValue('name');
$filelist = scandir($this->autoupgradePath);
foreach($filelist as $filename)
if (preg_match('#^auto-backup(db|files)_'.preg_quote($name).'\..*$#', $filename, $matches))
{
if (is_file($this->autoupgradePath.DIRECTORY_SEPARATOR.$filename))
$res &= unlink($this->autoupgradePath.DIRECTORY_SEPARATOR.$filename);

if (!empty($name) && is_dir($this->autoupgradePath.DIRECTORY_SEPARATOR.$name))
Tools::deleteDirectory($this->autoupgradePath.DIRECTORY_SEPARATOR.$name);
}
foreach($matches[0] as $filename)
if (preg_match('#^auto-backup(db|files)_'.preg_quote($name).'\.*$#', $filename, $matches))
$res &= unlink($this->autoupgradePath.DIRECTORY_SEPARATOR.$filename);
if ($res)
Tools::redirectAdmin($currentIndex.'&conf=1&token='.Tools::getValue('token'));
else
Expand Down Expand Up @@ -795,7 +785,7 @@ public function ajaxProcessUpgradeNow()
else
{
$this->next = 'download';
$this->nextDesc = $this->l('Shop deactivated. Now downloading (this can take some time )...');
$this->nextDesc = $this->l('Shop deactivated. Now downloading (this can takes some times )...');
}
}

Expand Down Expand Up @@ -943,14 +933,17 @@ public function _listFilesToRemove()
// if we can't find the diff file list corresponding to _PS_VERSION_ and prev_version,
// let's assume to remove every files ...
if (!$toRemove)
{
$toRemove = $this->_listFilesInDir($this->prodRootDir, 'restore');
}
$adminDir = str_replace($this->prodRootDir, '', $this->adminDir);
// if a file in "ToRemove" has been skipped during backup,
// just keep it
foreach ($toRemove as $key => $file)
{
$filename = substr($file, strrpos($file, '/')+1);
$toRemove[$key] = preg_replace('#^/admin#', $adminDir, $file);
// additional checks : preserve everything that contains autoupgrade
if ($this->_skipFile($filename, $file, 'backup') || strpos($file, 'autoupgrade'))
if ($this->_skipFile($filename, $file, 'backup'))
unset($toRemove[$key]);
}
return $toRemove;
Expand Down Expand Up @@ -1054,7 +1047,7 @@ public function ajaxProcessUpgradeFiles()
}
}
$this->nextDesc = sprintf($this->l('%1$s files left to upgrade.'), sizeof($filesToUpgrade));
$this->nextQuickInfo[] = sprintf($this->l('%2$s files left to upgrade.'), (isset($file)?$file:''), sizeof($filesToUpgrade));
$this->nextQuickInfo[] = sprintf($this->l('%2$s files left to upgrade.'), $file, sizeof($filesToUpgrade));
file_put_contents($this->autoupgradePath.DIRECTORY_SEPARATOR.$this->nextParams['filesToUpgrade'],serialize($filesToUpgrade));
return true;
}
Expand Down Expand Up @@ -1563,15 +1556,15 @@ public function upgradeThisFile($file)
// @TODO : later, we could handle customization with some kind of diff functions
// for now, just copy $file in str_replace($this->latestRootDir,_PS_ROOT_DIR_)
// $file comes from scandir function, no need to lost time and memory with file_exists()
$orig = $this->latestRootDir.$file;
$dest = $this->destUpgradePath . $file;
if ($this->_skipFile($file, $dest, 'upgrade'))
if ($this->_skipFile('', $file, 'upgrade'))
{
$this->nextQuickInfo[] = sprintf($this->l('%s ignored'), $file);
return true;
}
else
{
$orig = $this->latestRootDir.$file;
$dest = $this->destUpgradePath . $file;

if (is_dir($orig))
{
Expand Down Expand Up @@ -1876,10 +1869,7 @@ public function ajaxProcessRestoreDb()
{
$table = array_shift($v);
if (!in_array($table, $ignore_stats_table))
{
$drops['drop table '.$k] = 'DROP TABLE IF EXISTS `'.bqSql($table).'`';
$drops['drop view '.$k] = 'DROP VIEW IF EXISTS `'.bqSql($table).'`';
}
$drops['drop'.$k] = 'DROP TABLE IF EXISTS `'.bqSql($table).'`';
}
unset($all_tables);
$listQuery = array_merge($drops, $listQuery);
Expand All @@ -1888,13 +1878,10 @@ public function ajaxProcessRestoreDb()

// handle current backup file
if (!isset($listQuery))
if (file_exists($this->autoupgradePath.DIRECTORY_SEPARATOR.$this->toRestoreQueryList))
$listQuery = unserialize(file_get_contents($this->autoupgradePath.DIRECTORY_SEPARATOR.$this->toRestoreQueryList));
else
$listQuery = array();
$listQuery = unserialize(file_get_contents($this->autoupgradePath.DIRECTORY_SEPARATOR.$this->toRestoreQueryList));

$time_elapsed = time() - $start_time;
if (is_array($listQuery) && (sizeof($listQuery) > 0))
if (sizeof($listQuery) > 0)
{
do
{
Expand All @@ -1916,22 +1903,18 @@ public function ajaxProcessRestoreDb()
$this->stepDone = true;
$this->status = 'ok';
$this->next = 'rollbackComplete';
$this->nextDesc = $this->l('Database restoration done.');
$this->nextQuickInfo[] = $this->l('database has been restored.');
$this->nextDesc = $this->l('Database restoration done. now restoring files ...');
$this->nextQuickInfo[] = $this->l('database backup has been restored. now restoring files ...');
return true;
}
}
// filesForBackup already contains all the correct files
if (count($listQuery) == 0)
continue;

$query = array_shift($listQuery);
if (!empty($query))
{
if (!$db->execute($query))
{
if (is_array($listQuery))
$listQuery = array_unshift($listQuery, $query);
$listQuery = array_unshift($listQuery, $query);
$this->nextQuickInfo[] = '[SQL ERROR] '.$query.' - '.$db->getMsgError();
$this->next = 'error';
$this->nextDesc = $this->l('error during database restoration');
Expand All @@ -1951,15 +1934,6 @@ public function ajaxProcessRestoreDb()
$this->next = 'restoreDb';
$this->nextDesc = sprintf($this->l('%s queries left for %s...'), $queries_left, $this->nextParams['dbStep']);
}
else
{
$this->stepDone = true;
$this->status = 'ok';
$this->next = 'rollbackComplete';
$this->nextDesc = $this->l('Database restoration done.');
$this->nextQuickInfo[] = $this->l('database has been restored.');
return true;
}

return true;
}
Expand Down Expand Up @@ -2102,11 +2076,7 @@ public function ajaxProcessBackupDb()
{
$views .= '/* Scheme for view' . $schema[0]['View'] . " */\n";
if ($psBackupDropTable)
{
// If some *upgrade* transform a table in a view, drop both just in case
$views .= 'DROP VIEW IF EXISTS `'.$schema[0]['View'].'`;'."\n";
$views .= 'DROP TABLE IF EXISTS `'.$schema[0]['View'].'`;'."\n";
}
$views .= preg_replace('#DEFINER[^ ]* #', ' ', $schema[0]['Create View']).";\n\n";
$written += fwrite($fp, "\n".$views);
}
Expand All @@ -2117,8 +2087,6 @@ public function ajaxProcessBackupDb()
$written += fwrite($fp, '/* Scheme for table ' . $schema[0]['Table'] . " */\n");
if ($psBackupDropTable && !in_array($schema[0]['Table'], $ignore_stats_table))
{
// If some *upgrade* transform a table in a view, drop both just in case
$written += fwrite($fp, 'DROP VIEW IF EXISTS `'.$schema[0]['Table'].'`;'."\n");
$written += fwrite($fp, 'DROP TABLE IF EXISTS `'.$schema[0]['Table'].'`;'."\n");
// CREATE TABLE
$written += fwrite($fp, $schema[0]['Create Table'] . ";\n\n");
Expand Down Expand Up @@ -2242,7 +2210,7 @@ public function ajaxProcessBackupFiles()
if (empty($this->nextParams['filesForBackup']))
{
// @todo : only add files and dir listed in "originalPrestashopVersion" list
$filesToBackup = $this->_listFilesInDir($this->prodRootDir);
$filesToBackup = $this->_listFilesInDir($this->prodRootDir, 'backup');
file_put_contents($this->autoupgradePath.DIRECTORY_SEPARATOR.$this->toBackupFileList, serialize($filesToBackup));

$this->nextQuickInfo[] = sprintf($this->l('%s Files to backup.'), sizeof($this->toBackupFileList));
Expand Down Expand Up @@ -2558,6 +2526,18 @@ public function buildAjaxResult()
return Tools14::jsonEncode($return);
}

/**
* displayConf
*
* @return void
*/
public function displayConf()
{

if (version_compare(_PS_VERSION_,'1.4.5.0','<') AND false)
$this->_errors[] = $this->l('This class depends of several files modified in 1.4.5.0 version and should not be used in an older version');
parent::displayConf();
}

public function ajaxPreProcess()
{
Expand Down Expand Up @@ -2700,6 +2680,7 @@ protected function _displayRollbackForm()
else if (!empty($this->backupFilesFilename) || !empty($this->backupDbFilename))
{
$content .= '<div id="rollbackContainer">
@TODO rollback
<a disabled="disabled" class="upgradestep button" href="" id="rollback">'.$this->l('rollback').'</a>
</div><br/>';
}
Expand Down Expand Up @@ -3729,7 +3710,7 @@ private function _listArchivedFiles($zipfile)
* 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/config/settings.inc.php'
* @param type $fullpath : current file or directory fullpath eg:'/home/web/www/prestashop/img'
* @param type $way : 'backup' , 'upgrade'
*/
protected function _skipFile($file, $fullpath, $way='backup')
Expand Down
2 changes: 1 addition & 1 deletion modules/autoupgrade/Upgrader.php
Expand Up @@ -28,7 +28,7 @@
class UpgraderCore
{
const DEFAULT_CHECK_VERSION_DELAY_HOURS = 24;
public $rss_version_link = 'http://api.prestashop.com/xml/upgrader.xml';
public $rss_version_link = 'http://api.prestashop.com/xml/upgrader-1.5.xml';
public $rss_md5file_link_dir = 'http://api.prestashop.com/xml/md5/';
/**
* @var boolean contains true if last version is not installed
Expand Down

0 comments on commit 105b41b

Please sign in to comment.