[*] BO : #PSFV-94 - added AdminBackupController and some changes to AdminController

This commit is contained in:
tDidierjean
2011-10-18 12:40:35 +00:00
parent a2f6996ced
commit b2b2a4fbc6
10 changed files with 532 additions and 355 deletions
+271
View File
@@ -0,0 +1,271 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 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/osl-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: 7320 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class AdminBackupControllerCore extends AdminController
{
/** @var string The field we are sorting on */
protected $_sortBy = 'date';
public function __construct()
{
$this->table = 'backup';
$this->className = 'Backup';
parent::__construct();
$this->addRowAction('delete');
$this->addRowAction('view');
$this->deleted = false;
$this->requiredDatabase = false;
$this->fieldsDisplay = array (
'date' => array('title' => $this->l('Date'), 'type' => 'datetime', 'width' => 120, 'align' => 'right'),
'age' => array('title' => $this->l('Age')),
'filename' => array('title' => $this->l('File name'), 'width' => 200),
'filesize' => array('title' => $this->l('File size'))
);
$this->options = array(
'options_general' => array(
'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'),
),
),
),
);
$this->identifier = 'filename';
}
/**
* Load class object using identifier in $_GET (if possible)
* otherwise return an empty object
* This method overrides the one in AdminTab because AdminTab assumes the id is a UnsignedInt
* "Backups" Directory in admin directory must be writeable (CHMOD 777)
* @param boolean $opt Return an empty object if load fail
* @return object
*/
protected function loadObject($opt = false)
{
if ($id = Tools::getValue($this->identifier))
return new $this->className($id);
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();
if ($this->display == 'list')
{
$helper = new HelperOptions();
$helper->id = $this->id;
$helper->currentIndex = self::$currentIndex;
$this->content .= $helper->generateOptions($this->options['options_general']);
}
}
public function postProcess()
{
// Test if the backup dir is writable
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 (($object = $this->loadObject()))
{
if ($object->add())
{
$this->context->smarty->assign(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;
}
}
parent::postProcess();
}
public function getList($id_lang, $orderBy = NULL, $orderWay = 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');
// Try and obtain getList arguments from $_GET
$orderBy = Tools::getValue($this->table.'Orderby');
$orderWay = Tools::getValue($this->table.'Orderway');
// Validate the orderBy and orderWay fields
switch ($orderBy)
{
case 'filename':
case 'filesize':
case 'date':
case 'age':
break;
default:
$orderBy = 'date';
}
switch ($orderWay)
{
case 'asc':
case 'desc':
break;
default:
$orderWay = '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));
$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);
$this->_list = array();
// Find all the backups
$dh = @opendir(_PS_ADMIN_DIR_.'/backups/');
if ($dh === false)
{
$this->_errors[] = Tools::displayError('Unable to open backup directory .').addslashes(_PS_ADMIN_DIR_.'/backups/').'"';
return;
}
while (($file = readdir($dh)) !== false)
{
if (preg_match('/^([\d]+-[a-z\d]+)\.sql(\.gz|\.bz2)?$/', $file, $matches) == 0)
continue;
$timestamp = (int)($matches[1]);
$date = date('Y-m-d H:i:s', $timestamp);
$age = time() - $timestamp;
if ($age < 3600)
$age = '< 1 '.$this->l('hour');
else if ($age < 86400)
{
$age = floor($age / 3600);
$age = $age.' '.(($age == 1) ? $this->l('hour') : $this->l('hours'));
}
else
{
$age = floor($age / 86400);
$age = $age.' '.(($age == 1) ? $this->l('day') : $this->l('days'));
}
$size = filesize(_PS_ADMIN_DIR_.'/backups/'.$file);
$this->_list[] = array(
'filename' => $file,
'age' => $age,
'date' => $date,
'filesize' => number_format($size / 1000, 2).' Kb',
'timestamp' => $timestamp,
'filesize_sort' => $size,
);
}
closedir($dh);
$this->_listTotal = count($this->_list);
// Sort the _list based on the order requirements
switch ($this->_orderBy)
{
case 'filename':
$this->_sortBy = 'filename';
$sorter = 'str_sort';
break;
case 'filesize':
$this->_sortBy = 'filesize_sort';
$sorter = 'int_sort';
break;
case 'age':
case 'date':
$this->_sortBy = 'timestamp';
$sorter = 'int_sort';
break;
}
usort($this->_list, array($this, $sorter));
$this->_list = array_slice($this->_list, $start, $limit);
}
public function int_sort($a, $b)
{
return $this->_orderWay == 'ASC' ? $a[$this->_sortBy] - $b[$this->_sortBy] : $b[$this->_sortBy] - $a[$this->_sortBy];
}
public function str_sort($a, $b)
{
return $this->_orderWay == 'ASC' ? strcmp($a[ $this->_sortBy], $b[$this->_sortBy]) : strcmp($b[ $this->_sortBy], $a[$this->_sortBy]);
}
}
+22 -23
View File
@@ -1,6 +1,6 @@
<?php
/*
* 2007-2011 PrestaShop
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
@@ -47,7 +47,7 @@ class AdminHomeControllerCore extends AdminController
$rewrite = 0;
}
}
$htaccessAfterUpdate = 2;
$htaccessOptimized = (Configuration::get('PS_HTACCESS_CACHE_CONTROL') ? 2 : 0);
if (!file_exists(dirname(__FILE__).'/../../.htaccess'))
@@ -61,7 +61,7 @@ class AdminHomeControllerCore extends AdminController
$dateUpdHtaccess = Db::getInstance()->getValue('SELECT date_upd FROM '._DB_PREFIX_.'configuration WHERE name = "PS_HTACCESS_CACHE_CONTROL"');
if (Configuration::get('PS_HTACCESS_CACHE_CONTROL') AND strtotime($dateUpdHtaccess) > $stat['mtime'])
$htaccessOptimized = 1;
$dateUpdate = Configuration::get('PS_LAST_SHOP_UPDATE');
if ($dateUpdate AND strtotime($dateUpdate) > $stat['mtime'])
$htaccessAfterUpdate = 0;
@@ -70,7 +70,7 @@ class AdminHomeControllerCore extends AdminController
$needRebuild=Configuration::get('PS_NEED_REBUILD_INDEX');
if($needRebuild !='0');
$indexRebuiltAfterUpdate = 2;
$smartyOptimized = 0;
if (Configuration::get('PS_SMARTY_FORCE_COMPILE') == _PS_SMARTY_NO_COMPILE_)
++$smartyOptimized;
@@ -85,15 +85,15 @@ class AdminHomeControllerCore extends AdminController
$cccOptimized = 2;
else
$cccOptimized = 1;
$shopEnabled = (Configuration::get('PS_SHOP_ENABLE') ? 2 : 1);
$lights = array(
0 => array('image'=>'error2.png','color'=>'#fbe8e8'),
0 => array('image'=>'error2.png','color'=>'#fbe8e8'),
1 => array('image'=>'warn2.png','color'=>'#fffac6'),
2 => array('image'=>'ok2.png','color'=>'#dffad3'));
if ($rewrite + $htaccessOptimized + $smartyOptimized + $cccOptimized + $shopEnabled + $htaccessAfterUpdate + $indexRebuiltAfterUpdate != 14)
{
$this->context->smarty->assign('hide_tips',Configuration::get('PS_HIDE_OPTIMIZATION_TIPS'));
@@ -124,13 +124,13 @@ class AdminHomeControllerCore extends AdminController
'color' => $lights[$cccOptimized]['color'],
'image' => $lights[$cccOptimized]['image'],
);
$opti_list[] = array(
'title' => $this->l('Shop enabled'),
'href' => $link->getAdminLink('AdminPreferences'),
'color' => $lights[$shopEnabled]['color'],
'image' => $lights[$shopEnabled]['image'],
);
);
$opti_list[] = array(
'title' => $this->l('index rebuilt after update'),
@@ -138,7 +138,7 @@ class AdminHomeControllerCore extends AdminController
'color' => $lights[$indexRebuiltAfterUpdate]['color'],
'image' => $lights[$indexRebuiltAfterUpdate]['image'],
);
$opti_list[] = array(
'title' => $this->l('.htaccess up-to-date'),
'href' => $link->getAdminLink('AdminGenerator'),
@@ -181,7 +181,7 @@ class AdminHomeControllerCore extends AdminController
'title' => $this->l('New product'),
'description' => $this->l('Fill up your catalog with new articles and attributes.'),
);
$quick_links['third'] = array(
'href' => $this->context->link->getAdminLink('AdminStats'),
'title' => $this->l('Statistics'),
@@ -313,7 +313,7 @@ class AdminHomeControllerCore extends AdminController
$content = '<div id="table_info_large">
<h5><a href="index.php?tab=AdminStats&token='.Tools::getAdminTokenLite('AdminStats').'">'.$this->l('View more').'</a> <strong>'.$this->l('Statistics').'</strong> / '.$this->l('Sales of the week').'</h5>
<div id="stat_google">';
$chart = new Chart();
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT total_paid / conversion_rate as total_converted, invoice_date
@@ -326,13 +326,13 @@ class AdminHomeControllerCore extends AdminController
$chart->setTimeMode(strtotime('-7 DAYS', time()), time(), 'd');
$currency = Tools::setCurrency($this->context->cookie);
$chart->getCurve(1)->setLabel($this->l('Sales +Tx').' ('.strtoupper($currency->iso_code).')');
$content .= $chart->fetch();
$content .= ' </div>
</div>';
return $content;
}
public function getLastOrders()
{
$content = '
@@ -347,7 +347,7 @@ class AdminHomeControllerCore extends AdminController
<tr>
</thead>
<tbody>';
$orders = Order::getOrdersWithInformations(10);
$i = 0;
foreach ($orders AS $order)
@@ -366,7 +366,7 @@ class AdminHomeControllerCore extends AdminController
';
$i++;
}
$content .= '
</tbody>
</table>
@@ -388,9 +388,9 @@ class AdminHomeControllerCore extends AdminController
$result['msg'] = $this->l('an error occured a');
}
$this->content = Tools::jsonEncode($result);
}
public function displayAjax()
{
echo $this->content;
@@ -496,7 +496,6 @@ class AdminHomeControllerCore extends AdminController
public function initContent()
{
$smarty = $this->context->smarty;
$smarty->assign('token',$this->token);
$this->warnDomainName();
@@ -513,7 +512,7 @@ class AdminHomeControllerCore extends AdminController
$upgrade->checkPSVersion();
}
$smarty->assign('upgrade', $upgrade);
$smarty->assign('show_screencast', $this->context->employee->show_screencast);
$smarty->assign('quick_links', $this->getQuickLinks());
$smarty->assign('monthly_statistics', $this->getMonthlyStatistics());
@@ -521,7 +520,7 @@ class AdminHomeControllerCore extends AdminController
$smarty->assign('stats_sales', $this->getStatsSales());
$smarty->assign('last_orders',$this->getLastOrders());
$smarty->assign('tips_optimization', $this->_displayOptimizationTips());
$HOOK_BACKOFFICEHOME = Module::hookExec('backOfficeHome');
$smarty->assign('HOOK_BACKOFFICEHOME', $HOOK_BACKOFFICEHOME);
+2 -3
View File
@@ -46,7 +46,7 @@ class AdminImagesController extends AdminController
'height' => array('title' => $this->l('Height'), 'align' => 'right', 'suffix' => ' px', 'width' => 50, 'size' => 5)
);
$this->form_list = array(
$this->options = array(
'options_image_pref' => array(
'images' => array(
'title' => $this->l('Images'),
@@ -534,11 +534,10 @@ class AdminImagesController extends AdminController
if ($this->display == 'list')
{
$helper = new HelperOptions();
$helper->id = $this->id;
$helper->currentIndex = self::$currentIndex;
$this->content .= $helper->generateOptions($this->form_list['options_image_pref']);
$this->content .= $helper->generateOptions($this->options['options_image_pref']);
$this->initRegenerate();
$this->initMoveImages();
@@ -120,18 +120,6 @@ class AdminRequestSqlControllerCore extends AdminController
}
}
public function init()
{
if (isset($_GET['view'.$this->table]) && isset($_GET['id_'.$this->table]))
{
if ($this->tabAccess['edit'] === '1' || ($this->table == 'employee' && $this->context->employee->id == Tools::getValue('id_employee')))
$this->display = 'view';
else
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
}
parent::init();
}
public function initContent()
{
$this->displayWarning($this->l('When saving the query, only the request type "SELECT" are allowed.'));
+2 -2
View File
@@ -213,7 +213,7 @@ class AdminStoresControllerCore extends AdminController
)
);
$this->form_list = array(
$this->options = array(
'option_store_pref' => array(
'general' => array(
'title' => $this->l('Parameters'),
@@ -371,7 +371,7 @@ class AdminStoresControllerCore extends AdminController
$helper->id = $this->id;
$helper->currentIndex = self::$currentIndex;
$this->content .= $helper->generateOptions($this->form_list['option_store_pref']);
$this->content .= $helper->generateOptions($this->options['option_store_pref']);
}
}