From 752d85b6e122bef64ca35a949bb77f6421623dc3 Mon Sep 17 00:00:00 2001 From: lLefevre Date: Tue, 22 Nov 2011 14:44:54 +0000 Subject: [PATCH] // fix bug in AdminBackupController --- .../backup/{content.tpl => download/view.tpl} | 40 ++-- .../themes/template/backup/list_header.tpl | 70 ++++++ admin-dev/themes/template/backup/view.tpl | 18 +- controllers/admin/AdminBackupController.php | 214 +++++++++++------- 4 files changed, 228 insertions(+), 114 deletions(-) rename admin-dev/themes/template/backup/{content.tpl => download/view.tpl} (80%) create mode 100644 admin-dev/themes/template/backup/list_header.tpl diff --git a/admin-dev/themes/template/backup/content.tpl b/admin-dev/themes/template/backup/download/view.tpl similarity index 80% rename from admin-dev/themes/template/backup/content.tpl rename to admin-dev/themes/template/backup/download/view.tpl index 0bd3e32ab..43c5d3cd9 100644 --- a/admin-dev/themes/template/backup/content.tpl +++ b/admin-dev/themes/template/backup/download/view.tpl @@ -1,5 +1,5 @@ {* -* 2007-2011 PrestaShop +* 2007-2011 PrestaShop * * NOTICE OF LICENSE * @@ -19,20 +19,23 @@ * * @author PrestaShop SA * @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)} -
- {l s='Download'} -

{l s='Download the Backup file'} ({$backup_weight}{l s='Mb'})

- {l s='Tip: You can also download this file by FTP, Backup files are located in "admin/backups" directory.'}

-
-{/if} +{extends file="helper/view/view.tpl"} + +{block name="override_tpl"} + +
+ {l s='Download'} +

+ + {l s='Download the Backup file'} ({$backup_weight}{l s='Mb'})

+ {l s='Tip: You can also download this file by FTP, Backup files are located in "admin/backups" directory.'}

+


-{if isset($how_to)}

{l s='Disclaimer before creating a new Backup'}

    @@ -46,12 +49,8 @@
  1. {l s='Always check your data.'}
  2. {l s='Never restore a Backup on a live site.'}
- {if $show_form} -
- -
- {/if}
+

{l s='How-to restore a database Backup in 10 easy steps'}

    @@ -67,10 +66,9 @@
  1. {l s='Click on the "Go" button and wait during the import, the process can take several minutes'}
-
-{/if} -{if isset($download)} -

{l s='Back to list'}
-{/if} -{$content} +
+ +{/block} + + diff --git a/admin-dev/themes/template/backup/list_header.tpl b/admin-dev/themes/template/backup/list_header.tpl new file mode 100644 index 000000000..47ac95877 --- /dev/null +++ b/admin-dev/themes/template/backup/list_header.tpl @@ -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 +* @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"} + +
+

{l s='Disclaimer before creating a new Backup'}

+
    +
  1. {l s='PrestaShop is not responsible for your database, Backups, restore and data.'}
  2. +
  3. {l s='PrestaShop is an Open-source software, you are using it at your own risk under the licence agreement.'}
  4. +
  5. {l s='You should Backup your data on a regular basis (both files and database).'}
  6. +
  7. {l s='This function only backs up your database, not your files.'}
  8. +
  9. {l s='By default, your existing database tables will be deleted during Backup restore (see options).'}
  10. +
  11. {l s='Always verify the quality and integrity of your Backups files.'}
  12. +
  13. {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.'}
  14. +
  15. {l s='Always check your data.'}
  16. +
  17. {l s='Never restore a Backup on a live site.'}
  18. +
+
+ +
+ +
+ +
+ +
+

{l s='How-to restore a database Backup in 10 easy steps'}

+
    +
  1. {l s='Turn off the "Enable Shop" option in the "Preferences" tab.'}
  2. +
  3. {l s='Download the Backup from the list below or from your FTP server (in the folder "admin/backups").'}
  4. +
  5. {l s='Check the Backup integrity: look for errors, incomplete file. Verify all your data.'}
  6. +
  7. {l s='Ask your hosting provider for a "phpMyAdmin" access to your database'}
  8. +
  9. {l s='Connect to "phpMyAdmin" and select your current database'}
  10. +
  11. {l s='Unless you enabled the "Drop existing tables" option, you must delete all tables from your current database.'}
  12. +
  13. {l s='At the top of the screen select the tab "Import"'}
  14. +
  15. {l s='Click on the "Browse..." button and select the Backup file from your hard drive'}
  16. +
  17. {l s='Check the max. allowed filesize (ie. Max: 16Mb)'}
    {l s='If your Backup file exceeds this limit, contact your hosting provider'}
  18. +
  19. {l s='Click on the "Go" button and wait during the import, the process can take several minutes'}
  20. +
+
+ +
+ +{/block} \ No newline at end of file diff --git a/admin-dev/themes/template/backup/view.tpl b/admin-dev/themes/template/backup/view.tpl index 596c20197..6a439d8f9 100644 --- a/admin-dev/themes/template/backup/view.tpl +++ b/admin-dev/themes/template/backup/view.tpl @@ -24,10 +24,18 @@ * International Registered Trademark & Property of PrestaShop SA *} -
 {l s='Beginning download ...'}
-
{l s='Back-up file should automatically download.'} -

{l s='If not,'} {l s='please click here!'} - -


{l s='Back to list'}
+{extends file="helper/view/view.tpl"} + +{block name="override_tpl"} + +
{l s='Beginning download ...'}
+ +

{l s='Back-up file should automatically download.'}

+ +

{l s='If not,'} {l s='please click here!'}

+ + + +{/block} diff --git a/controllers/admin/AdminBackupController.php b/controllers/admin/AdminBackupController.php index e0f128722..902f67161 100644 --- a/controllers/admin/AdminBackupController.php +++ b/controllers/admin/AdminBackupController.php @@ -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:').'
'._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').'
(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:').' +
'._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'). + '
(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]); } }