![]() 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/app/code/Amasty/MWishlist/Model/Config/Backend/ |
<?php declare(strict_types=1); /** * @author Amasty Team * @copyright Copyright (c) Amasty (https://www.amasty.com) * @package Multiple Wishlist for Magento 2 */ namespace Amasty\MWishlist\Model\Config\Backend; use Magento\Cron\Model\Config\Source\Frequency; class Alert extends \Magento\Framework\App\Config\Value { public const CRON_STRING_PATH = 'crontab/default/jobs/amasty_mwishlist_notify_customer/schedule/cron_expr'; public const CRON_MODEL_PATH = 'crontab/default/jobs/amasty_mwishlist_notify_customer/run/model'; /** * @var \Magento\Framework\App\Config\ValueFactory */ private $configValueFactory; /** * @var string */ private $runModelPath = ''; /** * @var \Psr\Log\LoggerInterface */ private $logger; 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, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, $runModelPath = '', array $data = [] ) { $this->runModelPath = $runModelPath; $this->configValueFactory = $configValueFactory; $this->logger = $logger; parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); } /** * @inheritdoc */ public function afterSave() { try { $this->configValueFactory->create()->load( self::CRON_STRING_PATH, 'path' )->setValue( $this->getCronExprString() )->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) { $this->logger->error(__('We can\'t save the cron expression.')); $this->logger->error($e->getMessage()); } return parent::afterSave(); } private function getCronExprString(): string { $time = $this->getData('groups/customer_notifications/fields/time/value'); $frequency = $this->getData('groups/customer_notifications/fields/frequency/value'); $cronExprArray = [ (int)$time[1], (int)$time[0], $frequency == Frequency::CRON_MONTHLY ? '1' : '*', '*', $frequency == Frequency::CRON_WEEKLY ? '1' : '*', ]; return join(' ', $cronExprArray); } }