![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/cartforge.co/vendor/magento/module-analytics/Model/Config/Backend/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace Magento\Analytics\Model\Config\Backend; use Magento\Framework\App\Cache\TypeListInterface; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\Config\Storage\WriterInterface; use Magento\Framework\App\Config\Value; use Magento\Framework\Data\Collection\AbstractDb; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Model\Context; use Magento\Framework\Model\ResourceModel\AbstractResource; use Magento\Framework\Registry; /** * Config value backend model. */ class CollectionTime extends Value { /** * The path to config setting of schedule of collection data cron. */ const CRON_SCHEDULE_PATH = 'crontab/default/jobs/analytics_collect_data/schedule/cron_expr'; /** * @var WriterInterface */ private $configWriter; /** * @param Context $context * @param Registry $registry * @param ScopeConfigInterface $config * @param TypeListInterface $cacheTypeList * @param WriterInterface $configWriter * @param AbstractResource|null $resource * @param AbstractDb|null $resourceCollection * @param array $data */ public function __construct( Context $context, Registry $registry, ScopeConfigInterface $config, TypeListInterface $cacheTypeList, WriterInterface $configWriter, AbstractResource $resource = null, AbstractDb $resourceCollection = null, array $data = [] ) { $this->configWriter = $configWriter; parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); } /** * {@inheritdoc} * * {@inheritdoc}. Set schedule setting for cron. * * @return Value */ public function afterSave() { $result = preg_match('#(?<hour>\d{2}),(?<min>\d{2}),(?<sec>\d{2})#', $this->getValue(), $time); if (!$result) { throw new LocalizedException( __('The time value is using an unsupported format. Enter a supported format and try again.') ); } $cronExprArray = [ $time['min'], # Minute $time['hour'], # Hour '*', # Day of the Month '*', # Month of the Year '*', # Day of the Week ]; $cronExprString = join(' ', $cronExprArray); try { $this->configWriter->save(self::CRON_SCHEDULE_PATH, $cronExprString); } catch (\Exception $e) { $this->_logger->error($e->getMessage()); throw new LocalizedException(__('Cron settings can\'t be saved')); } return parent::afterSave(); } }