diff --git a/CHANGELOG.md b/CHANGELOG.md index 08bb0398..eb1831bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ### 4.0.18 ### Added -- Delete empty field groups on import with force +- Delete empty field and site groups on import with force ### Fixed - Fixed user field sources not being exported - Fixed import of multiple sites in same sitegroup diff --git a/src/DataTypes/SiteDataType.php b/src/DataTypes/SiteDataType.php index f733c962..953b67b5 100644 --- a/src/DataTypes/SiteDataType.php +++ b/src/DataTypes/SiteDataType.php @@ -35,9 +35,20 @@ public function getRecords(): array } /** - * Reset craft site service sites cache using reflection. + * {@inheritdoc} */ public function afterImport() + { + $this->clearSiteCaches(); + if (Schematic::$force) { + $this->clearEmptyGroups(); + } + } + + /** + * Reset craft site service sites cache using reflection. + */ + private function clearSiteCaches() { $obj = Craft::$app->sites; $refObject = new \ReflectionObject($obj); @@ -53,4 +64,16 @@ public function afterImport() } $obj->init(); // reload sites } + + /** + * Clear empty sute groups + */ + private function clearEmptyGroups() + { + foreach (Craft::$app->sites->getAllGroups() as $group) { + if (count($group->getSites()) == 0) { + Craft::$app->sites->deleteGroup($group); + } + } + } }