configWriter = $configWriter; $this->configReader = $vertexConfigFactory->create(['scopeConfig' => $config]); // Support snapshot config parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); } /** * Convert the saved configuration values into a valid cron schedule. * * @return Value * @throws CouldNotSaveException */ public function afterSave() { $time = explode(',', $this->configReader->getCronRotationTime()); $frequency = $this->configReader->getCronRotationFrequency(); $cronExprString = $this->createCronExpression($time, $frequency); try { $this->configWriter->save(Config::CRON_STRING_PATH, $cronExprString); } catch (\Exception $e) { throw new CouldNotSaveException(__('Failed to write crontab expression.'), $e); } return parent::afterSave(); } /** * Generate a crontab expression from the given data. * * @param array $timeComponents * @param string $frequency * @return string */ private function createCronExpression(array $timeComponents = [], $frequency = null) { $timeComponents = array_pad($timeComponents, 3, 0); $expression = [ (int)$timeComponents[1], (int)$timeComponents[0], $frequency === Frequency::CRON_MONTHLY ? '1' : '*', '*', $frequency === Frequency::CRON_WEEKLY ? '1' : '*', ]; return \implode(' ', $expression); } }