00001 <?php 00002 /** 00003 * Magento 00004 * 00005 * NOTICE OF LICENSE 00006 * 00007 * This source file is subject to the Open Software License (OSL 3.0) 00008 * that is bundled with this package in the file LICENSE.txt. 00009 * It is also available through the world-wide-web at this URL: 00010 * http://opensource.org/licenses/osl-3.0.php 00011 * If you did not receive a copy of the license and are unable to 00012 * obtain it through the world-wide-web, please send an email 00013 * to license@magentocommerce.com so we can send you a copy immediately. 00014 * 00015 * DISCLAIMER 00016 * 00017 * Do not edit or add to this file if you wish to upgrade Magento to newer 00018 * versions in the future. If you wish to customize Magento for your 00019 * needs please refer to http://www.magentocommerce.com for more information. 00020 * 00021 * @category Mage 00022 * @package Mage_Adminhtml 00023 * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) 00024 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 00025 */ 00026 00027 /** 00028 * Backup admin controller 00029 * 00030 * @category Mage 00031 * @package Mage_Adminhtml 00032 * @author Magento Core Team <core@magentocommerce.com> 00033 */ 00034 class Mage_Adminhtml_System_BackupController extends Mage_Adminhtml_Controller_Action 00035 { 00036 /** 00037 * Backup list action 00038 */ 00039 public function indexAction() 00040 { 00041 if($this->getRequest()->getParam('ajax')) { 00042 $this->_forward('grid'); 00043 return; 00044 } 00045 00046 $this->loadLayout(); 00047 $this->_setActiveMenu('system'); 00048 $this->_addBreadcrumb(Mage::helper('adminhtml')->__('System'), Mage::helper('adminhtml')->__('System')); 00049 $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Tools'), Mage::helper('adminhtml')->__('Tools')); 00050 $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Backups'), Mage::helper('adminhtml')->__('Backup')); 00051 00052 $this->_addContent($this->getLayout()->createBlock('adminhtml/backup', 'backup')); 00053 00054 $this->renderLayout(); 00055 } 00056 00057 /** 00058 * Backup list action 00059 */ 00060 public function gridAction() 00061 { 00062 $this->getResponse()->setBody($this->getLayout()->createBlock('adminhtml/backup_grid')->toHtml()); 00063 } 00064 00065 /** 00066 * Create backup action 00067 */ 00068 public function createAction() 00069 { 00070 try { 00071 $backupDb = Mage::getModel('backup/db'); 00072 $backup = Mage::getModel('backup/backup') 00073 ->setTime(time()) 00074 ->setType('db') 00075 ->setPath(Mage::getBaseDir("var") . DS . "backups"); 00076 00077 $backupDb->createBackup($backup); 00078 $this->_getSession()->addSuccess(Mage::helper('adminhtml')->__('Backup successfully created')); 00079 } 00080 catch (Exception $e) { 00081 $this->_getSession()->addException($e, Mage::helper('adminhtml')->__('Error while create backup. Please try again later')); 00082 } 00083 $this->_redirect('*/*'); 00084 } 00085 00086 /** 00087 * Download backup action 00088 */ 00089 public function downloadAction() 00090 { 00091 $backup = Mage::getModel('backup/backup') 00092 ->setTime((int)$this->getRequest()->getParam('time')) 00093 ->setType($this->getRequest()->getParam('type')) 00094 ->setPath(Mage::getBaseDir("var") . DS . "backups"); 00095 /* @var $backup Mage_Backup_Model_Backup */ 00096 00097 if (!$backup->exists()) { 00098 $this->_redirect('*/*'); 00099 } 00100 00101 $fileName = 'backup-' . date('YmdHis', $backup->getTime()) . '.sql.gz'; 00102 00103 $this->_prepareDownloadResponse($fileName, null, 'application/octet-stream', $backup->getSize()); 00104 00105 $this->getResponse()->sendHeaders(); 00106 00107 $backup->output(); 00108 exit(); 00109 } 00110 00111 /** 00112 * Delete backup action 00113 */ 00114 public function deleteAction() 00115 { 00116 try { 00117 $backup = Mage::getModel('backup/backup') 00118 ->setTime((int)$this->getRequest()->getParam('time')) 00119 ->setType($this->getRequest()->getParam('type')) 00120 ->setPath(Mage::getBaseDir("var") . DS . "backups") 00121 ->deleteFile(); 00122 00123 $this->_getSession()->addSuccess(Mage::helper('adminhtml')->__('Backup record was deleted')); 00124 } 00125 catch (Exception $e) { 00126 // Nothing 00127 } 00128 00129 $this->_redirect('*/*/'); 00130 00131 } 00132 00133 protected function _isAllowed() 00134 { 00135 return Mage::getSingleton('admin/session')->isAllowed('system/tools/backup'); 00136 } 00137 00138 /** 00139 * Retrive adminhtml session model 00140 * 00141 * @return Mage_Adminhtml_Model_Session 00142 */ 00143 protected function _getSession() 00144 { 00145 return Mage::getSingleton('adminhtml/session'); 00146 } 00147 }