diff --git a/src/Campaign.php b/src/Campaign.php index e3ffaac1..9a5349de 100644 --- a/src/Campaign.php +++ b/src/Campaign.php @@ -416,8 +416,6 @@ protected function getCpRoutes(): array 'campaign/campaigns//' => 'elements/edit', 'campaign/contacts/new' => 'campaign/contacts/create', 'campaign/contacts/' => 'elements/edit', - // TODO: remove in 5.0.0, when element index URLs include the source, added in Craft 4.3.0. - 'campaign/contacts/view/' => ['template' => 'campaign/contacts/view'], 'campaign/contacts/import/' => ['template' => 'campaign/contacts/import/_view'], 'campaign/contacts/import' => 'campaign/imports/index', 'campaign/contacts/import/' => 'campaign/imports/index', diff --git a/src/elements/CampaignElement.php b/src/elements/CampaignElement.php index a0fa1daf..550a4fdb 100755 --- a/src/elements/CampaignElement.php +++ b/src/elements/CampaignElement.php @@ -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, ]; } diff --git a/src/elements/MailingListElement.php b/src/elements/MailingListElement.php index 01bf556d..039e4fed 100755 --- a/src/elements/MailingListElement.php +++ b/src/elements/MailingListElement.php @@ -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, ]; } diff --git a/src/fieldlayoutelements/mailinglists/MailingListContactFieldLayoutElement.php b/src/fieldlayoutelements/mailinglists/MailingListContactFieldLayoutElement.php index 95870d92..2e7b31d9 100644 --- a/src/fieldlayoutelements/mailinglists/MailingListContactFieldLayoutElement.php +++ b/src/fieldlayoutelements/mailinglists/MailingListContactFieldLayoutElement.php @@ -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', [ diff --git a/src/helpers/DateRangeHelper.php b/src/helpers/DateRangeHelper.php deleted file mode 100755 index 5c8d0982..00000000 --- a/src/helpers/DateRangeHelper.php +++ /dev/null @@ -1,73 +0,0 @@ - [ - DateTimeHelper::today(), - DateTimeHelper::tomorrow(), - ], - self::TYPE_THIS_WEEK => [ - DateTimeHelper::thisWeek(), - DateTimeHelper::nextWeek(), - ], - self::TYPE_THIS_MONTH => [ - DateTimeHelper::thisMonth(), - DateTimeHelper::nextMonth(), - ], - self::TYPE_THIS_YEAR => [ - DateTimeHelper::thisYear(), - DateTimeHelper::nextYear(), - ], - self::TYPE_PAST_7_DAYS => [ - DateTimeHelper::today()->modify('-7 days'), - DateTimeHelper::now(), - ], - self::TYPE_PAST_30_DAYS => [ - DateTimeHelper::today()->modify('-30 days'), - DateTimeHelper::now(), - ], - self::TYPE_PAST_90_DAYS => [ - DateTimeHelper::today()->modify('-90 days'), - DateTimeHelper::now(), - ], - self::TYPE_PAST_YEAR => [ - DateTimeHelper::today()->modify('-1 year'), - DateTimeHelper::now(), - ], - default => throw new InvalidArgumentException("Invalid range type: $rangeType"), - }; - } -} diff --git a/src/services/PendingContactsService.php b/src/services/PendingContactsService.php index f03d7cdf..2deb2710 100644 --- a/src/services/PendingContactsService.php +++ b/src/services/PendingContactsService.php @@ -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); diff --git a/src/widgets/CampaignStatsWidget.php b/src/widgets/CampaignStatsWidget.php index e4d48e22..b203195e 100755 --- a/src/widgets/CampaignStatsWidget.php +++ b/src/widgets/CampaignStatsWidget.php @@ -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; @@ -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], ]); diff --git a/src/widgets/DateRangeWidgetTrait.php b/src/widgets/DateRangeWidgetTrait.php index 39530967..f48b7073 100755 --- a/src/widgets/DateRangeWidgetTrait.php +++ b/src/widgets/DateRangeWidgetTrait.php @@ -6,7 +6,7 @@ namespace putyourlightson\campaign\widgets; use Craft; -use putyourlightson\campaign\helpers\DateRangeHelper; +use craft\helpers\DateRange; /** * @since 2.4.0 @@ -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'), ]; } } diff --git a/src/widgets/MailingListStatsWidget.php b/src/widgets/MailingListStatsWidget.php index 6ce0d78c..01bf9423 100755 --- a/src/widgets/MailingListStatsWidget.php +++ b/src/widgets/MailingListStatsWidget.php @@ -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; /** @@ -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], ]);