Skip to content

Commit

Permalink
Revert "Resave entries after adding/removing fields from field layouts"
Browse files Browse the repository at this point in the history
This reverts a portion of commit 42bcdfc.

(#3482 (comment))
  • Loading branch information
brandonkelly authored and angrybrad committed May 6, 2019
1 parent c151f8f commit 991d794
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 20 deletions.
1 change: 0 additions & 1 deletion CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

### Fixed
- Fixed an error where re-saving a site would reset its sorting order. ([#4147](https://github.com/craftcms/cms/issues/4147))
- Fixed a bug where Craft wasn’t auto-resaving entries after a field was added or removed from an entry type. ([#3482](https://github.com/craftcms/cms/issues/3482))
- Fixed a SQL error that could occur when updating to Craft 3.1. ([#3663](https://github.com/craftcms/cms/issues/3663))
- Fixed an error that occurred when an SVG with `/` characters in its `id` attributes was passed to the `svg()` Twig function. ([#4155](https://github.com/craftcms/cms/issues/4155))
- Fixed a bug where passing `:empty:` or `:notempty:` to a Matrix field param on an element query could return incorrect results for fields that had soft-deleted blocks. ([#4161](https://github.com/craftcms/cms/issues/4161))
Expand Down
22 changes: 3 additions & 19 deletions src/services/Sections.php
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,6 @@ public function handleChangedEntryType(ConfigEvent $event)
return;
}

$fieldsService = Craft::$app->getFields();
$transaction = Craft::$app->getDb()->beginTransaction();

try {
Expand All @@ -1205,36 +1204,21 @@ public function handleChangedEntryType(ConfigEvent $event)
$entryTypeRecord->sectionId = $section->id;
$entryTypeRecord->uid = $entryTypeUid;

$resaveEntries = false;

if (!empty($data['fieldLayouts'])) {
// Get the old field IDs
$oldFieldIds = $entryTypeRecord->fieldLayoutId
? $fieldsService->getFieldIdsByLayoutId($entryTypeRecord->fieldLayoutId)
: [];
sort($oldFieldIds, SORT_NUMERIC);

// Save the field layout
$layout = FieldLayout::createFromConfig(reset($data['fieldLayouts']));
$layout->id = $entryTypeRecord->fieldLayoutId;
$layout->type = Entry::class;
$layout->uid = key($data['fieldLayouts']);
$fieldsService->saveLayout($layout);
Craft::$app->getFields()->saveLayout($layout);
$entryTypeRecord->fieldLayoutId = $layout->id;

// See if any field changes were just made
$newFieldIds = $fieldsService->getFieldIdsByLayoutId($layout->id);
sort($newFieldIds, SORT_NUMERIC);
if ($newFieldIds !== $oldFieldIds) {
$resaveEntries = true;
}
} else if ($entryTypeRecord->fieldLayoutId) {
// Delete the field layout
$fieldsService->deleteLayoutById($entryTypeRecord->fieldLayoutId);
Craft::$app->getFields()->deleteLayoutById($entryTypeRecord->fieldLayoutId);
$entryTypeRecord->fieldLayoutId = null;
}

$resaveEntries = $resaveEntries || (
$resaveEntries = (
$entryTypeRecord->handle !== $entryTypeRecord->getOldAttribute('handle') ||
$entryTypeRecord->hasTitleField != $entryTypeRecord->getOldAttribute('hasTitleField') ||
$entryTypeRecord->titleFormat !== $entryTypeRecord->getOldAttribute('titleFormat') ||
Expand Down

0 comments on commit 991d794

Please sign in to comment.