diff --git a/CHANGELOG.md b/CHANGELOG.md index 0464147..1b5d939 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for Blogify +## 1.0.9 - 2022-07-06 +### Fixed +- Multisite Support [#2](https://github.com/matfish2/craft-blogify/issues/2) + ## 1.0.8 - 2021-11-26 ### Changed - Seeding: Randomize post date diff --git a/src/migrations/Migrators/BlogCategoriesMigrator.php b/src/migrations/Migrators/BlogCategoriesMigrator.php index c3e7dee..b306c75 100644 --- a/src/migrations/Migrators/BlogCategoriesMigrator.php +++ b/src/migrations/Migrators/BlogCategoriesMigrator.php @@ -22,22 +22,26 @@ public static function add(): bool return true; } - $siteId = Craft::$app->sites->getPrimarySite()->id; + $allSitesSettings = []; + + foreach (Craft::$app->getSites()->getAllSiteIds() as $siteId) { + $allSitesSettings[$siteId] = new CategoryGroup_SiteSettings([ + 'siteId' => $siteId, + 'hasUrls' => true, + 'uriFormat' => 'blog/category/{slug}', + 'template' => 'blogify/filters/category/_entry', + ]); + } - $siteSettings = new CategoryGroup_SiteSettings([ - 'siteId' => Craft::$app->sites->getPrimarySite()->id, - 'hasUrls' => true, - 'uriFormat' => 'blog/category/{slug}', - 'template' => 'blogify/filters/category/_entry', - ]); $categoryGroup = new CategoryGroup([ 'name' => 'Blog Categories', 'handle' => Handles::CATEGORIES, ] ); + blogify_log("Setting Category group site settings..."); - $categoryGroup->setSiteSettings([$siteId => $siteSettings]); + $categoryGroup->setSiteSettings($allSitesSettings); return Craft::$app->categories->saveGroup($categoryGroup); } diff --git a/src/services/SectionService.php b/src/services/SectionService.php index 167edb6..25641f7 100644 --- a/src/services/SectionService.php +++ b/src/services/SectionService.php @@ -20,19 +20,23 @@ public function add($name, $handle, $type, $url, $template): bool return true; } + $allSitesSettings = []; + + foreach (Craft::$app->getSites()->getAllSiteIds() as $siteId) { + $allSitesSettings[$siteId] = new Section_SiteSettings([ + 'siteId' => $siteId, + 'enabledByDefault' => true, + 'hasUrls' => true, + 'uriFormat' => 'blog' . $url, + 'template' => 'blogify/' . $template, + ]); + } + $section = new Section([ 'name' => $name, 'handle' => $handle, 'type' => $type, - 'siteSettings' => [ - new Section_SiteSettings([ - 'siteId' => Craft::$app->sites->getPrimarySite()->id, - 'enabledByDefault' => true, - 'hasUrls' => true, - 'uriFormat' => 'blog' . $url, - 'template' => 'blogify/' . $template, - ]), - ] + 'siteSettings' => $allSitesSettings ]); if (!Craft::$app->sections->saveSection($section)) {