From 0ae3856d741397c0438904c74e389d1bbf9cf826 Mon Sep 17 00:00:00 2001 From: Iwona Just Date: Fri, 20 Sep 2024 16:29:33 +0100 Subject: [PATCH] adjust hasAlt condition --- src/elements/db/AssetQuery.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/elements/db/AssetQuery.php b/src/elements/db/AssetQuery.php index 9c7e926eef4..dc783d67c01 100644 --- a/src/elements/db/AssetQuery.php +++ b/src/elements/db/AssetQuery.php @@ -994,8 +994,28 @@ protected function afterPrepare(): bool if ($this->hasAlt !== null) { $hasAltCondition = [ 'or', - ['assets.alt' => null], - ['assets_sites.alt' => null], + ['not', ['assets_sites.alt' => '']], + [ + 'and', + ['assets_sites.alt' => null], + ['not', ['assets.alt' => '']], + ['not', ['assets.alt' => null]], + ], + ]; + + $withoutAltCondition = [ + 'or', + ['assets_sites.alt' => ''], + [ + 'and', + ['assets_sites.alt' => null], + [ + 'or', + ['assets.alt' => ''], + ['assets.alt' => null], + ], + + ], ]; $this->subQuery @@ -1004,7 +1024,7 @@ protected function afterPrepare(): bool '[[assets_sites.assetId]] = [[assets.id]]', '[[assets_sites.siteId]] = [[elements_sites.siteId]]', ]) - ->andWhere($this->hasAlt ? ['not', $hasAltCondition] : $hasAltCondition); + ->andWhere($this->hasAlt ? $hasAltCondition : $withoutAltCondition); } return parent::afterPrepare();