diff --git a/CHANGELOG.md b/CHANGELOG.md index 3356375d..a4697af6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixed +- Fixed a bug in which the content column was not being populated for elements in non primary sites after upgrading from Campaign 2 ([#470](https://github.com/putyourlightson/craft-campaign/issues/470)). - Fixed the PHPDoc type for relation field values. ## 3.1.1 - 2024-04-16 diff --git a/src/Campaign.php b/src/Campaign.php index a14d897b..e1db6450 100644 --- a/src/Campaign.php +++ b/src/Campaign.php @@ -180,7 +180,7 @@ public static function editions(): array /** * @inheritdoc */ - public string $schemaVersion = '3.0.0.3'; + public string $schemaVersion = '3.1.2'; /** * @inheritdoc diff --git a/src/migrations/m240502_120000_content_refactor_elements_non_primary_sites.php b/src/migrations/m240502_120000_content_refactor_elements_non_primary_sites.php new file mode 100644 index 00000000..ffcc6e10 --- /dev/null +++ b/src/migrations/m240502_120000_content_refactor_elements_non_primary_sites.php @@ -0,0 +1,72 @@ +getSites()->getPrimarySite()->id; + + foreach (Campaign::$plugin->campaignTypes->getAllCampaignTypes() as $campaignType) { + if ($campaignType->siteId !== $primarySiteId) { + $this->updateElements( + CampaignElement::find() + ->campaignType($campaignType) + ->siteId($campaignType->siteId) + ->ids(), + $campaignType->getFieldLayout(), + ); + } + } + + foreach (Campaign::$plugin->mailingListTypes->getAllMailingListTypes() as $mailingListType) { + if ($mailingListType->siteId !== $primarySiteId) { + $this->updateElements( + MailingListElement::find() + ->mailingListType($mailingListType) + ->siteId($mailingListType->siteId) + ->ids(), + $mailingListType->getFieldLayout(), + ); + } + } + + $this->updateElements( + SegmentElement::find() + ->siteId(['not', $primarySiteId]) + ->ids(), + Craft::$app->getFields()->getLayoutByType(SegmentElement::class), + ); + + $this->updateElements( + SendoutElement::find() + ->siteId(['not', $primarySiteId]) + ->ids(), + Craft::$app->getFields()->getLayoutByType(SendoutElement::class), + ); + + return true; + } + + /** + * @inheritdoc + */ + public function safeDown(): bool + { + echo self::class . " cannot be reverted.\n"; + + return false; + } +}