From 3171bc1b52dc004367930edccf9fa3e10bd63369 Mon Sep 17 00:00:00 2001 From: Bart van Gennep Date: Fri, 29 Jan 2016 17:01:53 +0100 Subject: [PATCH 1/4] Don't import sections and fields when no changes have been detected --- src/Services/Fields.php | 8 ++++++++ src/Services/Sections.php | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/src/Services/Fields.php b/src/Services/Fields.php index 186cdc41..d89c4f85 100644 --- a/src/Services/Fields.php +++ b/src/Services/Fields.php @@ -292,6 +292,14 @@ private function importFields(array $fieldDefinitions, FieldGroupModel $group) foreach ($fieldDefinitions as $fieldHandle => $fieldDef) { $field = $this->getFieldModel($fieldHandle); $schematicFieldModel = $fieldFactory->build($fieldDef['type']); + + if ($schematicFieldModel->getDefinition($field, true) === $fieldDef ) { + Craft::log(Craft::t('Skipping `{name}`, no changes detected', ['name' => $field->name])); + continue; + } + + Craft::log(Craft::t('Importing `{name}`', ['name' => $fieldDef['name']])); + $schematicFieldModel->populate($fieldDef, $field, $fieldHandle, $group); $this->saveFieldModel($field); } diff --git a/src/Services/Sections.php b/src/Services/Sections.php index 7ae97aa6..f836d5f7 100644 --- a/src/Services/Sections.php +++ b/src/Services/Sections.php @@ -158,6 +158,11 @@ public function import(array $sectionDefinitions, $force = false) unset($sections[$sectionHandle]); + if($sectionDefinition === $this->getSectionDefinition($section, null)){ + Craft::log(Craft::t('Skipping `{name}`, no changes detected', ['name' => $section->name])); + continue; + } + if (!array_key_exists('locales', $sectionDefinition)) { $this->addError('`sections[handle].locales` must be defined'); @@ -170,6 +175,8 @@ public function import(array $sectionDefinitions, $force = false) continue; } + Craft::log(Craft::t('Importing section `{name}`', ['name' => $sectionDefinition['name']])); + $this->populateSection($section, $sectionDefinition, $sectionHandle); // Create initial section record From 5bbfba5f4523e175de1860d465ec4599de8cacea Mon Sep 17 00:00:00 2001 From: Bart van Gennep Date: Fri, 29 Jan 2016 17:06:36 +0100 Subject: [PATCH 2/4] Repeat field import after everything else has been imported so full double imports are no longer needed --- src/Services/Schematic.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Services/Schematic.php b/src/Services/Schematic.php index 08b6672f..01e831ce 100644 --- a/src/Services/Schematic.php +++ b/src/Services/Schematic.php @@ -100,6 +100,7 @@ private function importDataModel(Data $model, $force) $sectionImportResult = Craft::app()->schematic_sections->import($model->getAttribute('sections'), $force); $userGroupImportResult = Craft::app()->schematic_userGroups->import($model->getAttribute('userGroups'), $force); $userImportResult = Craft::app()->schematic_users->import($model->getAttribute('users'), true); + $fieldImportResultFinal = Craft::app()->schematic_fields->import($model->getAttribute('fields'), $force); // Element index settings are supported from Craft 2.5 if (version_compare(CRAFT_VERSION, '2.5', '>=')) { @@ -116,6 +117,7 @@ private function importDataModel(Data $model, $force) $result->consume($sectionImportResult); $result->consume($userGroupImportResult); $result->consume($userImportResult); + $result->consume($fieldImportResultFinal); // Element index settings are supported from Craft 2.5 if (version_compare(CRAFT_VERSION, '2.5', '>=')) { From d6025b7a384a443f4f06f3d7ba2c1aab44387693 Mon Sep 17 00:00:00 2001 From: Bart van Gennep Date: Fri, 29 Jan 2016 17:08:23 +0100 Subject: [PATCH 3/4] Updated changelog --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 549f83ac..047d0444 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,11 @@ public function registerSchematicFieldModels() ## Changelog +###3.1.1### + - Sections are not imported when nothing has changed + - Fields are not imported when nothing has changed + - Field import is repeated after everything else has been imported to make sure sources are set correctly + ###3.1.1### - Folders are now CamelCased to add support for case-sensitive systems and PSR-4 (thanks to @ostark and @ukautz) From 03c239523a678e9c8c1634b95b1c4fd479b16fc4 Mon Sep 17 00:00:00 2001 From: Bart van Gennep Date: Fri, 29 Jan 2016 17:16:29 +0100 Subject: [PATCH 4/4] Fix version number --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 047d0444..dec38e82 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ public function registerSchematicFieldModels() ## Changelog -###3.1.1### +###3.1.2### - Sections are not imported when nothing has changed - Fields are not imported when nothing has changed - Field import is repeated after everything else has been imported to make sure sources are set correctly