// fix bug in AdminBackupController
This commit is contained in:
+19
-21
@@ -1,5 +1,5 @@
|
||||
{*
|
||||
* 2007-2011 PrestaShop
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
@@ -19,20 +19,23 @@
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @version Release: $Revision: 8971 $
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*}
|
||||
|
||||
{if isset($download)}
|
||||
<fieldset style="margin: 40px 0;" class="width3">
|
||||
<legend><img src="../img/admin/AdminBackup.gif" alt="" class="icon" /> {l s='Download'}</legend>
|
||||
<p style="font-size: 13px;"><a href="{$backup_url}"><img src="../img/admin/AdminBackup.gif" alt="" class="icon" /></a><b><a href="{$backup_url}">{l s='Download the Backup file'} ({$backup_weight}{l s='Mb'})</a></b><br /><br />
|
||||
{l s='Tip: You can also download this file by FTP, Backup files are located in "admin/backups" directory.'}</p>
|
||||
</fieldset>
|
||||
{/if}
|
||||
{extends file="helper/view/view.tpl"}
|
||||
|
||||
{block name="override_tpl"}
|
||||
|
||||
<fieldset class="width3">
|
||||
<legend><img src="../img/admin/AdminBackup.gif" alt="" class="icon" /> {l s='Download'}</legend>
|
||||
<p style="font-size: 13px;">
|
||||
<a href="{$backup_url}"><img src="../img/admin/AdminBackup.gif" alt="" class="icon" /></a>
|
||||
<b><a href="{$backup_url}">{l s='Download the Backup file'} ({$backup_weight}{l s='Mb'})</a></b><br /><br />
|
||||
{l s='Tip: You can also download this file by FTP, Backup files are located in "admin/backups" directory.'}</p>
|
||||
</fieldset><br /><br />
|
||||
|
||||
{if isset($how_to)}
|
||||
<div class="error width1" style="float: left; margin-right: 10px;">
|
||||
<p>{l s='Disclaimer before creating a new Backup'}</p>
|
||||
<ol style="font-size: 11px; font-weight: normal; line-height: 20px; padding-left: 10px;">
|
||||
@@ -46,12 +49,8 @@
|
||||
<li>{l s='Always check your data.'}</li>
|
||||
<li>{l s='Never restore a Backup on a live site.'}</li>
|
||||
</ol>
|
||||
{if $show_form}
|
||||
<form action="{$current}&add{$table}&token={$token}" method="post" style="text-align: center;">
|
||||
<input type="submit" class="button" value="{l s='I read the disclaimer - Create a new Backup'}" style="padding: 10px; font-weight: bold; border: 1px solid;" />
|
||||
</form>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="warn width2" style="float: left;">
|
||||
<p>{l s='How-to restore a database Backup in 10 easy steps'}</p>
|
||||
<ol style="font-size: 11px; font-weight: normal; line-height: 20px;">
|
||||
@@ -67,10 +66,9 @@
|
||||
<li>{l s='Click on the "Go" button and wait during the import, the process can take several minutes'}</li>
|
||||
</ol>
|
||||
</div>
|
||||
<div class="clear"></div>
|
||||
{/if}
|
||||
{if isset($download)}
|
||||
<br /><br /><a href="{$current}&token={$token}"><img src="../img/admin/arrow2.gif" /> {l s='Back to list'}</a><br />
|
||||
{/if}
|
||||
|
||||
{$content}
|
||||
<div class="clear"></div>
|
||||
|
||||
{/block}
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
{*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 9639 $
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*}
|
||||
|
||||
{extends file="helper/list/list_header.tpl"}
|
||||
|
||||
{block name="override_header"}
|
||||
|
||||
<div class="error width1" style="float: left; margin-right: 10px;">
|
||||
<p>{l s='Disclaimer before creating a new Backup'}</p>
|
||||
<ol style="font-size: 11px; font-weight: normal; line-height: 20px; padding-left: 10px;">
|
||||
<li>{l s='PrestaShop is not responsible for your database, Backups, restore and data.'}</li>
|
||||
<li>{l s='PrestaShop is an Open-source software, you are using it at your own risk under the licence agreement.'}</li>
|
||||
<li>{l s='You should Backup your data on a regular basis (both files and database).'}</li>
|
||||
<li>{l s='This function only backs up your database, not your files.'}</li>
|
||||
<li>{l s='By default, your existing database tables will be deleted during Backup restore (see options).'}</li>
|
||||
<li>{l s='Always verify the quality and integrity of your Backups files.'}</li>
|
||||
<li>{l s='Always verify that your Backups files are complete, up-to-date and valid. Even if you had a success message during the Backup process.'}</li>
|
||||
<li>{l s='Always check your data.'}</li>
|
||||
<li>{l s='Never restore a Backup on a live site.'}</li>
|
||||
</ol>
|
||||
<br />
|
||||
|
||||
<form action="{$currentIndex}&add{$table}&token={$token}" method="post" style="text-align:center;">
|
||||
<input type="submit" class="button" value="{l s='I read the disclaimer - Create a new Backup'}" style="padding:10px;font-weight:bold;border:1px solid;cursor:pointer;" />
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="warn width2" style="float: left;">
|
||||
<p>{l s='How-to restore a database Backup in 10 easy steps'}</p>
|
||||
<ol style="font-size: 11px; font-weight: normal; line-height: 20px;">
|
||||
<li>{l s='Turn off the "Enable Shop" option in the "Preferences" tab.'}</li>
|
||||
<li>{l s='Download the Backup from the list below or from your FTP server (in the folder "admin/backups").'}</li>
|
||||
<li>{l s='Check the Backup integrity: look for errors, incomplete file. Verify all your data.'}</li>
|
||||
<li>{l s='Ask your hosting provider for a "phpMyAdmin" access to your database'}</li>
|
||||
<li>{l s='Connect to "phpMyAdmin" and select your current database'}</li>
|
||||
<li>{l s='Unless you enabled the "Drop existing tables" option, you must delete all tables from your current database.'}</li>
|
||||
<li>{l s='At the top of the screen select the tab "Import"'}</li>
|
||||
<li>{l s='Click on the "Browse..." button and select the Backup file from your hard drive'}</li>
|
||||
<li>{l s='Check the max. allowed filesize (ie. Max: 16Mb)'}<br />{l s='If your Backup file exceeds this limit, contact your hosting provider'}</li>
|
||||
<li>{l s='Click on the "Go" button and wait during the import, the process can take several minutes'}</li>
|
||||
</ol>
|
||||
</div>
|
||||
|
||||
<div class="clear"></div>
|
||||
|
||||
{/block}
|
||||
@@ -24,10 +24,18 @@
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*}
|
||||
|
||||
<div class="conf confirm"><img src="../img/admin/ok.gif" /> {l s='Beginning download ...'}</div>
|
||||
<br />{l s='Back-up file should automatically download.'}
|
||||
<br /><br />{l s='If not,'} <b><a href="{$url_backup}">{l s='please click here!'}</a></b>
|
||||
<iframe width="0" height="0" scrolling="no" frameborder="0" src="{$url_backup}"></iframe>
|
||||
<br /><br /><br /><a href="{$current}&token={$token}"><img src="../img/admin/arrow2.gif" /> {l s='Back to list'}</a><br />
|
||||
{extends file="helper/view/view.tpl"}
|
||||
|
||||
{block name="override_tpl"}
|
||||
|
||||
<div class="conf">{l s='Beginning download ...'}</div>
|
||||
|
||||
<p>{l s='Back-up file should automatically download.'}</p>
|
||||
|
||||
<p>{l s='If not,'} <b><a href="{$url_backup}">{l s='please click here!'}</a></b></p>
|
||||
|
||||
<iframe width="0" height="0" scrolling="no" frameborder="0" src="{$url_backup}"></iframe>
|
||||
|
||||
{/block}
|
||||
|
||||
|
||||
|
||||
@@ -28,21 +28,14 @@
|
||||
class AdminBackupControllerCore extends AdminController
|
||||
{
|
||||
/** @var string The field we are sorting on */
|
||||
protected $_sortBy = 'date';
|
||||
protected $sort_by = 'date';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->table = 'backup';
|
||||
$this->className = 'Backup';
|
||||
parent::__construct();
|
||||
|
||||
$this->addRowAction('view');
|
||||
$this->addRowAction('delete');
|
||||
$this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')));
|
||||
|
||||
$this->deleted = false;
|
||||
$this->requiredDatabase = false;
|
||||
$this->identifier = 'filename';
|
||||
parent::__construct();
|
||||
|
||||
$this->fieldsDisplay = array (
|
||||
'date' => array('title' => $this->l('Date'), 'type' => 'datetime', 'width' => 120, 'align' => 'right'),
|
||||
@@ -55,16 +48,101 @@ class AdminBackupControllerCore extends AdminController
|
||||
'general' => array(
|
||||
'title' => $this->l('Backup options'),
|
||||
'fields' => array(
|
||||
'PS_BACKUP_ALL' => array('title' => $this->l('Ignore statistics tables:'),
|
||||
'desc' => $this->l('The following tables will NOT be backed up if you enable this option:').'<br />'._DB_PREFIX_.'connections, '._DB_PREFIX_.'connections_page, '._DB_PREFIX_.'connections_source, '._DB_PREFIX_.'guest, '._DB_PREFIX_.'statssearch', 'cast' => 'intval', 'type' => 'bool'),
|
||||
'PS_BACKUP_DROP_TABLE' => array('title' => $this->l('Drop existing tables during import:'),
|
||||
'desc' => $this->l('Select this option to instruct the backup file to drop your tables prior to restoring the backed up data').'<br />(ie. "DROP TABLE IF EXISTS")', 'cast' => 'intval', 'type' => 'bool'),
|
||||
'PS_BACKUP_ALL' => array(
|
||||
'title' => $this->l('Ignore statistics tables:'),
|
||||
'desc' => $this->l('The following tables will NOT be backed up if you enable this option:').'
|
||||
<br />'._DB_PREFIX_.'connections, '._DB_PREFIX_.'connections_page, '._DB_PREFIX_.'connections_source, '.
|
||||
_DB_PREFIX_.'guest, '._DB_PREFIX_.'statssearch',
|
||||
'cast' => 'intval',
|
||||
'type' => 'bool'
|
||||
),
|
||||
'PS_BACKUP_DROP_TABLE' => array(
|
||||
'title' => $this->l('Drop existing tables during import:'),
|
||||
'desc' => $this->l('Select this option to instruct the backup file to drop your tables prior to restoring the backed up data').
|
||||
'<br />(ie. "DROP TABLE IF EXISTS")',
|
||||
'cast' => 'intval',
|
||||
'type' => 'bool'
|
||||
)
|
||||
),
|
||||
'submit' => array()
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function initList()
|
||||
{
|
||||
$this->addRowAction('view');
|
||||
$this->addRowAction('delete');
|
||||
$this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')));
|
||||
|
||||
return parent::initList();
|
||||
}
|
||||
|
||||
public function initView()
|
||||
{
|
||||
if (!($object = $this->loadObject()))
|
||||
$this->_errors[] = Tools::displayError('The object could not be loaded.');
|
||||
|
||||
if ($object->id)
|
||||
$this->tpl_view_vars = array('url_backup' => $object->getBackupURL());
|
||||
else if ($object->error)
|
||||
$this->_errors[] = $object->error;
|
||||
|
||||
return parent::initView();
|
||||
}
|
||||
|
||||
public function initViewDownload()
|
||||
{
|
||||
$this->tpl_folder = $this->tpl_folder.'download/';
|
||||
|
||||
return parent::initView();
|
||||
}
|
||||
|
||||
public function initToolbar()
|
||||
{
|
||||
switch ($this->display)
|
||||
{
|
||||
case 'add':
|
||||
case 'edit':
|
||||
case 'view':
|
||||
$this->toolbar_btn['cancel'] = array(
|
||||
'href' => self::$currentIndex.'&token='.$this->token,
|
||||
'desc' => $this->l('Cancel')
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function initContent()
|
||||
{
|
||||
// toolbar (save, cancel, new, ..)
|
||||
$this->initToolbar();
|
||||
if ($this->display == 'edit' || $this->display == 'add')
|
||||
{
|
||||
if (!$this->loadObject(true))
|
||||
return;
|
||||
|
||||
$this->content .= $this->initViewDownload();
|
||||
}
|
||||
else if ($this->display == 'view')
|
||||
{
|
||||
// Some controllers use the view action without an object
|
||||
if ($this->className)
|
||||
$this->loadObject(true);
|
||||
$this->content .= $this->initView();
|
||||
}
|
||||
else if (!$this->ajax)
|
||||
{
|
||||
$this->content .= $this->initList();
|
||||
$this->content .= $this->initOptions();
|
||||
}
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
'content' => $this->content,
|
||||
'url_post' => self::$currentIndex.'&token='.$this->token,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Load class object using identifier in $_GET (if possible)
|
||||
* otherwise return an empty object
|
||||
@@ -80,44 +158,6 @@ class AdminBackupControllerCore extends AdminController
|
||||
return new $this->className();
|
||||
}
|
||||
|
||||
public function initContent()
|
||||
{
|
||||
if ($this->display == 'view')
|
||||
{
|
||||
if (!($object = $this->loadObject()))
|
||||
$this->_errors[] = Tools::displayError('The object could not be loaded.');
|
||||
if ($object->id)
|
||||
{
|
||||
$this->context->smarty->assign(array(
|
||||
'url_backup' => $object->getBackupURL()
|
||||
));
|
||||
}
|
||||
elseif ($object->error)
|
||||
$this->_errors[] = $object->error;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->display == 'add')
|
||||
{
|
||||
$download = true;
|
||||
$show_form = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->display = 'list';
|
||||
$show_form = true;
|
||||
}
|
||||
$this->context->smarty->assign(array(
|
||||
'current' => self::$currentIndex,
|
||||
'show_form' => $show_form,
|
||||
'download' => isset($download) ? $download : null,
|
||||
'how_to' => true,
|
||||
));
|
||||
}
|
||||
|
||||
parent::initContent();
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
/* PrestaShop demo mode */
|
||||
@@ -132,41 +172,39 @@ class AdminBackupControllerCore extends AdminController
|
||||
if (!is_writable(_PS_ADMIN_DIR_.'/backups/'))
|
||||
$this->warnings[] = $this->l('"Backups" Directory in admin directory must be writeable (CHMOD 755 / 777)');
|
||||
|
||||
if ($this->action == 'new' && is_writable(_PS_ADMIN_DIR_.'/backups/'))
|
||||
if ($this->display == 'add' && is_writable(_PS_ADMIN_DIR_.'/backups/'))
|
||||
{
|
||||
if (($object = $this->loadObject()))
|
||||
{
|
||||
if ($object->add())
|
||||
{
|
||||
$this->context->smarty->assign(array(
|
||||
if (!$object->add())
|
||||
$this->_errors[] = $object->error;
|
||||
else
|
||||
$this->tpl_view_vars = array(
|
||||
'conf' => $this->l('It appears that the Backup was successful, however, you must download and carefully verify the Backup file.'),
|
||||
'backup_url' => $object->getBackupURL(),
|
||||
'backup_weight' => number_format((filesize($object->id)*0.000001), 2, '.', '')
|
||||
));
|
||||
}
|
||||
elseif ($object->error)
|
||||
$this->_errors[] = $object->error;
|
||||
'backup_weight' => number_format((filesize($object->id) * 0.000001), 2, '.', '')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
parent::postProcess();
|
||||
}
|
||||
|
||||
public function getList($id_lang, $orderBy = NULL, $orderWay = NULL, $start = 0, $limit = NULL, $id_lang_shop = NULL)
|
||||
public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = null)
|
||||
{
|
||||
if (!Validate::isTableOrIdentifier($this->table))
|
||||
die('filter is corrupted');
|
||||
if (empty($orderBy))
|
||||
$orderBy = Tools::getValue($this->table.'Orderby', $this->_defaultOrderBy);
|
||||
if (empty($orderWay))
|
||||
$orderWay = Tools::getValue($this->table.'Orderway', 'ASC');
|
||||
if (empty($order_by))
|
||||
$order_by = Tools::getValue($this->table.'Orderby', $this->_defaultOrderBy);
|
||||
if (empty($order_way))
|
||||
$order_way = Tools::getValue($this->table.'Orderway', 'ASC');
|
||||
|
||||
// Try and obtain getList arguments from $_GET
|
||||
$orderBy = Tools::getValue($this->table.'Orderby');
|
||||
$orderWay = Tools::getValue($this->table.'Orderway');
|
||||
$order_by = Tools::getValue($this->table.'Orderby');
|
||||
$order_way = Tools::getValue($this->table.'Orderway');
|
||||
|
||||
// Validate the orderBy and orderWay fields
|
||||
switch ($orderBy)
|
||||
switch ($order_by)
|
||||
{
|
||||
case 'filename':
|
||||
case 'filesize':
|
||||
@@ -174,27 +212,27 @@ class AdminBackupControllerCore extends AdminController
|
||||
case 'age':
|
||||
break;
|
||||
default:
|
||||
$orderBy = 'date';
|
||||
$order_by = 'date';
|
||||
}
|
||||
switch ($orderWay)
|
||||
switch ($order_way)
|
||||
{
|
||||
case 'asc':
|
||||
case 'desc':
|
||||
break;
|
||||
default:
|
||||
$orderWay = 'desc';
|
||||
$order_way = 'desc';
|
||||
}
|
||||
if (empty($limit))
|
||||
$limit = ((!isset($this->context->cookie->{$this->table.'_pagination'})) ? $this->_pagination[0] : $limit = $this->context->cookie->{$this->table.'_pagination'});
|
||||
$limit = (int)(Tools::getValue('pagination', $limit));
|
||||
$limit = (int)Tools::getValue('pagination', $limit);
|
||||
$this->context->cookie->{$this->table.'_pagination'} = $limit;
|
||||
|
||||
/* Determine offset from current page */
|
||||
if (!empty($_POST['submitFilter'.$this->table]) AND is_numeric($_POST['submitFilter'.$this->table]))
|
||||
$start = (int)($_POST['submitFilter'.$this->table] - 1) * $limit;
|
||||
$this->_lang = (int)($id_lang);
|
||||
$this->_orderBy = $orderBy;
|
||||
$this->_orderWay = strtoupper($orderWay);
|
||||
if (!empty($_POST['submitFilter'.$this->table]) && is_numeric($_POST['submitFilter'.$this->table]))
|
||||
$start = (int)$_POST['submitFilter'.$this->table] - 1 * $limit;
|
||||
$this->_lang = (int)$id_lang;
|
||||
$this->_orderBy = $order_by;
|
||||
$this->_orderWay = strtoupper($order_way);
|
||||
$this->_list = array();
|
||||
|
||||
// Find all the backups
|
||||
@@ -208,7 +246,7 @@ class AdminBackupControllerCore extends AdminController
|
||||
{
|
||||
if (preg_match('/^([\d]+-[a-z\d]+)\.sql(\.gz|\.bz2)?$/', $file, $matches) == 0)
|
||||
continue;
|
||||
$timestamp = (int)($matches[1]);
|
||||
$timestamp = (int)$matches[1];
|
||||
$date = date('Y-m-d H:i:s', $timestamp);
|
||||
$age = time() - $timestamp;
|
||||
if ($age < 3600)
|
||||
@@ -240,30 +278,30 @@ class AdminBackupControllerCore extends AdminController
|
||||
switch ($this->_orderBy)
|
||||
{
|
||||
case 'filename':
|
||||
$this->_sortBy = 'filename';
|
||||
$sorter = 'str_sort';
|
||||
$this->sort_by = 'filename';
|
||||
$sorter = 'strSort';
|
||||
break;
|
||||
case 'filesize':
|
||||
$this->_sortBy = 'filesize_sort';
|
||||
$sorter = 'int_sort';
|
||||
$this->sort_by = 'filesize_sort';
|
||||
$sorter = 'intSort';
|
||||
break;
|
||||
case 'age':
|
||||
case 'date':
|
||||
$this->_sortBy = 'timestamp';
|
||||
$sorter = 'int_sort';
|
||||
$this->sort_by = 'timestamp';
|
||||
$sorter = 'intSort';
|
||||
break;
|
||||
}
|
||||
usort($this->_list, array($this, $sorter));
|
||||
$this->_list = array_slice($this->_list, $start, $limit);
|
||||
}
|
||||
|
||||
public function int_sort($a, $b)
|
||||
public function intSort($a, $b)
|
||||
{
|
||||
return $this->_orderWay == 'ASC' ? $a[$this->_sortBy] - $b[$this->_sortBy] : $b[$this->_sortBy] - $a[$this->_sortBy];
|
||||
return $this->_orderWay == 'ASC' ? $a[$this->sort_by] - $b[$this->sort_by] : $b[$this->sort_by] - $a[$this->sort_by];
|
||||
}
|
||||
|
||||
public function str_sort($a, $b)
|
||||
public function strSort($a, $b)
|
||||
{
|
||||
return $this->_orderWay == 'ASC' ? strcmp($a[ $this->_sortBy], $b[$this->_sortBy]) : strcmp($b[ $this->_sortBy], $a[$this->_sortBy]);
|
||||
return $this->_orderWay == 'ASC' ? strcmp($a[$this->sort_by], $b[$this->sort_by]) : strcmp($b[$this->sort_by], $a[$this->sort_by]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user