PageRenderTime 61ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/magento/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Log/Cron.php

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