From 85c58f3b76cc8b33cbbba42393b3e99f2d017baf Mon Sep 17 00:00:00 2001 From: Vidar Langseid Date: Tue, 9 Jan 2024 13:17:36 +0100 Subject: [PATCH 1/9] IBX-7172: loadLocationChildren() not working with multiple objectstate permissions --- .../Content/ObjectStateIdQueryBuilder.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/eZ/Publish/Core/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/ObjectStateIdQueryBuilder.php b/eZ/Publish/Core/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/ObjectStateIdQueryBuilder.php index fcb0f5821d..929b5236b2 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/ObjectStateIdQueryBuilder.php +++ b/eZ/Publish/Core/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/ObjectStateIdQueryBuilder.php @@ -29,19 +29,23 @@ public function buildQueryConstraint( FilteringQueryBuilder $queryBuilder, FilteringCriterion $criterion ): ?string { + static $counter = 1; + $tableAlias = 'object_state_link_' . $counter; + ++$counter; + /** @var \eZ\Publish\API\Repository\Values\Content\Query\Criterion\ObjectStateId $criterion */ $queryBuilder ->joinOnce( 'content', Gateway::OBJECT_STATE_LINK_TABLE, - 'object_state_link', - 'content.id = object_state_link.contentobject_id', + $tableAlias, + 'content.id = ' . $tableAlias . '.contentobject_id', ); $value = (array)$criterion->value; return $queryBuilder->expr()->in( - 'object_state_link.contentobject_state_id', + $tableAlias . '.contentobject_state_id', $queryBuilder->createNamedParameter($value, Connection::PARAM_INT_ARRAY) ); } From 3271b673ddf01a2bd8d2fc06c8f4271d8235485f Mon Sep 17 00:00:00 2001 From: Vidar Langseid Date: Fri, 12 Jan 2024 12:21:09 +0100 Subject: [PATCH 2/9] fixup! IBX-7172: loadLocationChildren() not working with multiple objectstate permissions --- .../Tests/Filtering/ContentFilteringTest.php | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/eZ/Publish/API/Repository/Tests/Filtering/ContentFilteringTest.php b/eZ/Publish/API/Repository/Tests/Filtering/ContentFilteringTest.php index 2bcfe4b361..e3671c799d 100644 --- a/eZ/Publish/API/Repository/Tests/Filtering/ContentFilteringTest.php +++ b/eZ/Publish/API/Repository/Tests/Filtering/ContentFilteringTest.php @@ -12,11 +12,14 @@ use function count; use eZ\Publish\API\Repository\Values\Content\Content; use eZ\Publish\API\Repository\Values\Content\ContentList; +use eZ\Publish\API\Repository\Values\Content\Location; use eZ\Publish\API\Repository\Values\Content\Query; use eZ\Publish\API\Repository\Values\Content\Query\Criterion; use eZ\Publish\API\Repository\Values\Content\Query\SortClause; use eZ\Publish\API\Repository\Values\Content\Search\SearchHit; use eZ\Publish\API\Repository\Values\Filter\Filter; +use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateCreateStruct; +use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroupCreateStruct; use eZ\Publish\Core\FieldType\Keyword; use eZ\Publish\SPI\Repository\Values\Filter\FilteringSortClause; use IteratorAggregate; @@ -27,6 +30,13 @@ */ final class ContentFilteringTest extends BaseRepositoryFilteringTestCase { + protected function setUp(): void + { + parent::setUp(); + $this->getSetupFactory()->getRepository(true); + $this->contentProvider = new TestContentProvider($this->getRepository(true), $this); + } + /** * Test that special cases of Location Sort Clauses are working correctly. * @@ -332,6 +342,64 @@ private function performAndAssertSimpleSortClauseQuery(FilteringSortClause $sort self::assertSame(57, $contentList->getIterator()[0]->id); } + public function testObjectStateIdCriterionOnMultipleObjectStates(): void + { + $contentService = $this->getRepository()->getContentService(); + $contentTypeService = $this->getRepository()->getContentTypeService(); + $locationService = $this->getRepository()->getLocationService(); + $objectStateService = $this->getRepository()->getObjectStateService(); + + // Create additional Object States + $objectStateGroupStruct = new ObjectStateGroupCreateStruct(); + $objectStateGroupStruct->identifier = 'domain'; + $objectStateGroupStruct->names = ['eng-GB' => 'Domain']; + $objectStateGroupStruct->defaultLanguageCode = 'eng-GB'; + $objectStateGroup = $objectStateService->createObjectStateGroup($objectStateGroupStruct); + + $objectStateCreateStruct = new ObjectStateCreateStruct(); + $objectStateCreateStruct->identifier = 'public'; + $objectStateCreateStruct->names = ['eng-GB' => 'Public']; + $objectStateCreateStruct->defaultLanguageCode = 'eng-GB'; + $objectStatePublic = $objectStateService->createObjectState($objectStateGroup, $objectStateCreateStruct); + + $objectStateCreateStruct->identifier = 'private'; + $objectStateCreateStruct->names = ['eng-GB' => 'Private']; + $objectStatePrivate = $objectStateService->createObjectState($objectStateGroup, $objectStateCreateStruct); + + // Create a new content object and assign object state "Private" to it: + $contentCreate = $contentService->newContentCreateStruct( + $contentTypeService->loadContentTypeByIdentifier('folder'), + 'eng-GB' + ); + $contentCreate->setField('name', 'Private Folder'); + $content = $contentService->createContent( + $contentCreate, + [$locationService->newLocationCreateStruct(2)] + ); + $contentService->publishVersion( + $content->getVersionInfo() + ); + $objectStateService->setContentState($content->contentInfo, $objectStateGroup, $objectStatePrivate); + + $filter = new Filter(); + $filter + ->withCriterion(new Criterion\LogicalAnd([ + new Criterion\ParentLocationId(2), + new Criterion\LogicalAnd([ + new Criterion\ObjectStateId(1), + new Criterion\ObjectStateId(4), + ]), + ])); + + $results = $this->find($filter); + + self::assertEquals(1, $results->getTotalCount(), 'Expected to find only one object which has state "not_locked" and "private"'); + /** @var \eZ\Publish\API\Repository\Values\Content\Location $result */ + foreach ($results as $result) { + self::assertEquals($result->id, $content->id, 'Expected to find "Private Folder"'); + } + } + public function getListOfSupportedSortClauses(): iterable { yield 'Content\\Id' => [SortClause\ContentId::class]; From 03b685d698431c6c883e63e877f8b3869a7cdda3 Mon Sep 17 00:00:00 2001 From: Vidar Date: Mon, 15 Jan 2024 16:07:09 +0100 Subject: [PATCH 3/9] Update eZ/Publish/Core/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/ObjectStateIdQueryBuilder.php Co-authored-by: Andrew Longosz --- .../Content/ObjectStateIdQueryBuilder.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/eZ/Publish/Core/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/ObjectStateIdQueryBuilder.php b/eZ/Publish/Core/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/ObjectStateIdQueryBuilder.php index 929b5236b2..136c8ed917 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/ObjectStateIdQueryBuilder.php +++ b/eZ/Publish/Core/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/ObjectStateIdQueryBuilder.php @@ -29,9 +29,7 @@ public function buildQueryConstraint( FilteringQueryBuilder $queryBuilder, FilteringCriterion $criterion ): ?string { - static $counter = 1; - $tableAlias = 'object_state_link_' . $counter; - ++$counter; + $tableAlias = uniqid('osl_'); /** @var \eZ\Publish\API\Repository\Values\Content\Query\Criterion\ObjectStateId $criterion */ $queryBuilder From 9df086897b803e8f538b5d4c83b494d8cb985089 Mon Sep 17 00:00:00 2001 From: Vidar Langseid Date: Tue, 16 Jan 2024 12:43:29 +0100 Subject: [PATCH 4/9] fixup! IBX-7172: loadLocationChildren() not working with multiple objectstate permissions --- .../Tests/Filtering/ContentFilteringTest.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/eZ/Publish/API/Repository/Tests/Filtering/ContentFilteringTest.php b/eZ/Publish/API/Repository/Tests/Filtering/ContentFilteringTest.php index e3671c799d..1361ddb406 100644 --- a/eZ/Publish/API/Repository/Tests/Filtering/ContentFilteringTest.php +++ b/eZ/Publish/API/Repository/Tests/Filtering/ContentFilteringTest.php @@ -32,9 +32,9 @@ final class ContentFilteringTest extends BaseRepositoryFilteringTestCase { protected function setUp(): void { - parent::setUp(); $this->getSetupFactory()->getRepository(true); $this->contentProvider = new TestContentProvider($this->getRepository(true), $this); + parent::setUp(); } /** @@ -360,7 +360,7 @@ public function testObjectStateIdCriterionOnMultipleObjectStates(): void $objectStateCreateStruct->identifier = 'public'; $objectStateCreateStruct->names = ['eng-GB' => 'Public']; $objectStateCreateStruct->defaultLanguageCode = 'eng-GB'; - $objectStatePublic = $objectStateService->createObjectState($objectStateGroup, $objectStateCreateStruct); + $objectStateService->createObjectState($objectStateGroup, $objectStateCreateStruct); $objectStateCreateStruct->identifier = 'private'; $objectStateCreateStruct->names = ['eng-GB' => 'Private']; @@ -393,7 +393,12 @@ public function testObjectStateIdCriterionOnMultipleObjectStates(): void $results = $this->find($filter); - self::assertEquals(1, $results->getTotalCount(), 'Expected to find only one object which has state "not_locked" and "private"'); + self::assertEquals( + 1, + $results->getTotalCount(), + 'Expected to find only one object which has state "not_locked" and "private"' + ); + /** @var \eZ\Publish\API\Repository\Values\Content\Location $result */ foreach ($results as $result) { self::assertEquals($result->id, $content->id, 'Expected to find "Private Folder"'); From 57fcf5b79f1a1ee7e45d8b6858a0f6546c0a94f2 Mon Sep 17 00:00:00 2001 From: Vidar Langseid Date: Tue, 16 Jan 2024 13:47:01 +0100 Subject: [PATCH 5/9] fixup! IBX-7172: loadLocationChildren() not working with multiple objectstate permissions --- .../API/Repository/Tests/Filtering/ContentFilteringTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/eZ/Publish/API/Repository/Tests/Filtering/ContentFilteringTest.php b/eZ/Publish/API/Repository/Tests/Filtering/ContentFilteringTest.php index 1361ddb406..cfd480061f 100644 --- a/eZ/Publish/API/Repository/Tests/Filtering/ContentFilteringTest.php +++ b/eZ/Publish/API/Repository/Tests/Filtering/ContentFilteringTest.php @@ -32,8 +32,6 @@ final class ContentFilteringTest extends BaseRepositoryFilteringTestCase { protected function setUp(): void { - $this->getSetupFactory()->getRepository(true); - $this->contentProvider = new TestContentProvider($this->getRepository(true), $this); parent::setUp(); } @@ -387,7 +385,7 @@ public function testObjectStateIdCriterionOnMultipleObjectStates(): void new Criterion\ParentLocationId(2), new Criterion\LogicalAnd([ new Criterion\ObjectStateId(1), - new Criterion\ObjectStateId(4), + new Criterion\ObjectStateId($objectStatePrivate->id), ]), ])); From b3cf69662294f021feeec1f6911d18157f764f67 Mon Sep 17 00:00:00 2001 From: Vidar Date: Tue, 13 Feb 2024 15:07:04 +0100 Subject: [PATCH 6/9] Update eZ/Publish/API/Repository/Tests/Filtering/ContentFilteringTest.php Co-authored-by: Andrew Longosz --- .../API/Repository/Tests/Filtering/ContentFilteringTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/eZ/Publish/API/Repository/Tests/Filtering/ContentFilteringTest.php b/eZ/Publish/API/Repository/Tests/Filtering/ContentFilteringTest.php index cfd480061f..2c36b73ce3 100644 --- a/eZ/Publish/API/Repository/Tests/Filtering/ContentFilteringTest.php +++ b/eZ/Publish/API/Repository/Tests/Filtering/ContentFilteringTest.php @@ -340,6 +340,9 @@ private function performAndAssertSimpleSortClauseQuery(FilteringSortClause $sort self::assertSame(57, $contentList->getIterator()[0]->id); } + /** + * @throws \eZ\Publish\API\Repository\Exceptions\Exception + */ public function testObjectStateIdCriterionOnMultipleObjectStates(): void { $contentService = $this->getRepository()->getContentService(); From b83916cb363199872ff6fed6bdaec621bda0d01b Mon Sep 17 00:00:00 2001 From: Vidar Date: Tue, 13 Feb 2024 15:09:47 +0100 Subject: [PATCH 7/9] Apply suggestions from code review Co-authored-by: Andrew Longosz --- .../Repository/Tests/Filtering/ContentFilteringTest.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/eZ/Publish/API/Repository/Tests/Filtering/ContentFilteringTest.php b/eZ/Publish/API/Repository/Tests/Filtering/ContentFilteringTest.php index 2c36b73ce3..e550cf30c6 100644 --- a/eZ/Publish/API/Repository/Tests/Filtering/ContentFilteringTest.php +++ b/eZ/Publish/API/Repository/Tests/Filtering/ContentFilteringTest.php @@ -380,7 +380,11 @@ public function testObjectStateIdCriterionOnMultipleObjectStates(): void $contentService->publishVersion( $content->getVersionInfo() ); - $objectStateService->setContentState($content->contentInfo, $objectStateGroup, $objectStatePrivate); + $objectStateService->setContentState( + $content->getVersionInfo()->getContentInfo(), + $objectStateGroup, + $objectStatePrivate + ); $filter = new Filter(); $filter @@ -400,7 +404,6 @@ public function testObjectStateIdCriterionOnMultipleObjectStates(): void 'Expected to find only one object which has state "not_locked" and "private"' ); - /** @var \eZ\Publish\API\Repository\Values\Content\Location $result */ foreach ($results as $result) { self::assertEquals($result->id, $content->id, 'Expected to find "Private Folder"'); } From c205b0b68ba6f00bad207decad35de673eaafcc3 Mon Sep 17 00:00:00 2001 From: Vidar Langseid Date: Tue, 13 Feb 2024 15:11:37 +0100 Subject: [PATCH 8/9] fixup! fixup! IBX-7172: loadLocationChildren() not working with multiple objectstate permissions --- .../API/Repository/Tests/Filtering/ContentFilteringTest.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/eZ/Publish/API/Repository/Tests/Filtering/ContentFilteringTest.php b/eZ/Publish/API/Repository/Tests/Filtering/ContentFilteringTest.php index e550cf30c6..36d4b3a015 100644 --- a/eZ/Publish/API/Repository/Tests/Filtering/ContentFilteringTest.php +++ b/eZ/Publish/API/Repository/Tests/Filtering/ContentFilteringTest.php @@ -30,11 +30,6 @@ */ final class ContentFilteringTest extends BaseRepositoryFilteringTestCase { - protected function setUp(): void - { - parent::setUp(); - } - /** * Test that special cases of Location Sort Clauses are working correctly. * From c0dfbad8648fc650417cdc5457aa23f80b5f5246 Mon Sep 17 00:00:00 2001 From: Vidar Langseid Date: Wed, 14 Feb 2024 18:47:54 +0100 Subject: [PATCH 9/9] fixup! fixup! fixup! IBX-7172: loadLocationChildren() not working with multiple objectstate permissions --- .../CriterionQueryBuilder/Content/ObjectStateIdQueryBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eZ/Publish/Core/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/ObjectStateIdQueryBuilder.php b/eZ/Publish/Core/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/ObjectStateIdQueryBuilder.php index 136c8ed917..a189f42847 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/ObjectStateIdQueryBuilder.php +++ b/eZ/Publish/Core/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/ObjectStateIdQueryBuilder.php @@ -33,7 +33,7 @@ public function buildQueryConstraint( /** @var \eZ\Publish\API\Repository\Values\Content\Query\Criterion\ObjectStateId $criterion */ $queryBuilder - ->joinOnce( + ->join( 'content', Gateway::OBJECT_STATE_LINK_TABLE, $tableAlias,