From 9a4bd8be8c0d7adb20a54a48808af6576cc14d3e Mon Sep 17 00:00:00 2001 From: bencroker Date: Fri, 8 Mar 2024 08:39:49 -0600 Subject: [PATCH] Remove usage of deprecated code --- CHANGELOG.md | 1 + src/Campaign.php | 2 + src/config.php | 12 ---- src/controllers/ImportsController.php | 4 +- src/controllers/SettingsController.php | 10 +--- src/jobs/ImportJob.php | 3 - src/jobs/SendoutJob.php | 3 - src/jobs/SyncJob.php | 3 - src/models/SettingsModel.php | 4 ++ src/services/ExportsService.php | 8 +-- src/services/SendoutsService.php | 4 +- src/templates/_settings/sendout/index.twig | 57 ------------------- .../sendouts/_includes/preflight.twig | 9 ++- src/translations/de/campaign.php | 2 +- src/translations/en/campaign.php | 2 +- src/translations/fr/campaign.php | 2 +- 16 files changed, 25 insertions(+), 101 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75a75a3f..722c292d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - Deprecated the `memoryThreshold` config setting. - Deprecated the `timeLimit` config setting. - Deprecated the `timeThreshold` config setting. +- Deprecated the `Campaign::maxPowerLieutenant()` method. Use `App:maxPowerCaptain()` instead. ## 2.12.2 - 2024-03-05 diff --git a/src/Campaign.php b/src/Campaign.php index 2c4c5e5f..89837a37 100644 --- a/src/Campaign.php +++ b/src/Campaign.php @@ -330,6 +330,8 @@ public function createMailer(SettingsModel $settings = null): Mailer /** * Sets max memory and time limits. + * + * @deprecated in 2.13.0. Use `App:maxPowerCaptain()` instead. */ public function maxPowerLieutenant(): void { diff --git a/src/config.php b/src/config.php index 86cf27a3..5977c882 100644 --- a/src/config.php +++ b/src/config.php @@ -77,18 +77,6 @@ // The maximum size of sendout batches //'maxBatchSize' => 10000, - // The memory usage limit per sendout batch in bytes or a shorthand byte value (set to -1 for unlimited) - //'memoryLimit' => '1024M', - - // The execution time limit per sendout batch in seconds (set to 0 for unlimited) - //'timeLimit' => 3600, - - // The threshold for memory usage per sendout batch as a fraction - //'memoryThreshold' => 0.8, - - // The threshold for execution time per sendout batch as a fraction - //'timeThreshold' => 0.8, - // The amount of time in seconds to delay jobs between sendout batches //'batchJobDelay' => 10, diff --git a/src/controllers/ImportsController.php b/src/controllers/ImportsController.php index 3e1455ce..bf39644b 100644 --- a/src/controllers/ImportsController.php +++ b/src/controllers/ImportsController.php @@ -7,6 +7,7 @@ use Craft; use craft\elements\Asset; +use craft\helpers\App; use craft\helpers\Assets; use craft\helpers\FileHelper; use craft\web\Controller; @@ -235,8 +236,7 @@ public function actionDownloadFile(): ?Response throw new BadRequestHttpException('Import not found.'); } - // Call for max power - Campaign::$plugin->maxPowerLieutenant(); + App::maxPowerCaptain(); $handle = Campaign::$plugin->imports->getHandle($import); diff --git a/src/controllers/SettingsController.php b/src/controllers/SettingsController.php index 56b58283..19cc9657 100755 --- a/src/controllers/SettingsController.php +++ b/src/controllers/SettingsController.php @@ -17,7 +17,6 @@ use putyourlightson\campaign\base\BaseSettingsController; use putyourlightson\campaign\Campaign; use putyourlightson\campaign\elements\ContactElement; -use putyourlightson\campaign\helpers\SendoutHelper; use putyourlightson\campaign\helpers\SettingsHelper; use putyourlightson\campaign\models\SettingsModel; use yii\web\Response; @@ -136,17 +135,12 @@ public function actionEditSendout(SettingsModel $settings = null): Response $settings = Campaign::$plugin->settings; } - $memoryLimit = $settings->memoryLimit ? SendoutHelper::memoryInBytes($settings->memoryLimit) : 0; - return $this->renderTemplate('campaign/_settings/sendout', [ 'settings' => $settings, 'config' => Craft::$app->getConfig()->getConfigFromFile('campaign'), 'contactElementType' => ContactElement::class, - 'system' => [ - 'memoryLimit' => ini_get('memory_limit'), - 'memoryLimitExceeded' => $memoryLimit > SendoutHelper::memoryInBytes(ini_get('memory_limit')), - 'timeLimit' => ini_get('max_execution_time'), - ], + 'memoryLimit' => ini_get('memory_limit'), + 'timeLimit' => ini_get('max_execution_time'), ]); } diff --git a/src/jobs/ImportJob.php b/src/jobs/ImportJob.php index 0a6135ce..5739c4b5 100644 --- a/src/jobs/ImportJob.php +++ b/src/jobs/ImportJob.php @@ -45,9 +45,6 @@ public function execute($queue): void return; } - // Call for max power - Campaign::$plugin->maxPowerLieutenant(); - parent::execute($queue); // TODO: move what’s below this into the `BaseBatchedJob::after` method in Campaign 3. diff --git a/src/jobs/SendoutJob.php b/src/jobs/SendoutJob.php index 559651ce..0ad82b01 100644 --- a/src/jobs/SendoutJob.php +++ b/src/jobs/SendoutJob.php @@ -64,9 +64,6 @@ public function execute($queue): void return; } - // Call for max power - Campaign::$plugin->maxPowerLieutenant(); - // TODO: move what’s below this into the `BaseBatchedJob::beforeBatch` method in Campaign 3. Campaign::$plugin->sendouts->prepareSending($sendout, $this->batchIndex + 1); diff --git a/src/jobs/SyncJob.php b/src/jobs/SyncJob.php index 49bcac22..565b3a02 100644 --- a/src/jobs/SyncJob.php +++ b/src/jobs/SyncJob.php @@ -50,9 +50,6 @@ public function execute($queue): void return; } - // Call for max power - Campaign::$plugin->maxPowerLieutenant(); - parent::execute($queue); // TODO: move what’s below this into the `BaseBatchedJob::after` method in Campaign 3. diff --git a/src/models/SettingsModel.php b/src/models/SettingsModel.php index 93861c53..83f7afc4 100644 --- a/src/models/SettingsModel.php +++ b/src/models/SettingsModel.php @@ -122,21 +122,25 @@ class SettingsModel extends Model /** * @var string|null The memory usage limit per sendout batch in bytes or a shorthand byte value (set to -1 for unlimited) + * @deprecated in 2.13.0. */ public ?string $memoryLimit = '1024M'; /** * @var int|null The execution time limit per sendout batch in seconds (set to 0 for unlimited) + * @deprecated in 2.13.0. */ public ?int $timeLimit = 3600; /** * @var float The threshold for memory usage per sendout batch as a fraction + * @deprecated in 2.13.0. */ public float $memoryThreshold = 0.8; /** * @var float The threshold for execution time per sendout batch as a fraction + * @deprecated in 2.13.0. */ public float $timeThreshold = 0.8; diff --git a/src/services/ExportsService.php b/src/services/ExportsService.php index 5709b955..637bed18 100644 --- a/src/services/ExportsService.php +++ b/src/services/ExportsService.php @@ -9,7 +9,7 @@ use craft\base\Element; use craft\elements\db\ElementQuery; use craft\fields\data\MultiOptionsFieldData; -use putyourlightson\campaign\Campaign; +use craft\helpers\App; use putyourlightson\campaign\elements\ContactElement; use putyourlightson\campaign\elements\MailingListElement; use putyourlightson\campaign\events\ExportEvent; @@ -43,8 +43,7 @@ public function exportFile(ExportModel $export): bool return false; } - // Call for max power - Campaign::$plugin->maxPowerLieutenant(); + App::maxPowerCaptain(); // Open file for writing $handle = fopen($export->filePath, 'wb'); @@ -88,8 +87,7 @@ public function exportFile(ExportModel $export): bool } $value = implode(',', $elements); - } - // https://github.com/putyourlightson/craft-campaign/issues/297 + } // https://github.com/putyourlightson/craft-campaign/issues/297 elseif ($value instanceof MultiOptionsFieldData) { $value = implode(',', iterator_to_array($value)); } diff --git a/src/services/SendoutsService.php b/src/services/SendoutsService.php index 3d957a0a..ee27ed45 100755 --- a/src/services/SendoutsService.php +++ b/src/services/SendoutsService.php @@ -7,6 +7,7 @@ use Craft; use craft\base\Component; +use craft\helpers\App; use craft\helpers\DateTimeHelper; use craft\helpers\Db; use craft\helpers\Queue; @@ -591,8 +592,7 @@ private function _getSentRecipientsQuery(SendoutElement $sendout, bool $todayOnl */ private function _getPendingRecipientsStandard(SendoutElement $sendout): array { - // Call for max power - Campaign::$plugin->maxPowerLieutenant(); + App::maxPowerCaptain(); $baseCondition = [ 'mailingListId' => $sendout->mailingListIds, diff --git a/src/templates/_settings/sendout/index.twig b/src/templates/_settings/sendout/index.twig index 6912e764..6a70ea50 100644 --- a/src/templates/_settings/sendout/index.twig +++ b/src/templates/_settings/sendout/index.twig @@ -56,61 +56,4 @@ required: true, }) }} - {% set memoryLimitInfo %} - {{ 'The `memory_limit` directive in `php.ini` is currently set to `{value}`.'|t('campaign', {value: system.memoryLimit}) }} - {% endset %} - {% if (settings.memoryLimit == -1 and system.memoryLimit > -1) or system.memoryLimitExceeded %} - {% set memoryLimitWarning %} - {{ memoryLimitInfo }} {{ config.memoryLimit is defined ? macros.configWarning('memoryLimit') }} - {% endset %} - {% else %} - {% set memoryLimitTip %} - {{ memoryLimitInfo }} - {% endset %} - {% set memoryLimitWarning -%} - {{ config.memoryLimit is defined ? macros.configWarning('memoryLimit') }} - {%- endset %} - {% endif %} - {{ forms.textField({ - label: "Memory Limit"|t('campaign'), - instructions: "The memory usage limit per sendout batch in bytes or a shorthand byte value (set to -1 for unlimited)."|t('campaign'), - tip: memoryLimitTip ?? '', - warning: memoryLimitWarning ?? '', - id: 'memoryLimit', - name: 'memoryLimit', - placeholder: '1024M', - value: settings.memoryLimit, - errors: settings.getErrors('memoryLimit'), - required: true, - }) }} - - {% set timeLimitInfo %} - {{ 'The `max_execution_time` directive in `php.ini` is currently set to `{value}`.'|t('campaign', {value: system.timeLimit}) }} - {% endset %} - {% if (settings.timeLimit == 0 and system.timeLimit > 0) or settings.timeLimit > system.timeLimit %} - {% set timeLimitWarning %} - {{ timeLimitInfo }} {{ config.timeLimit is defined ? macros.configWarning('timeLimit') }} - {% endset %} - {% else %} - {% set timeLimitTip %} - {{ timeLimitInfo }} - {% endset %} - {% set timeLimitWarning -%} - {{ config.timeLimit is defined ? macros.configWarning('timeLimit') }} - {%- endset %} - {% endif %} - {{ forms.textField({ - type: 'number', - label: "Time Limit"|t('campaign'), - instructions: "The execution time limit per sendout batch in seconds (set to 0 for unlimited)."|t('campaign'), - tip: timeLimitTip ?? '', - warning: timeLimitWarning ?? '', - id: 'timeLimit', - name: 'timeLimit', - placeholder: '3600', - value: settings.timeLimit, - errors: settings.getErrors('timeLimit'), - required: true, - }) }} - {% endblock %} diff --git a/src/templates/sendouts/_includes/preflight.twig b/src/templates/sendouts/_includes/preflight.twig index fd66ade3..4e05f187 100644 --- a/src/templates/sendouts/_includes/preflight.twig +++ b/src/templates/sendouts/_includes/preflight.twig @@ -52,8 +52,9 @@ {% endif %} {{ 'Max Batch Size'|t('campaign') }}: {{ settings.maxBatchSize }}
- {{ 'Memory Limit'|t('campaign') }}: {{ system.memoryLimit == -1 ? 'Unlimited'|t('campaign') : system.memoryLimit }}
- {{ 'Max Execution Time'|t('campaign') }}: {{ system.timeLimit == 0 ? 'Unlimited'|t('campaign') : system.timeLimit ~ 's' }}
+ {{ 'Batch Job Delay'|t('campaign') }}: {{ settings.batchJobDelay == 0 ? 'None'|t('campaign') : settings.batchJobDelay ~ 's' }}
+ {{ 'Memory Limit'|t('campaign') }}: {{ memoryLimit == -1 ? 'Unlimited'|t('campaign') : memoryLimit }}
+ {{ 'Max Execution Time'|t('campaign') }}: {{ timeLimit == 0 ? 'Unlimited'|t('campaign') : timeLimit ~ 's' }}
{% if isDynamicWebAliasUsed %} {{ 'Alias Check Failed – one of your site or asset volume URLs is using a dynamic `@web` alias.'|t('campaign')|markdown(inlineOnly=true) }} @@ -61,7 +62,9 @@ {% endif %}

-

+

+ +

diff --git a/src/translations/de/campaign.php b/src/translations/de/campaign.php index bef44a47..1a0102b2 100644 --- a/src/translations/de/campaign.php +++ b/src/translations/de/campaign.php @@ -504,7 +504,7 @@ 'Send sendouts' => 'Verschicke Sendungen', 'Send Test Email' => 'Sende Test-E-Mail', 'Send Test' => 'Sende Test', - 'Sending “{title}” sendout [batch {batch}]' => 'Sende “{title}”-Sendung [Charge {batch}]', + 'Sending “{title}” sendout.' => 'Sende “{title}”-Sendung.', 'Sending completed: {title}' => 'Senden beendet: {title}', 'Sending failed: {title}' => 'Senden fehlgeschlagen: {title}', 'Sending failed. Please check your email settings and the error in the logs.' => 'Senden fehlgeschlagen. Bitte überprüfen Sie Ihre E-Mail-Einstellungen und den Fehler-Log.', diff --git a/src/translations/en/campaign.php b/src/translations/en/campaign.php index 98357a7a..c9bf784c 100644 --- a/src/translations/en/campaign.php +++ b/src/translations/en/campaign.php @@ -503,7 +503,7 @@ 'Send sendouts' => '', 'Send Test Email' => '', 'Send Test' => '', - 'Sending “{title}” sendout [batch {batch}]' => '', + 'Sending “{title}” sendout.' => '', 'Sending completed: {title}' => '', 'Sending failed: {title}' => '', 'Sending failed. Please check your email settings and the error in the logs.' => '', diff --git a/src/translations/fr/campaign.php b/src/translations/fr/campaign.php index 8bdb6894..19048270 100644 --- a/src/translations/fr/campaign.php +++ b/src/translations/fr/campaign.php @@ -504,7 +504,7 @@ 'Send sendouts' => 'Envoyer les campagnes', 'Send Test Email' => 'Envoyer un mail de test', 'Send Test' => 'Envoyer le test', - 'Sending “{title}” sendout [batch {batch}]' => 'Envoi de “{title}” par [batch {batch}]', + 'Sending “{title}” sendout.' => 'Envoi de “{title}”.', 'Sending completed: {title}' => 'Envoi complété : {title}', 'Sending failed: {title}' => 'Échec de l’envoi : {title}', 'Sending failed. Please check your email settings and the error in the logs.' => 'Échec de l’envoi. Veuillez vérifiez les réglages de vos emails et les erreurs dans les logs.',