* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 7721 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php');
class AdminBackup extends AdminTab
{
/** @var string The field we are sorting on */
protected $_sortBy = 'date';
public function __construct()
{
$this->table = 'backup';
$this->className = 'Backup';
parent::__construct();
$this->edit = false;
$this->delete = true;
$this->view = true;
$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->optionTitle = $this->l('Backup options');
$this->_fieldsOptions = 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'));
$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();
}
/**
* Creates a new backup, and then displays the normal menu
*/
public function displayForm($isMainTab = true)
{
if (is_writable(PS_ADMIN_DIR.'/backups/'))
{
if (!($object = $this->loadObject()))
return;
if ($object->add())
{
echo '
'.$this->l('It appears that the Backup was successful, however, you must download and carefully verify the Backup file.').'
';
if ($this->tabAccess['view'] === '1')
echo '
';
$this->displayHowTo(false);
}
elseif ($object->error)
$this->_errors[] = $object->error;
}
else
$this->_errors[] = $this->l('"Backups" Directory in admin directory must be writeable (CHMOD 755 / 777)');
$this->displayErrors();
}
/**
* Displays the page which allows the backup to be downloaded
*/
public function viewbackup()
{
global $currentIndex;
if (!($object = $this->loadObject()))
return;
if ($object->id)
{
$url = $object->getBackupURL();
echo '
'.$this->l('Beginning download ...').'
';
echo ' '.$this->l('Back-up file should automatically download.');
echo '