16 class Cron extends \Magento\Framework\App\Config\Value
50 \
Magento\Framework\
Data\Collection\AbstractDb $resourceCollection =
null,
54 $this->_configValueFactory = $configValueFactory;
55 $this->_runModelPath = $runModelPath;
67 $enabled = $this->
getData(
'groups/log/fields/enabled/value');
68 $time = $this->
getData(
'groups/log/fields/time/value');
69 $frequency = $this->
getData(
'groups/log/fields/frequency/value');
71 $frequencyWeekly = \Magento\Cron\Model\Config\Source\Frequency::CRON_WEEKLY;
72 $frequencyMonthly = \Magento\Cron\Model\Config\Source\Frequency::CRON_MONTHLY;
76 intval($time[1]), # Minute
77 intval($time[0]), # Hour
78 $frequency == $frequencyMonthly ?
'1' :
'*', # Day of the Month
79 '*', # Month of the Year
80 $frequency == $frequencyWeekly ?
'1' :
'*', # Day of the Week
82 $cronExprString = join(
' ', $cronExprArray);
89 $configValue = $this->_configValueFactory->create();
90 $configValue->load(self::CRON_STRING_PATH,
'path');
91 $configValue->setValue($cronExprString)->setPath(self::CRON_STRING_PATH)->save();
94 $configValue = $this->_configValueFactory->create();
95 $configValue->load(self::CRON_MODEL_PATH,
'path');
96 $configValue->setValue($this->_runModelPath)->setPath(self::CRON_MODEL_PATH)->save();
97 }
catch (\Exception $e) {
98 throw new \Magento\Framework\Exception\LocalizedException(
__(
'We can\'t save the Cron expression.'));
100 return parent::afterSave();
getData($key='', $index=null)
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\Framework\App\Config\ValueFactory $configValueFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, $runModelPath='', array $data=[])