Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Cron.php
Go to the documentation of this file.
1 <?php
7 
8 class Cron extends \Magento\Framework\App\Config\Value
9 {
10  const CRON_STRING_PATH = 'crontab/default/jobs/paypal_fetch_settlement_reports/schedule/cron_expr';
11 
12  const CRON_MODEL_PATH_INTERVAL = 'paypal/fetch_reports/schedule';
13 
18 
29  public function __construct(
30  \Magento\Framework\Model\Context $context,
31  \Magento\Framework\Registry $registry,
33  \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
34  \Magento\Framework\App\Config\ValueFactory $configValueFactory,
35  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
36  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
37  array $data = []
38  ) {
39  $this->_configValueFactory = $configValueFactory;
40  parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
41  }
42 
48  public function afterSave()
49  {
50  $cronExprString = '';
51  $time = explode(
52  ',',
53  $this->_configValueFactory->create()->load('paypal/fetch_reports/time', 'path')->getValue()
54  );
55 
56  if ($this->_configValueFactory->create()->load('paypal/fetch_reports/active', 'path')->getValue()) {
57  $interval = $this->_configValueFactory->create()->load(self::CRON_MODEL_PATH_INTERVAL, 'path')->getValue();
58  $cronExprString = "{$time[1]} {$time[0]} */{$interval} * *";
59  }
60 
61  $this->_configValueFactory->create()->load(
62  self::CRON_STRING_PATH,
63  'path'
64  )->setValue(
65  $cronExprString
66  )->setPath(
67  self::CRON_STRING_PATH
68  )->save();
69 
70  return parent::afterSave();
71  }
72 }
__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=[])
Definition: Cron.php:29
$config
Definition: fraud_order.php:17
$resource
Definition: bulk.php:12