- How-To: recommend Holesail Browser; NGINX/Apache/NPM/cURL examples - Add magesail-howto.css and layout head include - About: module overview, capabilities, docs pointer; LIVEPORT copyright - Add getCopyrightNotice(), magesail-about.css; update admin-ui.md
47 lines
1.5 KiB
PHP
47 lines
1.5 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace MageSail\Magesail\Model\Config\Backend;
|
|
|
|
use Magento\Cron\Model\ScheduleFactory;
|
|
use Magento\Framework\App\Config\Value;
|
|
use Magento\Framework\Exception\CronException;
|
|
use Magento\Framework\Exception\LocalizedException;
|
|
|
|
/**
|
|
* Validates and saves MageSail monitor job cron expression to core_config_data.
|
|
*/
|
|
class MonitorCronExpr extends Value
|
|
{
|
|
public function __construct(
|
|
\Magento\Framework\Model\Context $context,
|
|
\Magento\Framework\Registry $registry,
|
|
\Magento\Framework\App\Config\ScopeConfigInterface $config,
|
|
\Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
|
|
private readonly ScheduleFactory $scheduleFactory,
|
|
?\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);
|
|
}
|
|
|
|
/**
|
|
* @return $this
|
|
* @throws LocalizedException
|
|
*/
|
|
public function beforeSave()
|
|
{
|
|
$expr = trim((string) $this->getValue());
|
|
if ($expr === '') {
|
|
throw new LocalizedException(__('Monitor cron schedule cannot be empty.'));
|
|
}
|
|
try {
|
|
$this->scheduleFactory->create()->setCronExpr($expr);
|
|
} catch (CronException $e) {
|
|
throw new LocalizedException(__('%1', $e->getMessage()), $e);
|
|
}
|
|
return parent::beforeSave();
|
|
}
|
|
}
|