-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FFWEB:913 Add cron execution frequency configuration
- Loading branch information
a-laurowski
authored and
a.laurowski
committed
Jan 9, 2019
1 parent
01d75dc
commit 15e493a
Showing
9 changed files
with
126 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
Omikron/Factfinder/Model/Adminhtml/System/Config/Backend/Feed/Frequency.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
namespace Omikron\Factfinder\Model\Adminhtml\System\Config\Backend\Feed; | ||
|
||
/** | ||
* Class Frequency | ||
*/ | ||
class Frequency extends \Magento\Framework\App\Config\Value | ||
{ | ||
const PATH_CRON_TIME = 'ff_cron_time'; | ||
const PATH_CRON_IS_ENABLED = 'factfinder/configurable_cron/ff_cron_enabled'; | ||
const PATH_CRON_FREQUENCY = 'factfinder/configurable_cron/ff_cron_frequency'; | ||
const CRON_STRING_PATH = 'crontab/default/jobs/factfinder_feed_export/schedule/cron_expr'; | ||
|
||
/** | ||
* @var \Magento\Framework\App\Config\Storage\WriterInterface | ||
*/ | ||
protected $configWriter; | ||
|
||
/** | ||
* Frequency constructor. | ||
* | ||
* @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\Storage\WriterInterface $configWriter | ||
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource | ||
* @param \Magento\Framework\Data\Collection\AbstractDb|null $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\Storage\WriterInterface $configWriter, | ||
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, | ||
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); | ||
$this->configWriter = $configWriter; | ||
} | ||
|
||
/** | ||
* @return \Magento\Framework\App\Config\Value|void | ||
*/ | ||
public function afterSave() | ||
{ | ||
$time = $this->getFieldsetDataValue(self::PATH_CRON_TIME); | ||
$frequency = $this->getValue(); | ||
|
||
$frequencyWeekly = \Magento\Cron\Model\Config\Source\Frequency::CRON_WEEKLY; | ||
$frequencyMonthly = \Magento\Cron\Model\Config\Source\Frequency::CRON_MONTHLY; | ||
|
||
$cronExprArray = array( | ||
intval($time[1]), | ||
intval($time[0]), | ||
($frequency == $frequencyMonthly) ? '1' : '*', | ||
'*', | ||
($frequency == $frequencyWeekly) ? '1' : '*', | ||
); | ||
$cronExprString = join(' ', $cronExprArray); | ||
|
||
try { | ||
$this->configWriter->save(self::CRON_STRING_PATH, $cronExprString); | ||
} catch (Exception $e) { | ||
throw new Exception('Unable to save the cron expression.'); | ||
} | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+28.9 KB
...ron/Factfinder/view/frontend/web/images/documentation/cron-configuration_en.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters