From b9bca475b2795152e143f53a920888e0ae97f015 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Fri, 3 Jun 2022 15:13:36 -0700 Subject: [PATCH] Deprecate pruneDeletedField() methods Resolves #11054 --- CHANGELOG.md | 10 +++++++++ src/base/ApplicationTrait.php | 11 ---------- src/services/Categories.php | 38 ++-------------------------------- src/services/Globals.php | 38 ++-------------------------------- src/services/Sections.php | 39 ++--------------------------------- src/services/Tags.php | 38 ++-------------------------------- src/services/Users.php | 34 ++---------------------------- src/services/Volumes.php | 38 ++-------------------------------- 8 files changed, 22 insertions(+), 224 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c4d6413ed3..a5dc72fc7ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Release Notes for Craft CMS 4 +## Unreleased + +### Deprecated +- Deprecated `craft\services\Categories::pruneDeletedField()`. ([#11054](https://github.com/craftcms/cms/discussions/11054)) +- Deprecated `craft\services\Globals::pruneDeletedField()`. ([#11054](https://github.com/craftcms/cms/discussions/11054)) +- Deprecated `craft\services\Sections::pruneDeletedField()`. ([#11054](https://github.com/craftcms/cms/discussions/11054)) +- Deprecated `craft\services\Tags::pruneDeletedField()`. ([#11054](https://github.com/craftcms/cms/discussions/11054)) +- Deprecated `craft\services\Users::pruneDeletedField()`. ([#11054](https://github.com/craftcms/cms/discussions/11054)) +- Deprecated `craft\services\Volumes::pruneDeletedField()`. ([#11054](https://github.com/craftcms/cms/discussions/11054)) + ## 4.0.4 - 2022-06-03 ### Added diff --git a/src/base/ApplicationTrait.php b/src/base/ApplicationTrait.php index 7f82d0ed0de..2c6dc4ee991 100644 --- a/src/base/ApplicationTrait.php +++ b/src/base/ApplicationTrait.php @@ -27,7 +27,6 @@ use craft\events\DefineFieldLayoutFieldsEvent; use craft\events\DeleteSiteEvent; use craft\events\EditionChangeEvent; -use craft\events\FieldEvent; use craft\fieldlayoutelements\addresses\AddressField; use craft\fieldlayoutelements\addresses\CountryCodeField; use craft\fieldlayoutelements\addresses\LabelField; @@ -1646,16 +1645,6 @@ private function _registerConfigListeners(): void ->onAdd(ProjectConfig::PATH_GRAPHQL_PUBLIC_TOKEN, $this->_proxy('gql', 'handleChangedPublicToken')) ->onUpdate(ProjectConfig::PATH_GRAPHQL_PUBLIC_TOKEN, $this->_proxy('gql', 'handleChangedPublicToken')); - // Prune deleted fields from their layouts - Event::on(Fields::class, Fields::EVENT_AFTER_DELETE_FIELD, function(FieldEvent $event) { - $this->getVolumes()->pruneDeletedField($event); - $this->getTags()->pruneDeletedField($event); - $this->getCategories()->pruneDeletedField($event); - $this->getUsers()->pruneDeletedField($event); - $this->getGlobals()->pruneDeletedField($event); - $this->getSections()->pruneDeletedField($event); - }); - // Prune deleted sites from site settings Event::on(Sites::class, Sites::EVENT_AFTER_DELETE_SITE, function(DeleteSiteEvent $event) { $this->getRoutes()->handleDeletedSite($event); diff --git a/src/services/Categories.php b/src/services/Categories.php index 21ff9e48e51..254949fe646 100644 --- a/src/services/Categories.php +++ b/src/services/Categories.php @@ -16,7 +16,6 @@ use craft\events\CategoryGroupEvent; use craft\events\ConfigEvent; use craft\events\DeleteSiteEvent; -use craft\events\FieldEvent; use craft\helpers\App; use craft\helpers\ArrayHelper; use craft\helpers\Db; @@ -626,43 +625,10 @@ public function handleDeletedCategoryGroup(ConfigEvent $event): void } /** - * Prune a deleted field from category group layouts. - * - * @param FieldEvent $event + * @deprecated in 4.0.5. Unused fields will be pruned automatically as field layouts are resaved. */ - public function pruneDeletedField(FieldEvent $event): void + public function pruneDeletedField(): void { - $field = $event->field; - $fieldUid = $field->uid; - - $projectConfig = Craft::$app->getProjectConfig(); - $categoryGroups = $projectConfig->get(ProjectConfig::PATH_CATEGORY_GROUPS); - - // Engage stealth mode - $projectConfig->muteEvents = true; - - // Loop through the category groups and prune the UID from field layouts. - if (is_array($categoryGroups)) { - foreach ($categoryGroups as $categoryGroupUid => $categoryGroup) { - if (!empty($categoryGroup['fieldLayouts'])) { - foreach ($categoryGroup['fieldLayouts'] as $layoutUid => $layout) { - if (!empty($layout['tabs'])) { - foreach ($layout['tabs'] as $tabUid => $tab) { - $projectConfig->remove(ProjectConfig::PATH_CATEGORY_GROUPS . '.' . $categoryGroupUid . '.fieldLayouts.' . $layoutUid . '.tabs.' . $tabUid . '.fields.' . $fieldUid, 'Prune deleted field'); - } - } - } - } - } - } - - // Nuke all the layout fields from the DB - Db::delete(Table::FIELDLAYOUTFIELDS, [ - 'fieldId' => $field->id, - ]); - - // Allow events again - $projectConfig->muteEvents = false; } /** diff --git a/src/services/Globals.php b/src/services/Globals.php index 83b6c95274f..70c7b1b9ff8 100644 --- a/src/services/Globals.php +++ b/src/services/Globals.php @@ -15,7 +15,6 @@ use craft\errors\ElementNotFoundException; use craft\errors\GlobalSetNotFoundException; use craft\events\ConfigEvent; -use craft\events\FieldEvent; use craft\events\GlobalSetEvent; use craft\helpers\ArrayHelper; use craft\helpers\Db; @@ -512,43 +511,10 @@ public function handleDeletedGlobalSet(ConfigEvent $event): void } /** - * Prune a deleted field from global set. - * - * @param FieldEvent $event + * @deprecated in 4.0.5. Unused fields will be pruned automatically as field layouts are resaved. */ - public function pruneDeletedField(FieldEvent $event): void + public function pruneDeletedField(): void { - $field = $event->field; - $fieldUid = $field->uid; - - $projectConfig = Craft::$app->getProjectConfig(); - $globalSets = $projectConfig->get(ProjectConfig::PATH_GLOBAL_SETS); - - // Engage stealth mode - $projectConfig->muteEvents = true; - - // Loop through the global sets and prune the UID from field layouts. - if (is_array($globalSets)) { - foreach ($globalSets as $globalSetUid => $globalSet) { - if (!empty($globalSet['fieldLayouts'])) { - foreach ($globalSet['fieldLayouts'] as $layoutUid => $layout) { - if (!empty($layout['tabs'])) { - foreach ($layout['tabs'] as $tabUid => $tab) { - $projectConfig->remove(ProjectConfig::PATH_GLOBAL_SETS . '.' . $globalSetUid . '.fieldLayouts.' . $layoutUid . '.tabs.' . $tabUid . '.fields.' . $fieldUid, 'Prune deleted field'); - } - } - } - } - } - } - - // Nuke all the layout fields from the DB - Db::delete(Table::FIELDLAYOUTFIELDS, [ - 'fieldId' => $field->id, - ]); - - // Allow events again - $projectConfig->muteEvents = false; } /** diff --git a/src/services/Sections.php b/src/services/Sections.php index 7f95fb6ae03..21fdb6ec5b4 100644 --- a/src/services/Sections.php +++ b/src/services/Sections.php @@ -18,7 +18,6 @@ use craft\events\ConfigEvent; use craft\events\DeleteSiteEvent; use craft\events\EntryTypeEvent; -use craft\events\FieldEvent; use craft\events\SectionEvent; use craft\helpers\ArrayHelper; use craft\helpers\Db; @@ -927,44 +926,10 @@ public function pruneDeletedSite(DeleteSiteEvent $event): void } /** - * Prune a deleted field from entry type layouts. - * - * @param FieldEvent $event - * @since 3.1.20 + * @deprecated in 4.0.5. Unused fields will be pruned automatically as field layouts are resaved. */ - public function pruneDeletedField(FieldEvent $event): void + public function pruneDeletedField(): void { - $field = $event->field; - $fieldUid = $field->uid; - - $projectConfig = Craft::$app->getProjectConfig(); - $entryTypes = $projectConfig->get(ProjectConfig::PATH_ENTRY_TYPES); - - // Engage stealth mode - $projectConfig->muteEvents = true; - - // Loop through the tag groups and prune the UID from field layouts. - if (is_array($entryTypes)) { - foreach ($entryTypes as $entryTypeUid => $entryType) { - if (!empty($entryType['fieldLayouts'])) { - foreach ($entryType['fieldLayouts'] as $layoutUid => $layout) { - if (!empty($layout['tabs'])) { - foreach ($layout['tabs'] as $tabUid => $tab) { - $projectConfig->remove(ProjectConfig::PATH_ENTRY_TYPES . '.' . $entryTypeUid . '.fieldLayouts.' . $layoutUid . '.tabs.' . $tabUid . '.fields.' . $fieldUid, 'Prune deleted field'); - } - } - } - } - } - } - - // Nuke all the layout fields from the DB - Db::delete(Table::FIELDLAYOUTFIELDS, [ - 'fieldId' => $field->id, - ]); - - // Allow events again - $projectConfig->muteEvents = false; } // Entry Types diff --git a/src/services/Tags.php b/src/services/Tags.php index 6d6dccbfb44..6aae626fcb0 100644 --- a/src/services/Tags.php +++ b/src/services/Tags.php @@ -13,7 +13,6 @@ use craft\elements\Tag; use craft\errors\TagGroupNotFoundException; use craft\events\ConfigEvent; -use craft\events\FieldEvent; use craft\events\TagGroupEvent; use craft\helpers\ArrayHelper; use craft\helpers\Db; @@ -406,43 +405,10 @@ public function handleDeletedTagGroup(ConfigEvent $event): void } /** - * Prune a deleted field from tag group layouts. - * - * @param FieldEvent $event + * @deprecated in 4.0.5. Unused fields will be pruned automatically as field layouts are resaved. */ - public function pruneDeletedField(FieldEvent $event): void + public function pruneDeletedField(): void { - $field = $event->field; - $fieldUid = $field->uid; - - $projectConfig = Craft::$app->getProjectConfig(); - $tagGroups = $projectConfig->get(ProjectConfig::PATH_TAG_GROUPS); - - // Engage stealth mode - $projectConfig->muteEvents = true; - - // Loop through the tag groups and prune the UID from field layouts. - if (is_array($tagGroups)) { - foreach ($tagGroups as $tagGroupUid => $tagGroup) { - if (!empty($tagGroup['fieldLayouts'])) { - foreach ($tagGroup['fieldLayouts'] as $layoutUid => $layout) { - if (!empty($layout['tabs'])) { - foreach ($layout['tabs'] as $tabUid => $tab) { - $projectConfig->remove(ProjectConfig::PATH_TAG_GROUPS . '.' . $tagGroupUid . '.fieldLayouts.' . $layoutUid . '.tabs.' . $tabUid . '.fields.' . $fieldUid, 'Prune deleted field'); - } - } - } - } - } - } - - // Nuke all the layout fields from the DB - Db::delete(Table::FIELDLAYOUTFIELDS, [ - 'fieldId' => $field->id, - ]); - - // Allow events again - $projectConfig->muteEvents = false; } // Tags diff --git a/src/services/Users.php b/src/services/Users.php index 4dc9b35927c..1bc0adb7d78 100644 --- a/src/services/Users.php +++ b/src/services/Users.php @@ -17,7 +17,6 @@ use craft\errors\UserNotFoundException; use craft\errors\VolumeException; use craft\events\ConfigEvent; -use craft\events\FieldEvent; use craft\events\UserAssignGroupEvent; use craft\events\UserEvent; use craft\events\UserGroupsAssignEvent; @@ -1411,39 +1410,10 @@ public function canSuspend(User $suspender, User $suspendee): bool } /** - * Prune a deleted field from user group layout. - * - * @param FieldEvent $event + * @deprecated in 4.0.5. Unused fields will be pruned automatically as field layouts are resaved. */ - public function pruneDeletedField(FieldEvent $event): void + public function pruneDeletedField(): void { - $field = $event->field; - $fieldUid = $field->uid; - - $projectConfig = Craft::$app->getProjectConfig(); - $fieldLayouts = $projectConfig->get(ProjectConfig::PATH_USER_FIELD_LAYOUTS); - - // Engage stealth mode - $projectConfig->muteEvents = true; - - // Prune the user field layout. - if (is_array($fieldLayouts)) { - foreach ($fieldLayouts as $layoutUid => $layout) { - if (!empty($layout['tabs'])) { - foreach ($layout['tabs'] as $tabUid => $tab) { - $projectConfig->remove(ProjectConfig::PATH_USER_FIELD_LAYOUTS . '.' . $layoutUid . '.tabs.' . $tabUid . '.fields.' . $fieldUid, 'Prune deleted field'); - } - } - } - } - - // Nuke all the layout fields from the DB - Db::delete(Table::FIELDLAYOUTFIELDS, [ - 'fieldId' => $field->id, - ]); - - // Allow events again - $projectConfig->muteEvents = false; } /** diff --git a/src/services/Volumes.php b/src/services/Volumes.php index 6dd65a56e1d..f9c788abd8c 100644 --- a/src/services/Volumes.php +++ b/src/services/Volumes.php @@ -14,7 +14,6 @@ use craft\db\Table; use craft\elements\Asset; use craft\events\ConfigEvent; -use craft\events\FieldEvent; use craft\events\VolumeEvent; use craft\fs\Temp; use craft\helpers\ArrayHelper; @@ -574,43 +573,10 @@ public function handleDeletedVolume(ConfigEvent $event): void } /** - * Prune a deleted field from volume layouts. - * - * @param FieldEvent $event + * @deprecated in 4.0.5. Unused fields will be pruned automatically as field layouts are resaved. */ - public function pruneDeletedField(FieldEvent $event): void + public function pruneDeletedField(): void { - $field = $event->field; - $fieldUid = $field->uid; - - $projectConfig = Craft::$app->getProjectConfig(); - $volumes = $projectConfig->get(ProjectConfig::PATH_VOLUMES); - - // Engage stealth mode - $projectConfig->muteEvents = true; - - // Loop through the volumes and prune the UID from field layouts. - if (is_array($volumes)) { - foreach ($volumes as $volumeUid => $volume) { - if (!empty($volume['fieldLayouts'])) { - foreach ($volume['fieldLayouts'] as $layoutUid => $layout) { - if (!empty($layout['tabs'])) { - foreach ($layout['tabs'] as $tabUid => $tab) { - $projectConfig->remove(ProjectConfig::PATH_VOLUMES . '.' . $volumeUid . '.fieldLayouts.' . $layoutUid . '.tabs.' . $tabUid . '.fields.' . $fieldUid, 'Prune deleted field'); - } - } - } - } - } - } - - // Nuke all the layout fields from the DB - Db::delete(Table::FIELDLAYOUTFIELDS, [ - 'fieldId' => $field->id, - ]); - - // Allow events again - $projectConfig->muteEvents = false; } /**