Skip to content

Commit 0e74c02

Browse files
committed
Fixed structure issues when
Workaround for creocoder/yii2-nested-sets#114 Fixes #3456
1 parent 72a4f23 commit 0e74c02

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

CHANGELOG-v3.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
- Updated Twig to 2.12.
1212

1313
### Fixed
14+
- Fixed a SQL error that could occur when deleting an entry or category with three or more nested levels of elements. ([#3456](https://github.com/craftcms/cms/issues/3456))
15+
- Fixed a bug where deleting an entry or category with nested elements could leave the structure in a jumbled state.
1416
- Fixed a bug where the `resave/matrix-blocks` command would wittingly resave Matrix blocks even if they hadn’t been loaded with their content, resulting in lost content. ([#5030](https://github.com/craftcms/cms/issues/5030))
1517

1618
## 3.3.7 - 2019-10-03

src/services/Elements.php

+4-11
Original file line numberDiff line numberDiff line change
@@ -1158,20 +1158,13 @@ public function deleteElement(ElementInterface $element, bool $hardDelete = fals
11581158
$transaction = $db->beginTransaction();
11591159
try {
11601160
// First delete any structure nodes with this element, so NestedSetBehavior can do its thing.
1161-
/** @var StructureElementRecord[] $records */
1162-
$records = StructureElementRecord::findAll([
1163-
'elementId' => $element->id
1164-
]);
1165-
1166-
foreach ($records as $record) {
1161+
while (($record = StructureElementRecord::findOne(['elementId' => $element->id])) !== null) {
11671162
// If this element still has any children, move them up before the one getting deleted.
1168-
/** @var StructureElementRecord[] $children */
1169-
$children = $record->children()->all();
1170-
1171-
foreach ($children as $child) {
1163+
while (($child = $record->children(1)->one()) !== null) {
11721164
$child->insertBefore($record);
1165+
// Re-fetch the record since its lft and rgt attributes just changed
1166+
$record = StructureElementRecord::findOne($record->id);
11731167
}
1174-
11751168
// Delete this element's node
11761169
$record->deleteWithChildren();
11771170
}

0 commit comments

Comments
 (0)