1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_Adminhtml_Model_System_Config_Backend_Sitemap_Cron extends Mage_Core_Model_Config_Data
35: {
36:
37: const CRON_STRING_PATH = 'crontab/jobs/sitemap_generate/schedule/cron_expr';
38: const CRON_MODEL_PATH = 'crontab/jobs/sitemap_generate/run/model';
39:
40: protected function _afterSave()
41: {
42: $enabled = $this->getData('groups/generate/enabled/value');
43:
44: $time = $this->getData('groups/generate/fields/time/value');
45: $frequncy = $this->getData('groups/generate/frequency/value');
46: $errorEmail = $this->getData('groups/generate/error_email/value');
47:
48: $frequencyDaily = Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency::CRON_DAILY;
49: $frequencyWeekly = Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency::CRON_WEEKLY;
50: $frequencyMonthly = Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency::CRON_MONTHLY;
51:
52: $cronDayOfWeek = date('N');
53:
54: $cronExprArray = array(
55: intval($time[1]),
56: intval($time[0]),
57: ($frequncy == $frequencyMonthly) ? '1' : '*',
58: '*',
59: ($frequncy == $frequencyWeekly) ? '1' : '*',
60: );
61:
62: $cronExprString = join(' ', $cronExprArray);
63:
64: try {
65: Mage::getModel('core/config_data')
66: ->load(self::CRON_STRING_PATH, 'path')
67: ->setValue($cronExprString)
68: ->setPath(self::CRON_STRING_PATH)
69: ->save();
70: Mage::getModel('core/config_data')
71: ->load(self::CRON_MODEL_PATH, 'path')
72: ->setValue((string) Mage::getConfig()->getNode(self::CRON_MODEL_PATH))
73: ->setPath(self::CRON_MODEL_PATH)
74: ->save();
75: } catch (Exception $e) {
76: throw new Exception(Mage::helper('cron')->__('Unable to save the cron expression.'));
77: }
78: }
79:
80: }
81: