16 class Cron extends \Magento\Framework\App\Config\Value
18 const CRON_STRING_PATH =
'crontab/default/jobs/currency_rates_update/schedule/cron_expr';
42 \
Magento\Framework\
Data\Collection\AbstractDb $resourceCollection =
null,
45 $this->_configValueFactory = $configValueFactory;
55 $time = $this->
getData(
'groups/import/fields/time/value');
56 $frequency = $this->
getData(
'groups/import/fields/frequency/value');
58 $frequencyWeekly = \Magento\Cron\Model\Config\Source\Frequency::CRON_WEEKLY;
59 $frequencyMonthly = \Magento\Cron\Model\Config\Source\Frequency::CRON_MONTHLY;
62 intval($time[1]), # Minute
63 intval($time[0]), # Hour
64 $frequency == $frequencyMonthly ?
'1' :
'*', # Day of the Month
65 '*', # Month of the Year
66 $frequency == $frequencyWeekly ?
'1' :
'*', # Day of the Week
69 $cronExprString = join(
' ', $cronExprArray);
73 $configValue = $this->_configValueFactory->create();
74 $configValue->load(self::CRON_STRING_PATH,
'path');
75 $configValue->setValue($cronExprString)->setPath(self::CRON_STRING_PATH)->save();
76 }
catch (\Exception $e) {
77 throw new \Exception(
__(
'We can\'t save the Cron expression.'));
79 return parent::afterSave();
__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, array $data=[])
getData($key='', $index=null)