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:
35: class Mage_Adminhtml_Model_System_Config_Backend_Product_Alert_Cron extends Mage_Core_Model_Config_Data
36: {
37: const CRON_STRING_PATH = 'crontab/jobs/catalog_product_alert/schedule/cron_expr';
38: const CRON_MODEL_PATH = 'crontab/jobs/catalog_product_alert/run/model';
39:
40: protected function _afterSave()
41: {
42: $priceEnable = $this->getData('groups/productalert/fields/allow_price/value');
43: $stockEnable = $this->getData('groups/productalert/fields/allow_stock/value');
44:
45: $enabled = $priceEnable || $stockEnable;
46: $frequncy = $this->getData('groups/productalert_cron/fields/frequency/value');
47: $time = $this->getData('groups/productalert_cron/fields/time/value');
48:
49: $errorEmail = $this->getData('groups/productalert_cron/fields/error_email/value');
50:
51: $frequencyDaily = Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency::CRON_DAILY;
52: $frequencyWeekly = Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency::CRON_WEEKLY;
53: $frequencyMonthly = Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency::CRON_MONTHLY;
54: $cronDayOfWeek = date('N');
55:
56: $cronExprArray = array(
57: intval($time[1]),
58: intval($time[0]),
59: ($frequncy == $frequencyMonthly) ? '1' : '*',
60: '*',
61: ($frequncy == $frequencyWeekly) ? '1' : '*',
62: );
63:
64: $cronExprString = join(' ', $cronExprArray);
65:
66: try {
67: Mage::getModel('core/config_data')
68: ->load(self::CRON_STRING_PATH, 'path')
69: ->setValue($cronExprString)
70: ->setPath(self::CRON_STRING_PATH)
71: ->save();
72: Mage::getModel('core/config_data')
73: ->load(self::CRON_MODEL_PATH, 'path')
74: ->setValue((string) Mage::getConfig()->getNode(self::CRON_MODEL_PATH))
75: ->setPath(self::CRON_MODEL_PATH)
76: ->save();
77: } catch (Exception $e) {
78: throw new Exception(Mage::helper('cron')->__('Unable to save the cron expression.'));
79: }
80: }
81: }
82: