Skip to content

Commit

Permalink
Reset section model cache using reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart van Gennep committed Feb 23, 2016
1 parent cffd709 commit 496ee6f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Services/Sections.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public function import(array $sectionDefinitions, $force = false)
Craft::log(Craft::t('Importing section `{name}`', ['name' => $sectionDefinition['name']]));

$this->populateSection($section, $sectionDefinition, $sectionHandle);
$this->resetCraftFieldsSectionModelCache($section);

// Create initial section record
if (!$this->preSaveSection($section)) {
Expand Down Expand Up @@ -326,4 +327,17 @@ private function populateEntryType(EntryTypeModel $entryType, array $entryTypeDe
$fieldLayout = Craft::app()->schematic_fields->getFieldLayout($entryTypeDefinition['fieldLayout']);
$entryType->setFieldLayout($fieldLayout);
}

/**
* Reset craft section model cache using reflection
* @param SectionModel $section
*/
private function resetCraftFieldsSectionModelCache(SectionModel $section)
{
$obj = $section;
$refObject = new \ReflectionObject( $obj );
$refProperty = $refObject->getProperty( '_entryTypes' );
$refProperty->setAccessible( true );
$refProperty->setValue($obj, null);
}
}

0 comments on commit 496ee6f

Please sign in to comment.