Skip to content

Commit

Permalink
Don't join in structure elements that belong to soft-deleted structures
Browse files Browse the repository at this point in the history
Fixes #4066
  • Loading branch information
brandonkelly committed Mar 28, 2019
1 parent e744f2b commit bcda737
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Fixed
- Fixed a bug where the Asset Indexes utility wasn’t logging exceptions.
- Fixed a SQL error that could occur when using the Asset Indexes utility, if any filenames contained 4+ byte characters.
- Fixed a bug where entry queries could return duplicate results for any entries that belong to a section that has soft-deleted structures associated with it. ([#4066](https://github.com/craftcms/cms/issues/4066))

## 3.1.20.1 - 2019-03-27

Expand Down
19 changes: 17 additions & 2 deletions src/elements/db/ElementQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -1785,9 +1785,24 @@ private function _applyStructureParams(string $class)
} else {
$this->query
->addSelect(['structureelements.structureId'])
->leftJoin('{{%structureelements}} structureelements', '[[structureelements.elementId]] = [[subquery.elementsId]]');
->leftJoin('{{%structureelements}} structureelements', [
'and',
'[[structureelements.elementId]] = [[subquery.elementsId]]',
'[[structureelements.structureId]] = [[subquery.structureId]]',
]);
$this->subQuery
->leftJoin('{{%structureelements}} structureelements', '[[structureelements.elementId]] = [[elements.id]]');
->addSelect(['structureelements.structureId'])
->leftJoin('{{%structureelements}} structureelements', [
'and',
'[[structureelements.elementId]] = [[elements.id]]',
[
'exists',
(new Query())
->from([Table::STRUCTURES])
->where('[[id]] = [[structureelements.structureId]]')
->andWhere(['dateDeleted' => null])
],
]);
}

if ($this->hasDescendants !== null) {
Expand Down

0 comments on commit bcda737

Please sign in to comment.