From 1c3f183d67f18df84ed83d11a59dd11fccd3f420 Mon Sep 17 00:00:00 2001 From: bencroker Date: Sun, 14 Apr 2024 08:47:57 -0600 Subject: [PATCH] Code cleanup --- CHANGELOG.md | 8 ++++++++ composer.json | 2 +- src/services/ReportsService.php | 27 ++++++++++++++------------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2273b60..23abef5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Release Notes for Campaign +## 3.1.0 - Unreleased + +### Added + +- Added one-click unsubscribe headers to sent emails ([#467](https://github.com/putyourlightson/craft-campaign/issues/467)). +- Added a new one-click unsubscribe controller action. +- Added an `addOneClickUnsubscribeHeaders` config setting that determines whether one-click unsubscribe headers should be added to emails, defaulting to `true`. + ## 3.0.0 - 2024-04-08 > {warning} “Legacy” and “Template” segments are no longer available will be deleted in this update. They should be replaced with regular segments before updating, or they will be lost. diff --git a/composer.json b/composer.json index 23d32655..194f9025 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "putyourlightson/craft-campaign", "description": "Send and manage email campaigns, contacts and mailing lists.", - "version": "3.0.0", + "version": "3.1.0", "type": "craft-plugin", "homepage": "https://putyourlightson.com/plugins/campaign", "license": "proprietary", diff --git a/src/services/ReportsService.php b/src/services/ReportsService.php index 0668905e..bbdc4b8d 100755 --- a/src/services/ReportsService.php +++ b/src/services/ReportsService.php @@ -10,6 +10,7 @@ use craft\db\ActiveRecord; use craft\db\Query; use craft\db\Table; +use craft\enums\CmsEdition; use craft\helpers\DateTimeHelper; use craft\helpers\Db; use craft\helpers\Json; @@ -56,12 +57,12 @@ public function getMaxIntervals(string $interval): int /** * Returns campaigns report data. */ - public function getCampaignsReportData(Site|int|null $site = null): array + public function getCampaignsReportData(Site|null $site = null): array { // Get all sent campaigns $campaigns = CampaignElement::find() ->status(CampaignElement::STATUS_SENT) - ->orderBy('lastSent DESC') + ->orderBy(['lastSent' => SORT_DESC]) ->site($site) ->all(); @@ -432,7 +433,7 @@ public function getContactMailingListActivity(int $contactId, int $limit = null, /** * Returns mailing lists report data. */ - public function getMailingListsReportData(Site|int|null $site = null): array + public function getMailingListsReportData(Site|null $site = null): array { // Get all mailing lists in all sites $mailingLists = MailingListElement::find() @@ -650,7 +651,7 @@ private function getChartData(string $recordClass, array $condition, array $inte $fields = []; foreach ($record->fields() as $field) { - $fields[] = 'MIN([[' . $field . ']]) AS ' . $field; + $fields[$field] = 'MIN([[' . $field . ']])'; } // Get records within date range @@ -659,7 +660,7 @@ private function getChartData(string $recordClass, array $condition, array $inte ->where($condition) ->andWhere(Db::parseDateParam('dateCreated', $endDateTime, '<')) ->orderBy(['dateCreated' => SORT_ASC]) - ->groupBy('contactId') + ->groupBy(['contactId']) ->all(); // Get activity @@ -737,7 +738,7 @@ private function getActivity(array $models, string $interaction = null, int $lim $contactActivityModel->sourceUrl = UrlHelper::cpUrl('campaign/contacts/import/' . $model->source); break; case 'user': - $path = (Craft::$app->getEdition() === Craft::Pro && $model->source) ? 'users/' . $model->source : 'myaccount'; + $path = (Craft::$app->edition !== CmsEdition::Solo && $model->source) ? 'users/' . $model->source : 'myaccount'; $contactActivityModel->sourceUrl = UrlHelper::cpUrl($path); break; default: @@ -771,14 +772,14 @@ private function getLocations(string $recordClass, array $condition, int $total, /** @var ActiveRecord $recordClass */ $query = ContactRecord::find() - ->select(array_merge($fields, ['COUNT(*) AS count'])) - ->groupBy('country'); + ->select(array_merge($fields, ['count' => 'COUNT(*)'])) + ->groupBy(['country']); if ($recordClass != ContactRecord::class) { $contactIds = $recordClass::find() - ->select('contactId') + ->select(['contactId']) ->where($condition) - ->groupBy('contactId') + ->groupBy(['contactId']) ->column(); $query->andWhere([ContactRecord::tableName() . '.id' => $contactIds]); @@ -839,15 +840,15 @@ private function getDevices(string $recordClass, array $condition, bool $detaile /** @var ActiveRecord $recordClass */ $query = ContactRecord::find() - ->select(array_merge($fields, ['COUNT(*) AS count'])) + ->select(array_merge($fields, ['count' => 'COUNT(*)'])) ->where(['not', ['device' => null]]) ->groupBy($fields); if ($recordClass != ContactRecord::class) { $contactIds = $recordClass::find() - ->select('contactId') + ->select(['contactId']) ->where($condition) - ->groupBy('contactId') + ->groupBy(['contactId']) ->column(); $query->andWhere([ContactRecord::tableName() . '.id' => $contactIds]);