1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Backup
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27:
28: /**
29: * Backup Observer
30: *
31: * @category Mage
32: * @package Mage_Backup
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Backup_Model_Observer
36: {
37: const XML_PATH_BACKUP_ENABLED = 'system/backup/enabled';
38: const XML_PATH_BACKUP_TYPE = 'system/backup/type';
39: const XML_PATH_BACKUP_MAINTENANCE_MODE = 'system/backup/maintenance';
40:
41: /**
42: * Error messages
43: *
44: * @var array
45: */
46: protected $_errors = array();
47:
48: /**
49: * Create Backup
50: *
51: * @return Mage_Log_Model_Cron
52: */
53: public function scheduledBackup()
54: {
55: if (!Mage::getStoreConfigFlag(self::XML_PATH_BACKUP_ENABLED)) {
56: return $this;
57: }
58:
59: if (Mage::getStoreConfigFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE)) {
60: Mage::helper('backup')->turnOnMaintenanceMode();
61: }
62:
63: $type = Mage::getStoreConfig(self::XML_PATH_BACKUP_TYPE);
64:
65: $this->_errors = array();
66: try {
67: $backupManager = Mage_Backup::getBackupInstance($type)
68: ->setBackupExtension(Mage::helper('backup')->getExtensionByType($type))
69: ->setTime(time())
70: ->setBackupsDir(Mage::helper('backup')->getBackupsDir());
71:
72: Mage::register('backup_manager', $backupManager);
73:
74: if ($type != Mage_Backup_Helper_Data::TYPE_DB) {
75: $backupManager->setRootDir(Mage::getBaseDir())
76: ->addIgnorePaths(Mage::helper('backup')->getBackupIgnorePaths());
77: }
78:
79: $backupManager->create();
80: Mage::log(Mage::helper('backup')->getCreateSuccessMessageByType($type));
81: }
82: catch (Exception $e) {
83: $this->_errors[] = $e->getMessage();
84: $this->_errors[] = $e->getTrace();
85: Mage::log($e->getMessage(), Zend_Log::ERR);
86: Mage::logException($e);
87: }
88:
89: if (Mage::getStoreConfigFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE)) {
90: Mage::helper('backup')->turnOffMaintenanceMode();
91: }
92:
93: return $this;
94: }
95: }
96: