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 by cron backend model
30: *
31: * @category Mage
32: * @package Mage_Backup
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Backup_Model_Config_Backend_Cron extends Mage_Core_Model_Config_Data
36: {
37: const CRON_STRING_PATH = 'crontab/jobs/system_backup/schedule/cron_expr';
38: const CRON_MODEL_PATH = 'crontab/jobs/system_backup/run/model';
39:
40: const XML_PATH_BACKUP_ENABLED = 'groups/backup/fields/enabled/value';
41: const XML_PATH_BACKUP_TIME = 'groups/backup/fields/time/value';
42: const XML_PATH_BACKUP_FREQUENCY = 'groups/backup/fields/frequency/value';
43:
44: /**
45: * Cron settings after save
46: *
47: * @return Mage_Adminhtml_Model_System_Config_Backend_Log_Cron
48: */
49: protected function _afterSave()
50: {
51: $enabled = $this->getData(self::XML_PATH_BACKUP_ENABLED);
52: $time = $this->getData(self::XML_PATH_BACKUP_TIME);
53: $frequency = $this->getData(self::XML_PATH_BACKUP_FREQUENCY);
54:
55: $frequencyWeekly = Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency::CRON_WEEKLY;
56: $frequencyMonthly = Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency::CRON_MONTHLY;
57:
58: if ($enabled) {
59: $cronExprArray = array(
60: intval($time[1]), # Minute
61: intval($time[0]), # Hour
62: ($frequency == $frequencyMonthly) ? '1' : '*', # Day of the Month
63: '*', # Month of the Year
64: ($frequency == $frequencyWeekly) ? '1' : '*', # Day of the Week
65: );
66: $cronExprString = join(' ', $cronExprArray);
67: }
68: else {
69: $cronExprString = '';
70: }
71:
72: try {
73: Mage::getModel('core/config_data')
74: ->load(self::CRON_STRING_PATH, 'path')
75: ->setValue($cronExprString)
76: ->setPath(self::CRON_STRING_PATH)
77: ->save();
78:
79: Mage::getModel('core/config_data')
80: ->load(self::CRON_MODEL_PATH, 'path')
81: ->setValue((string) Mage::getConfig()->getNode(self::CRON_MODEL_PATH))
82: ->setPath(self::CRON_MODEL_PATH)
83: ->save();
84: }
85: catch (Exception $e) {
86: Mage::throwException(Mage::helper('backup')->__('Unable to save the cron expression.'));
87: }
88: }
89: }
90: