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