diff options
author | Zoltan Flamis <flamisz@gmail.com> | 2021-03-15 05:34:03 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-15 05:34:03 +0300 |
commit | 1a688e5ec4c4c96f7017b59bb2dbfac78c7c81d1 (patch) | |
tree | 83ce44b8b03f6bc98d2df0d00aadfd4e1f5ccd19 /plugins | |
parent | 069d2de9acb02bf337eb3d079e712a3071ee4f6d (diff) |
modify SegmentQueryDecorator so extra comment information can be saved (#17337)
* modify SegmentQueryDecorator so extra comment information can be saved
* Update LogAggregator.php
* fix tests
Diffstat (limited to 'plugins')
3 files changed, 16 insertions, 11 deletions
diff --git a/plugins/SegmentEditor/SegmentQueryDecorator.php b/plugins/SegmentEditor/SegmentQueryDecorator.php index e268c6febf..cbf4967b8f 100644 --- a/plugins/SegmentEditor/SegmentQueryDecorator.php +++ b/plugins/SegmentEditor/SegmentQueryDecorator.php @@ -50,8 +50,10 @@ class SegmentQueryDecorator extends LogQueryBuilder $prefixParts[] = "idSegments = [" . implode(', ', $idSegments) . "]"; } - if (!empty($prefixParts)) { - $result['sql'] = "/* " . implode(', ', $prefixParts) . " */\n" . $result['sql']; + $select = 'SELECT'; + if (!empty($prefixParts) && 0 === strpos(trim($result['sql']), $select)) { + $result['sql'] = trim($result['sql']); + $result['sql'] = 'SELECT /* ' . implode(', ', $prefixParts) . ' */' . substr($result['sql'], strlen($select)); } return $result; diff --git a/plugins/SegmentEditor/tests/Integration/SegmentQueryDecoratorTest.php b/plugins/SegmentEditor/tests/Integration/SegmentQueryDecoratorTest.php index 7cf0c46de3..7cc9158cd0 100644 --- a/plugins/SegmentEditor/tests/Integration/SegmentQueryDecoratorTest.php +++ b/plugins/SegmentEditor/tests/Integration/SegmentQueryDecoratorTest.php @@ -72,22 +72,23 @@ class SegmentQueryDecoratorTest extends IntegrationTestCase $this->assertStringStartsNotWith("/* idSegments", $sql); } else { $this->assertStringStartsWith($expectedPrefix, $sql); + $this->assertEquals(1, substr_count($sql, 'SELECT')); } } public function getTestDataForSegmentSqlTest() { return array( - array('countryCode==fr', null, '/* idSegments = [2] */'), - array('visitCount<2', null, '/* idSegments = [1, 3, 4, 5] */'), + array('countryCode==fr', null, 'SELECT /* idSegments = [2] */'), + array('visitCount<2', null, 'SELECT /* idSegments = [1, 3, 4, 5] */'), array('', null, null), - array('countryCode!=fr', null, '/* idSegments = [6] */'), + array('countryCode!=fr', null, 'SELECT /* idSegments = [6] */'), - array('', 'archivephp', '/* trigger = CronArchive */'), - array('countryCode!=fr', 'archivephp', '/* trigger = CronArchive, idSegments = [6] */'), + array('', 'archivephp', 'SELECT /* trigger = CronArchive */'), + array('countryCode!=fr', 'archivephp', 'SELECT /* trigger = CronArchive, idSegments = [6] */'), array('', 'garbage', null), - array('countryCode!=fr', 'garbage', '/* idSegments = [6] */'), + array('countryCode!=fr', 'garbage', 'SELECT /* idSegments = [6] */'), ); } -}
\ No newline at end of file +} diff --git a/plugins/SegmentEditor/tests/Unit/SegmentQueryDecoratorTest.php b/plugins/SegmentEditor/tests/Unit/SegmentQueryDecoratorTest.php index 1f7b6a29c1..593bac5bed 100644 --- a/plugins/SegmentEditor/tests/Unit/SegmentQueryDecoratorTest.php +++ b/plugins/SegmentEditor/tests/Unit/SegmentQueryDecoratorTest.php @@ -68,7 +68,8 @@ class SegmentQueryDecoratorTest extends \PHPUnit\Framework\TestCase $query = $this->decorator->getSelectQueryString($expression, '*', 'log_visit', '', array(), '', '', ''); - $this->assertStringStartsWith('/* idSegments = [3] */', $query['sql']); + $this->assertStringStartsWith('SELECT /* idSegments = [3] */', $query['sql']); + $this->assertEquals(1, substr_count($query['sql'], 'SELECT')); } public function test_getSelectQueryString_DecoratesSql_WhenMultipleStoredSegmentsMatchUsedSegment() @@ -78,7 +79,8 @@ class SegmentQueryDecoratorTest extends \PHPUnit\Framework\TestCase $query = $this->decorator->getSelectQueryString($expression, '*', 'log_visit', '', array(), '', '', ''); - $this->assertStringStartsWith('/* idSegments = [2, 4] */', $query['sql']); + $this->assertStringStartsWith('SELECT /* idSegments = [2, 4] */', $query['sql']); + $this->assertEquals(1, substr_count($query['sql'], 'SELECT')); } private function getMockSegmentEditorService() |