Skip to content

Commit

Permalink
Clean up legacy code
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Mar 10, 2024
1 parent 2fe0224 commit 4db0e08
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 109 deletions.
2 changes: 0 additions & 2 deletions src/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,6 @@ protected function getCpRoutes(): array
'campaign/campaigns/<campaignTypeHandle:{handle}>/<elementId:\d+><slug:(?:-[^\/]*)?>' => 'elements/edit',
'campaign/contacts/new' => 'campaign/contacts/create',
'campaign/contacts/<elementId:\d+>' => 'elements/edit',
// TODO: remove in 5.0.0, when element index URLs include the source, added in Craft 4.3.0.
'campaign/contacts/view/<sourceId:\d+>' => ['template' => 'campaign/contacts/view'],
'campaign/contacts/import/<importId:\d+>' => ['template' => 'campaign/contacts/import/_view'],
'campaign/contacts/import' => 'campaign/imports/index',
'campaign/contacts/import/<siteHandle:{handle}>' => 'campaign/imports/index',
Expand Down
6 changes: 2 additions & 4 deletions src/elements/CampaignElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,13 +468,11 @@ protected function tableAttributeHtml(string $attribute): string

/**
* @inheritdoc
* @since 2.0.0
* TODO: replace with cacheTags() in version 3.0.0
*/
public function getCacheTags(): array
public function cacheTags(): array
{
return [
"campaignType:$this->campaignTypeId",
'campaignType:' . $this->campaignTypeId,
];
}

Expand Down
6 changes: 2 additions & 4 deletions src/elements/MailingListElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,11 @@ protected function defineRules(): array

/**
* @inheritdoc
* @since 2.0.0
* TODO: replace with cacheTags() in version 3.0.0
*/
public function getCacheTags(): array
public function cacheTags(): array
{
return [
"mailingListType:$this->mailingListTypeId",
'mailingListType:' . $this->mailingListTypeId,
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ public function formHtml(?ElementInterface $element = null, bool $static = false
'source' => 'mailingList:' . $element->uid,
]);

// TODO: remove in 3.0.0, when element index URLs include the source, added in Craft 4.3.0.
if (version_compare(Craft::$app->getVersion(), '4.3.0', '<')) {
$viewAllUrl = UrlHelper::cpUrl('campaign/contacts/view/' . $element->id);
}

return Craft::$app->getView()->renderTemplate(
'campaign/mailinglists/_includes/contacts',
[
Expand Down
73 changes: 0 additions & 73 deletions src/helpers/DateRangeHelper.php

This file was deleted.

4 changes: 1 addition & 3 deletions src/services/PendingContactsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ public function purgeExpiredPendingContacts(): void
}

$purgePendingContactsDuration = ConfigHelper::durationInSeconds($settings->purgePendingContactsDuration);
// TODO: switch to using `DateTimeHelper::toDateInterval` in Campaign 3.
/** @noinspection PhpDeprecationInspection */
$interval = DateTimeHelper::secondsToInterval($purgePendingContactsDuration);
$interval = DateTimeHelper::toDateInterval($purgePendingContactsDuration);
$expire = DateTimeHelper::currentUTCDateTime();
$pastTime = $expire->sub($interval);

Expand Down
13 changes: 8 additions & 5 deletions src/widgets/CampaignStatsWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

use Craft;
use craft\base\Widget;
use craft\helpers\DateRange;
use craft\helpers\Db;
use putyourlightson\campaign\assets\WidgetAsset;
use putyourlightson\campaign\Campaign;
use putyourlightson\campaign\elements\CampaignElement;
use putyourlightson\campaign\elements\SendoutElement;
use putyourlightson\campaign\helpers\DateRangeHelper;
use putyourlightson\campaign\helpers\NumberHelper;
use putyourlightson\campaign\records\ContactCampaignRecord;

Expand Down Expand Up @@ -105,19 +105,22 @@ public function getBodyHtml(): ?string
}

if ($this->dateRange) {
[$startDate, $endDate] = DateRangeHelper::dateRangeByType($this->dateRange);
[$startDate, $endDate] = DateRange::dateRangeByType($this->dateRange);
$startDate = Db::prepareDateForDb($startDate);
$endDate = Db::prepareDateForDb($endDate);

$campaignQuery->andWhere(['and',
$campaignQuery->andWhere([
'and',
['>=', '[[elements.dateCreated]]', $startDate],
['<', '[[elements.dateCreated]]', $endDate],
]);
$sendoutQuery->andWhere(['and',
$sendoutQuery->andWhere([
'and',
['>=', 'sendDate', $startDate],
['<', 'sendDate', $endDate],
]);
$contactCampaignQuery->andWhere(['and',
$contactCampaignQuery->andWhere([
'and',
['>=', 'sent', $startDate],
['<', 'sent', $endDate],
]);
Expand Down
18 changes: 9 additions & 9 deletions src/widgets/DateRangeWidgetTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace putyourlightson\campaign\widgets;

use Craft;
use putyourlightson\campaign\helpers\DateRangeHelper;
use craft\helpers\DateRange;

/**
* @since 2.4.0
Expand All @@ -25,14 +25,14 @@ public function getDateRangeOptions(): array
{
return [
null => Craft::t('campaign', 'All time'),
DateRangeHelper::TYPE_TODAY => Craft::t('app', 'Today'),
DateRangeHelper::TYPE_THIS_WEEK => Craft::t('app', 'This week'),
DateRangeHelper::TYPE_THIS_MONTH => Craft::t('app', 'This month'),
DateRangeHelper::TYPE_THIS_YEAR => Craft::t('app', 'This year'),
DateRangeHelper::TYPE_PAST_7_DAYS => Craft::t('app', 'Past {num} days', ['num' => 7]),
DateRangeHelper::TYPE_PAST_30_DAYS => Craft::t('app', 'Past {num} days', ['num' => 30]),
DateRangeHelper::TYPE_PAST_90_DAYS => Craft::t('app', 'Past {num} days', ['num' => 90]),
DateRangeHelper::TYPE_PAST_YEAR => Craft::t('app', 'Past year'),
DateRange::TYPE_TODAY => Craft::t('app', 'Today'),
DateRange::TYPE_THIS_WEEK => Craft::t('app', 'This week'),
DateRange::TYPE_THIS_MONTH => Craft::t('app', 'This month'),
DateRange::TYPE_THIS_YEAR => Craft::t('app', 'This year'),
DateRange::TYPE_PAST_7_DAYS => Craft::t('app', 'Past {num} days', ['num' => 7]),
DateRange::TYPE_PAST_30_DAYS => Craft::t('app', 'Past {num} days', ['num' => 30]),
DateRange::TYPE_PAST_90_DAYS => Craft::t('app', 'Past {num} days', ['num' => 90]),
DateRange::TYPE_PAST_YEAR => Craft::t('app', 'Past year'),
];
}
}
10 changes: 6 additions & 4 deletions src/widgets/MailingListStatsWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

use Craft;
use craft\base\Widget;
use craft\helpers\DateRange;
use craft\helpers\Db;
use putyourlightson\campaign\assets\WidgetAsset;
use putyourlightson\campaign\Campaign;
use putyourlightson\campaign\elements\MailingListElement;
use putyourlightson\campaign\helpers\DateRangeHelper;
use putyourlightson\campaign\records\ContactMailingListRecord;

/**
Expand Down Expand Up @@ -101,15 +101,17 @@ public function getBodyHtml(): ?string
}

if ($this->dateRange) {
[$startDate, $endDate] = DateRangeHelper::dateRangeByType($this->dateRange);
[$startDate, $endDate] = DateRange::dateRangeByType($this->dateRange);
$startDate = Db::prepareDateForDb($startDate);
$endDate = Db::prepareDateForDb($endDate);

$mailingListQuery->andWhere(['and',
$mailingListQuery->andWhere([
'and',
['>=', '[[elements.dateCreated]]', $startDate],
['<', '[[elements.dateCreated]]', $endDate],
]);
$contactMailingListQuery->andWhere(['and',
$contactMailingListQuery->andWhere([
'and',
['>=', 'subscribed', $startDate],
['<', 'subscribed', $endDate],
]);
Expand Down

0 comments on commit 4db0e08

Please sign in to comment.