KeyCheckWorker.php
1 year ago
PremiumKeyCheck.php
3 years ago
SendingServiceKeyCheck.php
1 year ago
index.php
3 years ago
PremiumKeyCheck.php
43 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Cron\Workers\KeyCheck; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Cron\CronWorkerScheduler; |
| 9 | use MailPoet\InvalidStateException; |
| 10 | use MailPoet\Services\Bridge; |
| 11 | use MailPoet\Settings\SettingsController; |
| 12 | |
| 13 | class PremiumKeyCheck extends KeyCheckWorker { |
| 14 | const TASK_TYPE = 'premium_key_check'; |
| 15 | |
| 16 | /** @var SettingsController */ |
| 17 | private $settings; |
| 18 | |
| 19 | public function __construct( |
| 20 | SettingsController $settings, |
| 21 | CronWorkerScheduler $cronWorkerScheduler |
| 22 | ) { |
| 23 | $this->settings = $settings; |
| 24 | parent::__construct($cronWorkerScheduler); |
| 25 | } |
| 26 | |
| 27 | public function checkProcessingRequirements() { |
| 28 | return Bridge::isPremiumKeySpecified(); |
| 29 | } |
| 30 | |
| 31 | public function checkKey() { |
| 32 | // for phpstan because we set bridge property in the init function |
| 33 | if (!$this->bridge) { |
| 34 | throw new InvalidStateException('The class was not initialized properly. Please call the Init method before.'); |
| 35 | }; |
| 36 | |
| 37 | $premiumKey = $this->settings->get(Bridge::PREMIUM_KEY_SETTING_NAME); |
| 38 | $result = $this->bridge->checkPremiumKey($premiumKey); |
| 39 | $this->bridge->storePremiumKeyAndState($premiumKey, $result); |
| 40 | return $result; |
| 41 | } |
| 42 | } |
| 43 |