Skip to content

Commit

Permalink
Merge pull request #34 from itmundi/bypass-craft-caching-system
Browse files Browse the repository at this point in the history
Bypass craft caching system
  • Loading branch information
bvangennep committed Feb 23, 2016
2 parents c36d9f9 + 4ff521a commit cffd709
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public function registerSchematicFieldModels()

## Changelog

###3.1.4###
- Reset craft field service cache before each import
- Get section entry types by section id in stead of from section

###3.1.3###
- Added array_key_exists checks for AssetField settings

Expand Down
13 changes: 13 additions & 0 deletions src/Services/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function import(array $groupDefinitions, $force = false)
$contentService->fieldContext = 'global';
$contentService->contentTable = 'content';

$this->resetCraftFieldsServiceCache();
$this->groups = $this->getFieldsService()->getAllGroups('name');
$this->fields = $this->getFieldsService()->getAllFields('handle');

Expand Down Expand Up @@ -424,4 +425,16 @@ private function getPrepareFieldLayout(array $fieldLayoutDef)
'required' => $requiredFields,
];
}

/**
* Reset craft fields service cache using reflection
*/
private function resetCraftFieldsServiceCache()
{
$obj = $this->getFieldsService();
$refObject = new \ReflectionObject( $obj );
$refProperty = $refObject->getProperty( '_fetchedAllGroups' );
$refProperty->setAccessible( true );
$refProperty->setValue($obj, false);
}
}
2 changes: 1 addition & 1 deletion src/Services/Sections.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public function import(array $sectionDefinitions, $force = false)
continue;
}

$entryTypes = $section->getEntryTypes('handle');
$entryTypes = Craft::app()->sections->getEntryTypesBySectionId($section->id, 'handle');

foreach ($sectionDefinition['entryTypes'] as $entryTypeHandle => $entryTypeDefinition) {
$entryType = array_key_exists($entryTypeHandle, $entryTypes)
Expand Down

0 comments on commit cffd709

Please sign in to comment.