Skip to content

Commit

Permalink
Fixed v5 migration bug
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed May 24, 2024
1 parent 2ebe09f commit c2f58dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes for Craft CMS 5

## Unreleased

- Fixed an error that occurred when upgrading to Craft 5 if a Matrix block type didn’t have any fields.

## 5.1.6 - 2024-05-23

- Added `craft\services\Fields::getRelationalFieldTypes()`.
Expand Down
4 changes: 3 additions & 1 deletion src/migrations/m230511_215903_content_refactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ public function safeUp(): bool
throw new Exception("Matrix block type $blockTypeUid is out of sync.");
}
$blockTypeDatum = $blockTypeData[$blockTypeUid];
$fieldLayout = $fieldsService->getLayoutById($blockTypeDatum['fieldLayoutId']);
$fieldLayout = $blockTypeDatum['fieldLayoutId']
? $fieldsService->getLayoutById($blockTypeDatum['fieldLayoutId'])
: null;
$this->updateElements(
(new Query())->from('{{%matrixblocks}}')->where(['typeId' => $blockTypeDatum['id']]),
$fieldLayout,
Expand Down

0 comments on commit c2f58dc

Please sign in to comment.