Skip to content

Commit

Permalink
Remove usage of deprecated code
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Mar 8, 2024
1 parent a6c01e5 commit 9a4bd8b
Show file tree
Hide file tree
Showing 16 changed files with 25 additions and 101 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
12 changes: 0 additions & 12 deletions src/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
4 changes: 2 additions & 2 deletions src/controllers/ImportsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
10 changes: 2 additions & 8 deletions src/controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'),
]);
}

Expand Down
3 changes: 0 additions & 3 deletions src/jobs/ImportJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 0 additions & 3 deletions src/jobs/SendoutJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions src/jobs/SyncJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions src/models/SettingsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 3 additions & 5 deletions src/services/ExportsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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));
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/SendoutsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
57 changes: 0 additions & 57 deletions src/templates/_settings/sendout/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
9 changes: 6 additions & 3 deletions src/templates/sendouts/_includes/preflight.twig
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,19 @@
{% endif %}
<span class="info">
{{ 'Max Batch Size'|t('campaign') }}: {{ settings.maxBatchSize }}<br/>
{{ 'Memory Limit'|t('campaign') }}: {{ system.memoryLimit == -1 ? 'Unlimited'|t('campaign') : system.memoryLimit }}<br/>
{{ 'Max Execution Time'|t('campaign') }}: {{ system.timeLimit == 0 ? 'Unlimited'|t('campaign') : system.timeLimit ~ 's' }}<br/>
{{ 'Batch Job Delay'|t('campaign') }}: {{ settings.batchJobDelay == 0 ? 'None'|t('campaign') : settings.batchJobDelay ~ 's' }}<br/>
{{ 'Memory Limit'|t('campaign') }}: {{ memoryLimit == -1 ? 'Unlimited'|t('campaign') : memoryLimit }}<br/>
{{ 'Max Execution Time'|t('campaign') }}: {{ timeLimit == 0 ? 'Unlimited'|t('campaign') : timeLimit ~ 's' }}<br/>
{% if isDynamicWebAliasUsed %}
<span class="warning">
{{ 'Alias Check Failed – one of your site or asset volume URLs is using a dynamic `@web` alias.'|t('campaign')|markdown(inlineOnly=true) }}
</span>
{% endif %}
</span>
</p>
<p><input type="submit" class="btn submit launch" value="{{ saveLabel }}"></p>
<p>
<input type="submit" class="btn submit launch" value="{{ saveLabel }}">
</p>
<div class="rocketeer"></div>
<p class="spinner big hidden"></p>
<p class="error hidden"></p>
Expand Down
2 changes: 1 addition & 1 deletion src/translations/de/campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
2 changes: 1 addition & 1 deletion src/translations/en/campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.' => '',
Expand Down
2 changes: 1 addition & 1 deletion src/translations/fr/campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down

0 comments on commit 9a4bd8b

Please sign in to comment.