_runModelPath = $runModelPath; $this->_configValueFactory = $configValueFactory; parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); } /** * @inheritdoc * * @return $this * @throws \Exception */ public function afterSave() { $cronMinute = $this->getData('groups/synclog/fields/cron_minute/value'); $cronHour = $this->getData('groups/synclog/fields/cron_hour/value'); $cronDay = $this->getData('groups/synclog/fields/cron_day/value'); $cronMonth = $this->getData('groups/synclog/fields/cron_month/value'); $cronWeekday = $this->getData('groups/synclog/fields/cron_weekday/value'); $cronMinute = ($cronMinute == null) ? '*' : $cronMinute; $cronHour = ($cronHour == null) ? '*' : $cronHour; $cronDay = ($cronDay == null) ? '*' : $cronDay; $cronMonth = ($cronMonth == null) ? '*' : $cronMonth; $cronWeekday = ($cronWeekday == null) ? '*' : $cronWeekday; $cronExprArray = [ $cronMinute, //Minute $cronHour, //Hour $cronDay, //Day of the Month $cronMonth, //Month of the Year $cronWeekday, //Day of the Week ]; $cronExprString = join(' ', $cronExprArray); try { $this->_configValueFactory->create()->load( self::CRON_STRING_PATH, 'path' )->setValue( $cronExprString )->setPath( self::CRON_STRING_PATH )->save(); $this->_configValueFactory->create()->load( self::CRON_MODEL_PATH, 'path' )->setValue( $this->_runModelPath )->setPath( self::CRON_MODEL_PATH )->save(); } catch (\Exception $e) { throw new \Magento\Framework\Exception\LocalizedException(__('We can\'t save the Cron expression.')); } return parent::afterSave(); } }