123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Paypal\Model\System\Config\Backend;
- class Cron extends \Magento\Framework\App\Config\Value
- {
- const CRON_STRING_PATH = 'crontab/default/jobs/paypal_fetch_settlement_reports/schedule/cron_expr';
- const CRON_MODEL_PATH_INTERVAL = 'paypal/fetch_reports/schedule';
- /**
- * @var \Magento\Framework\App\Config\ValueFactory
- */
- protected $_configValueFactory;
- /**
- * @param \Magento\Framework\Model\Context $context
- * @param \Magento\Framework\Registry $registry
- * @param \Magento\Framework\App\Config\ScopeConfigInterface $config
- * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
- * @param \Magento\Framework\App\Config\ValueFactory $configValueFactory
- * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
- * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
- * @param array $data
- */
- public function __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 = []
- ) {
- $this->_configValueFactory = $configValueFactory;
- parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
- }
- /**
- * Cron settings after save
- *
- * @return $this
- */
- public function afterSave()
- {
- $cronExprString = '';
- $time = explode(
- ',',
- $this->_configValueFactory->create()->load('paypal/fetch_reports/time', 'path')->getValue()
- );
- if ($this->_configValueFactory->create()->load('paypal/fetch_reports/active', 'path')->getValue()) {
- $interval = $this->_configValueFactory->create()->load(self::CRON_MODEL_PATH_INTERVAL, 'path')->getValue();
- $cronExprString = "{$time[1]} {$time[0]} */{$interval} * *";
- }
- $this->_configValueFactory->create()->load(
- self::CRON_STRING_PATH,
- 'path'
- )->setValue(
- $cronExprString
- )->setPath(
- self::CRON_STRING_PATH
- )->save();
- return parent::afterSave();
- }
- }
|