diff --git a/core/Segment.php b/core/Segment.php index eafe24419c1..445cc7be732 100644 --- a/core/Segment.php +++ b/core/Segment.php @@ -387,9 +387,13 @@ protected function getCleanedExpression(array $expression): array $matchType = $expression[SegmentExpression::INDEX_OPERAND_OPERATOR]; $value = $expression[SegmentExpression::INDEX_OPERAND_VALUE]; - $segmentsList = Context::changeIdSite(implode(',', $this->idSites ?: []), function () { - return SegmentsList::get(); - }); + if (empty($this->idSites)) { + $segmentsList = SegmentsList::get(); + } else { + $segmentsList = Context::changeIdSite(implode(',', $this->idSites), function () { + return SegmentsList::get(); + }); + } $segmentObject = $segmentsList->getSegment($name); $sqlName = $segmentObject ? $segmentObject->getSqlSegment() : null; diff --git a/tests/PHPUnit/Integration/SegmentTest.php b/tests/PHPUnit/Integration/SegmentTest.php index 31808792c86..c7ab4d73fcb 100644 --- a/tests/PHPUnit/Integration/SegmentTest.php +++ b/tests/PHPUnit/Integration/SegmentTest.php @@ -182,8 +182,8 @@ public function getCommonSubqueryTestData(): iterable $segmentFrom = '2020-02-02 02:00:00'; $whereSingle = '(log_visit.idvisit NOT IN(SELECT log_visit.idvisit FROM log_visit AS log_visit LEFT JOIN log_link_visit_action AS log_link_visit_action ON log_link_visit_action.idvisit = log_visit.idvisit WHERE(log_visit.visit_last_action_time >= ?)AND(log_link_visit_action.idaction_name = ?)))'; - $whereMultiAnd = '(log_visit.idvisit NOT IN(SELECT log_visit.idvisit FROM log_visit AS log_visit LEFT JOIN log_link_visit_action AS log_link_visit_action ON log_link_visit_action.idvisit = log_visit.idvisit WHERE(log_visit.visit_last_action_time >= ?)AND(log_link_visit_action.idaction_name = ?)))AND(log_visit.idvisit NOT IN(SELECT log_visit.idvisit FROM log_visit AS log_visit LEFT JOIN log_link_visit_action AS log_link_visit_action ON log_link_visit_action.idvisit = log_visit.idvisit WHERE(log_visit.visit_last_action_time >= ?)AND(log_link_visit_action.idaction_name = ?)))'; - $whereMultiOr = '((log_visit.idvisit NOT IN(SELECT log_visit.idvisit FROM log_visit AS log_visit LEFT JOIN log_link_visit_action AS log_link_visit_action ON log_link_visit_action.idvisit = log_visit.idvisit WHERE(log_visit.visit_last_action_time >= ?)AND(log_link_visit_action.idaction_name = ?)))OR(log_visit.idvisit NOT IN(SELECT log_visit.idvisit FROM log_visit AS log_visit LEFT JOIN log_link_visit_action AS log_link_visit_action ON log_link_visit_action.idvisit = log_visit.idvisit WHERE(log_visit.visit_last_action_time >= ?)AND(log_link_visit_action.idaction_name = ?))))'; + $whereMultiAnd = '(log_visit.idvisit NOT IN(SELECT log_visit.idvisit FROM log_visit AS log_visit LEFT JOIN log_link_visit_action AS log_link_visit_action ON log_link_visit_action.idvisit = log_visit.idvisit WHERE(log_visit.visit_last_action_time >= ?)AND((log_link_visit_action.idaction_name = ? OR log_link_visit_action.idaction_name = ?))))'; + $whereMultiOr = '(log_visit.idvisit NOT IN(SELECT log_visit.idvisit FROM log_visit AS log_visit LEFT JOIN log_link_visit_action AS log_link_visit_action ON log_link_visit_action.idvisit = log_visit.idvisit WHERE(log_visit.visit_last_action_time >= ?)AND(log_link_visit_action.idaction_name = ? AND log_link_visit_action.idaction_name = ?)))'; yield 'normal segment' => [ 'pageTitle!=a', @@ -235,7 +235,7 @@ public function getCommonSubqueryTestData(): iterable $segmentFrom, [ 'where' => $whereMultiAnd, - 'bind' => [$segmentFrom, '1', $segmentFrom, '2'], + 'bind' => [$segmentFrom, '1', '2'], ], ]; @@ -244,7 +244,7 @@ public function getCommonSubqueryTestData(): iterable $segmentFrom, [ 'where' => $whereMultiOr, - 'bind' => [$segmentFrom, '1', $segmentFrom, '2'], + 'bind' => [$segmentFrom, '1', '2'], ], ]; @@ -253,7 +253,7 @@ public function getCommonSubqueryTestData(): iterable $segmentFrom, [ 'where' => $whereMultiAnd, - 'bind' => [$segmentFrom, '3', $segmentFrom, '4'], + 'bind' => [$segmentFrom, '3', '4'], ], ]; @@ -262,7 +262,7 @@ public function getCommonSubqueryTestData(): iterable $segmentFrom, [ 'where' => $whereMultiOr, - 'bind' => [$segmentFrom, '3', $segmentFrom, '4'], + 'bind' => [$segmentFrom, '3', '4'], ], ]; }