From 98262a568c999aa6877cc99cf083aeb7dda50c5f Mon Sep 17 00:00:00 2001 From: Josh Angell Date: Fri, 7 Feb 2020 15:43:25 +0000 Subject: [PATCH 1/6] Added fix in project config helper to deal with upgrading from older versions. Fixes #89 --- src/helpers/ProjectConfig.php | 39 +++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/helpers/ProjectConfig.php b/src/helpers/ProjectConfig.php index 83764f9..1d2e37a 100644 --- a/src/helpers/ProjectConfig.php +++ b/src/helpers/ProjectConfig.php @@ -14,23 +14,32 @@ class ProjectConfig */ public static function rebuildProjectConfig(): array { + $projectConfig = Craft::$app->getProjectConfig(); + $schemaVersion = $projectConfig->get('plugins.spoon.schemaVersion', true); + $oldSchema = version_compare($schemaVersion, '3.4.0', '<'); + $fields = Craft::$app->getFields(); $configData = []; + $selectArray = [ + 'b.uid', + 'b.fieldId', + 'b.matrixBlockTypeId', + 'b.fieldLayoutId', + 'b.groupName', + 'b.context', + 'b.uid', + 'f.uid AS fieldUid', + 'mbt.uid AS matrixBlockUid', + ]; + + if (!$oldSchema) { + $selectArray[] = 'b.groupSortOrder'; + $selectArray[] = 'b.sortOrder'; + } + $blockTypes = (new Query()) - ->select([ - 'b.uid', - 'b.fieldId', - 'b.matrixBlockTypeId', - 'b.fieldLayoutId', - 'b.groupName', - 'b.context', - 'b.groupSortOrder', - 'b.sortOrder', - 'b.uid', - 'f.uid AS fieldUid', - 'mbt.uid AS matrixBlockUid', - ]) + ->select($selectArray) ->from(['{{%spoon_blocktypes}} b']) ->innerJoin('{{%fields}} f', '[[b.fieldId]] = [[f.id]]') ->innerJoin('{{%matrixblocktypes}} mbt', '[[b.matrixBlockTypeId]] = [[mbt.id]]') @@ -41,8 +50,8 @@ public static function rebuildProjectConfig(): array $data = [ 'groupName' => $blockType['groupName'], 'context' => $blockType['context'], - 'groupSortOrder' => $blockType['groupSortOrder'], - 'sortOrder' => $blockType['sortOrder'], + 'groupSortOrder' => !$oldSchema ?? $blockType['groupSortOrder'], + 'sortOrder' => !$oldSchema ?? $blockType['sortOrder'], 'field' => $blockType['fieldUid'], 'matrixBlockType' => $blockType['matrixBlockUid'], ]; From 619d852b1e5875578457cb664b6974a6b30fde07 Mon Sep 17 00:00:00 2001 From: Josh Angell Date: Fri, 7 Feb 2020 15:50:13 +0000 Subject: [PATCH 2/6] Drop project config data on uninstall. See #85 --- src/Spoon.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Spoon.php b/src/Spoon.php index 39ca4c2..bffa329 100644 --- a/src/Spoon.php +++ b/src/Spoon.php @@ -211,4 +211,16 @@ protected function createSettingsModel() return new Settings(); } + /** + * @inheritdoc + */ + protected function afterUninstall() + { + // After uninstall drop project config keys + $projectConfig = Craft::$app->getProjectConfig(); + $projectConfig->muteEvents = true; + $projectConfig->remove(BlockTypes::CONFIG_BLOCKTYPE_KEY); + $projectConfig->muteEvents = false; + } + } From 162e4a14db15dae33a3b3dc95d4219ac1fe3de4c Mon Sep 17 00:00:00 2001 From: Josh Angell Date: Fri, 7 Feb 2020 16:11:52 +0000 Subject: [PATCH 3/6] Fixes an issue with removing field layouts from current block type configurations. Fixes #84 --- src/controllers/BlockTypesController.php | 16 +++++++++++----- src/services/BlockTypes.php | 12 +++++++----- src/services/Loader.php | 6 ++++-- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/controllers/BlockTypesController.php b/src/controllers/BlockTypesController.php index 11be8a2..1beccb9 100644 --- a/src/controllers/BlockTypesController.php +++ b/src/controllers/BlockTypesController.php @@ -152,13 +152,11 @@ public function actionSaveFieldLayout() $spoonedBlockTypeId = Craft::$app->getRequest()->getParam('spoonedBlockTypeId'); $blockTypeFieldLayouts = Craft::$app->getRequest()->getParam('blockTypeFieldLayouts'); - if ($spoonedBlockTypeId) - { + if ($spoonedBlockTypeId) { if (!$spoonedBlockType = Spoon::$plugin->blockTypes->getById($spoonedBlockTypeId)) { return false; } - } else - { + } else { return false; } @@ -180,12 +178,20 @@ public function actionSaveFieldLayout() // We don’t have a new field layout, so remove the old one if there is one $oldFieldLayoutId = $spoonedBlockType->fieldLayoutId; + if (!Craft::$app->fields->deleteLayoutById($oldFieldLayoutId)) { + return $this->asJson([ + 'success' => false + ]); + } + + // Also null the col on our block type row $spoonedBlockType->fieldLayoutId = null; - if (!Spoon::$plugin->blockTypes->save($spoonedBlockType) || !Craft::$app->fields->deleteLayoutById($oldFieldLayoutId)) { + if (!Spoon::$plugin->blockTypes->save($spoonedBlockType)) { return $this->asJson([ 'success' => false ]); } + } return $this->asJson([ diff --git a/src/services/BlockTypes.php b/src/services/BlockTypes.php index 99bcd73..b48984a 100644 --- a/src/services/BlockTypes.php +++ b/src/services/BlockTypes.php @@ -526,11 +526,13 @@ private function _populateBlockTypeFromRecord(BlockTypeRecord $blockTypeRecord) $blockType->matrixBlockType = $blockType->getBlockType(); // Save the field layout content on to our model - $layout = $blockType->getFieldLayout(); - $blockType->fieldLayoutModel = [ - 'tabs' => $layout->getTabs(), - 'fields' => $layout->getFields() - ]; + if ($blockType->fieldLayoutId) { + $layout = $blockType->getFieldLayout(); + $blockType->fieldLayoutModel = [ + 'tabs' => $layout->getTabs(), + 'fields' => $layout->getFields() + ]; + } return $blockType; } diff --git a/src/services/Loader.php b/src/services/Loader.php index 411267b..49e1af9 100644 --- a/src/services/Loader.php +++ b/src/services/Loader.php @@ -305,8 +305,10 @@ public function fieldManipulator($context, $versioned = false) $translations[] = $spoonedBlockType->groupName; $translations[] = $spoonedBlockType->matrixBlockType->name; - foreach ($spoonedBlockType->fieldLayoutModel['tabs'] as $tab) { - $translations[] = $tab->name; + if ($spoonedBlockType->fieldLayoutModel) { + foreach ($spoonedBlockType->fieldLayoutModel['tabs'] as $tab) { + $translations[] = $tab->name; + } } } From b9abf3f32d1faab9ba4144e0693f420a202ee72c Mon Sep 17 00:00:00 2001 From: Josh Angell Date: Fri, 7 Feb 2020 16:19:37 +0000 Subject: [PATCH 4/6] Fixed project config helper yet again. --- src/helpers/ProjectConfig.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers/ProjectConfig.php b/src/helpers/ProjectConfig.php index 1d2e37a..22fc22e 100644 --- a/src/helpers/ProjectConfig.php +++ b/src/helpers/ProjectConfig.php @@ -50,8 +50,8 @@ public static function rebuildProjectConfig(): array $data = [ 'groupName' => $blockType['groupName'], 'context' => $blockType['context'], - 'groupSortOrder' => !$oldSchema ?? $blockType['groupSortOrder'], - 'sortOrder' => !$oldSchema ?? $blockType['sortOrder'], + 'groupSortOrder' => $oldSchema ? null : $blockType['groupSortOrder'], + 'sortOrder' => $oldSchema ? null : $blockType['sortOrder'], 'field' => $blockType['fieldUid'], 'matrixBlockType' => $blockType['matrixBlockUid'], ]; From 2572082a34858f58cbc7c7d7906419a2aaee036e Mon Sep 17 00:00:00 2001 From: Josh Angell Date: Fri, 7 Feb 2020 16:20:02 +0000 Subject: [PATCH 5/6] Added note to changelog about updating to 3.5.x from pre 3.4.0 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c09d58..bbb7600 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ## 3.5.0 - 2020-02-05 +> {note} Before updating to 3.5.0 or greater it is a good idea to update to 3.4.3 first. + ### Fixed - Fixed things not working with Craft 3.4 ([#79](https://github.com/angell-co/Spoon/issues/79)) - Fixed an issue with block type configurations not keeping their order when deployed to another environment via project config ([#80](https://github.com/angell-co/Spoon/issues/80)) From ba5bd668de46911533a67655513792bcd17c7cb3 Mon Sep 17 00:00:00 2001 From: Josh Angell Date: Fri, 7 Feb 2020 16:20:09 +0000 Subject: [PATCH 6/6] Changelog for 3.5.2 --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbb7600..c4a78dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ## Unreleased +## 3.5.2 - 2020-02-07 + +### Changed +- Spoon-specific project config data is now wiped on uninstall ([#85](https://github.com/angell-co/Spoon/issues/85)) + +### Fixed +- Fixed an issue with updating to 3.5.x from 3.3.x ([#89](https://github.com/angell-co/Spoon/issues/89)) +- Fixed an issue with removing field layouts from current block type configurations ([#84](https://github.com/angell-co/Spoon/issues/84)) + + ## 3.5.1 - 2020-02-05 ### Fixed