Skip to content

Commit

Permalink
Fixed import of multiple sites in same sitegroup by clearing sitegrou…
Browse files Browse the repository at this point in the history
…p cache.
  • Loading branch information
bvangennep committed Nov 18, 2018
1 parent 3489dc4 commit 1a4150e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Delete empty field groups on import with force
### Fixed
- Fixed user field sources not being exported
- Fixed import of multiple sites in same sitegroup

### 4.0.17 - 2018-09-24
### Fixed
Expand Down
16 changes: 16 additions & 0 deletions src/Converters/Models/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public function deleteRecord(Model $record): bool
public function getGroupIdByName($name)
{
if (!isset($this->groups)) {
$this->resetCraftSitesServiceGroupsCache();

$this->groups = [];
foreach (Craft::$app->sites->getAllGroups() as $group) {
$this->groups[$group->name] = $group->id;
Expand All @@ -88,4 +90,18 @@ public function getGroupIdByName($name)

return $this->groups[$name];
}

/**
* Reset craft site service groups cache using reflection.
*/
private function resetCraftSitesServiceGroupsCache()
{
$obj = Craft::$app->sites;
$refObject = new \ReflectionObject($obj);
if ($refObject->hasProperty('_fetchedAllGroups')) {
$refProperty = $refObject->getProperty('_fetchedAllGroups');
$refProperty->setAccessible(true);
$refProperty->setValue($obj, false);
}
}
}

0 comments on commit 1a4150e

Please sign in to comment.