From dc6be01e23097595002dee696bf4722a63071804 Mon Sep 17 00:00:00 2001 From: ObitoTM Date: Tue, 26 May 2026 16:45:47 +0300 Subject: [PATCH] FIX: Inherit view for nested query conditions https://github.com/Crocoblock/issues-tracker/issues/18126 --- .../db-queries/query-conditions-builder.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/includes/db-queries/query-conditions-builder.php b/includes/db-queries/query-conditions-builder.php index 35dd4c553..9248a7064 100644 --- a/includes/db-queries/query-conditions-builder.php +++ b/includes/db-queries/query-conditions-builder.php @@ -51,6 +51,7 @@ class Query_Conditions_Builder { private $conditions = array(); private $relation_type = 'AND'; + private $inherit_view_only = false; /** * @var array @@ -138,6 +139,10 @@ public function set_conditions( array $conditions ): Query_Conditions_Builder { } public function after_set_view() { + if ( $this->inherit_view_only ) { + return; + } + try { $view = $this->view(); } catch ( Query_Builder_Exception $exception ) { @@ -147,6 +152,18 @@ public function after_set_view() { $this->set_conditions( $view->conditions() ); } + private function inherit_view( Views\View_Base $view ): Query_Conditions_Builder { + if ( $this->view ) { + return $this; + } + + $this->inherit_view_only = true; + $this->set_view( $view ); + $this->inherit_view_only = false; + + return $this; + } + /** * @return string */ @@ -182,6 +199,10 @@ public function prepare() { $condition = $this->generator->current(); if ( $condition instanceof Query_Conditions_Builder ) { + if ( $this->view ) { + $condition->inherit_view( $this->view ); + } + return sprintf( "(\r\n%s\r\n)", $condition->prepare_conditions() ); }