Skip to content

Commit 9fef2a0

Browse files
committed
Merge branch '4.6' into main
2 parents a5c22fe + 9775a9b commit 9fef2a0

6 files changed

Lines changed: 87 additions & 70 deletions

File tree

phpstan-baseline.neon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46299,13 +46299,13 @@ parameters:
4629946299
-
4630046300
message: '#^Parameter \#1 \$originalClassName of method PHPUnit\\Framework\\TestCase\:\:createMock\(\) expects class\-string\<mixed\>, string given\.$#'
4630146301
identifier: argument.type
46302-
count: 4
46302+
count: 3
4630346303
path: tests/lib/Persistence/Cache/TrashHandlerTest.php
4630446304

4630546305
-
4630646306
message: '#^Unable to resolve the template type T in call to method PHPUnit\\Framework\\TestCase\:\:createMock\(\)$#'
4630746307
identifier: argument.templateType
46308-
count: 4
46308+
count: 3
4630946309
path: tests/lib/Persistence/Cache/TrashHandlerTest.php
4631046310

4631146311
-

src/bundle/Core/Resources/config/services.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,3 +371,4 @@ services:
371371
decoration_priority: 500
372372
arguments:
373373
$inner: '@.inner'
374+

src/lib/Persistence/Cache/TrashHandler.php

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99

1010
use Ibexa\Contracts\Core\Persistence\Content\Location\Trash\Handler as TrashHandlerInterface;
1111
use Ibexa\Contracts\Core\Persistence\Content\Relation;
12+
use Ibexa\Contracts\Core\Persistence\User\RoleAssignment;
1213
use Ibexa\Contracts\Core\Repository\Values\Content\Query\CriterionInterface;
1314

1415
class TrashHandler extends AbstractHandler implements TrashHandlerInterface
1516
{
1617
private const EMPTY_TRASH_BULK_SIZE = 100;
1718
private const CONTENT_IDENTIFIER = 'content';
1819
private const LOCATION_PATH_IDENTIFIER = 'location_path';
20+
private const ROLE_ASSIGNMENT_ROLE_LIST_IDENTIFIER = 'role_assignment_role_list';
1921

2022
/**
2123
* {@inheritdoc}
@@ -34,13 +36,14 @@ public function trashSubtree($locationId)
3436
{
3537
$this->logger->logCall(__METHOD__, ['locationId' => $locationId]);
3638

37-
$location = $this->persistenceHandler->locationHandler()->load($locationId);
39+
$contentId = $this->persistenceHandler->locationHandler()->load($locationId)->contentId;
40+
$roleAssignments = $this->persistenceHandler->userHandler()->loadRoleAssignmentsByGroupId($contentId);
3841
$limit = $this->persistenceHandler->contentHandler()->countRelations(
39-
$location->contentId
42+
$contentId
4043
);
4144

4245
$reverseRelations = $this->persistenceHandler->contentHandler()->loadRelationList(
43-
$location->contentId,
46+
$contentId,
4447
$limit
4548
);
4649
$return = $this->persistenceHandler->trashHandler()->trashSubtree($locationId);
@@ -55,12 +58,20 @@ public function trashSubtree($locationId)
5558
}, $reverseRelations);
5659
}
5760

61+
$roleAssignmentTags = array_map(function (RoleAssignment $roleAssignment): string {
62+
return $this->cacheIdentifierGenerator->generateTag(
63+
self::ROLE_ASSIGNMENT_ROLE_LIST_IDENTIFIER,
64+
[$roleAssignment->roleId]
65+
);
66+
}, $roleAssignments);
67+
5868
$tags = array_merge(
5969
[
60-
$this->cacheIdentifierGenerator->generateTag(self::CONTENT_IDENTIFIER, [$location->contentId]),
70+
$this->cacheIdentifierGenerator->generateTag(self::CONTENT_IDENTIFIER, [$contentId]),
6171
$this->cacheIdentifierGenerator->generateTag(self::LOCATION_PATH_IDENTIFIER, [$locationId]),
6272
],
63-
$relationTags
73+
$relationTags,
74+
$roleAssignmentTags
6475
);
6576
$this->cache->invalidateTags(array_values(array_unique($tags)));
6677

@@ -76,14 +87,15 @@ public function recover($trashedId, $newParentId)
7687

7788
$return = $this->persistenceHandler->trashHandler()->recover($trashedId, $newParentId);
7889

79-
$location = $this->persistenceHandler->locationHandler()->load($return);
90+
$contentId = $this->persistenceHandler->locationHandler()->load($return)->contentId;
91+
$roleAssignments = $this->persistenceHandler->userHandler()->loadRoleAssignmentsByGroupId($contentId);
8092

8193
$limit = $this->persistenceHandler->contentHandler()->countRelations(
82-
$location->contentId
94+
$contentId
8395
);
8496

8597
$reverseRelations = $this->persistenceHandler->contentHandler()->loadRelationList(
86-
$location->contentId,
98+
$contentId,
8799
$limit
88100
);
89101

@@ -94,12 +106,20 @@ public function recover($trashedId, $newParentId)
94106
}, $reverseRelations);
95107
}
96108

109+
$roleAssignmentTags = array_map(function (RoleAssignment $roleAssignment): string {
110+
return $this->cacheIdentifierGenerator->generateTag(
111+
self::ROLE_ASSIGNMENT_ROLE_LIST_IDENTIFIER,
112+
[$roleAssignment->roleId]
113+
);
114+
}, $roleAssignments);
115+
97116
$tags = array_merge(
98117
[
99-
$this->cacheIdentifierGenerator->generateTag(self::CONTENT_IDENTIFIER, [$location->contentId]),
118+
$this->cacheIdentifierGenerator->generateTag(self::CONTENT_IDENTIFIER, [$contentId]),
100119
$this->cacheIdentifierGenerator->generateTag(self::LOCATION_PATH_IDENTIFIER, [$trashedId]),
101120
],
102-
$relationTags
121+
$relationTags,
122+
$roleAssignmentTags
103123
);
104124
$this->cache->invalidateTags(array_values(array_unique($tags)));
105125

src/lib/Persistence/Legacy/User/Role/Gateway/DoctrineDatabase.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Ibexa\Contracts\Core\Persistence\User\Policy;
1616
use Ibexa\Contracts\Core\Persistence\User\Role;
1717
use Ibexa\Contracts\Core\Persistence\User\RoleUpdateStruct;
18+
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
1819
use Ibexa\Core\Persistence\Legacy\Content\Gateway as ContentGateway;
1920
use Ibexa\Core\Persistence\Legacy\Content\Location\Gateway as LocationGateway;
2021
use Ibexa\Core\Persistence\Legacy\User\Role\Gateway;
@@ -371,16 +372,20 @@ public function countRoleAssignments(int $roleId): int
371372
private function buildLoadRoleAssignmentsQuery(array $columns, int $roleId): QueryBuilder
372373
{
373374
$query = $this->connection->createQueryBuilder();
375+
$expr = $query->expr();
374376
$query
375377
->select(...$columns)
376378
->from(self::USER_ROLE_TABLE, 'user_role')
377379
->innerJoin(
378380
'user_role',
379381
ContentGateway::CONTENT_ITEM_TABLE,
380382
'content_object',
381-
'user_role.contentobject_id = content_object.id'
383+
(string) $expr->and(
384+
$expr->eq('user_role.contentobject_id', 'content_object.id'),
385+
$expr->eq('content_object.status', ContentInfo::STATUS_PUBLISHED)
386+
)
382387
)->where(
383-
$query->expr()->eq(
388+
$expr->eq(
384389
'role_id',
385390
$query->createPositionalParameter($roleId, ParameterType::INTEGER)
386391
)

tests/lib/Persistence/Cache/TrashHandlerTest.php

Lines changed: 45 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use Ibexa\Contracts\Core\Persistence\Content\Location\Trash\Handler as TrashHandler;
1212
use Ibexa\Contracts\Core\Persistence\Content\Location\Trashed;
1313
use Ibexa\Contracts\Core\Persistence\Content\Relation;
14+
use Ibexa\Contracts\Core\Persistence\User\Handler as PersistenceUserHandler;
15+
use Ibexa\Contracts\Core\Persistence\User\RoleAssignment;
1416
use Ibexa\Contracts\Core\Repository\Values\Content\Trash\TrashItemDeleteResult;
1517
use Ibexa\Core\Persistence\Cache\ContentHandler;
1618
use Ibexa\Core\Persistence\Cache\LocationHandler;
@@ -57,72 +59,51 @@ public function testRecover()
5759
$originalLocationId = 6;
5860
$targetLocationId = 2;
5961
$contentId = 42;
60-
61-
$tags = [
62-
'c-' . $contentId,
63-
'lp-' . $originalLocationId,
64-
];
65-
66-
$handlerMethodName = $this->getHandlerMethodName();
62+
$roleId = 1;
6763

6864
$this->loggerMock->expects(self::once())->method('logCall');
6965

70-
$innerHandler = $this->createMock($this->getHandlerClassName());
71-
$contentHandlerMock = $this->createMock(ContentHandler::class);
72-
$locationHandlerMock = $this->createMock(LocationHandler::class);
73-
74-
$locationHandlerMock
75-
->method('load')
76-
->willReturn(new Location(['id' => $originalLocationId, 'contentId' => $contentId]));
77-
78-
$this->persistenceHandlerMock
79-
->method('contentHandler')
80-
->willReturn($contentHandlerMock);
81-
82-
$this->persistenceHandlerMock
83-
->method('locationHandler')
84-
->willReturn($locationHandlerMock);
85-
86-
$this->persistenceHandlerMock
87-
->expects(self::once())
88-
->method($handlerMethodName)
89-
->willReturn($innerHandler);
66+
$innerHandler = $this->setUpRoleAssignmentInvalidation($originalLocationId, $contentId, $roleId);
9067

9168
$innerHandler
9269
->expects(self::once())
9370
->method('recover')
9471
->with($originalLocationId, $targetLocationId)
9572
->willReturn(null);
9673

97-
$this->cacheIdentifierGeneratorMock
98-
->expects(self::exactly(2))
99-
->method('generateTag')
100-
->withConsecutive(
101-
['content', [$contentId], false],
102-
['location_path', [$originalLocationId], false]
103-
)
104-
->willReturnOnConsecutiveCalls(
105-
'c-' . $contentId,
106-
'lp-' . $originalLocationId
107-
);
108-
109-
$this->cacheMock
110-
->expects(self::once())
111-
->method('invalidateTags')
112-
->with($tags);
113-
114-
$handler = $this->persistenceCacheHandler->$handlerMethodName();
74+
$handler = $this->persistenceCacheHandler->{$this->getHandlerMethodName()}();
11575
$handler->recover($originalLocationId, $targetLocationId);
11676
}
11777

11878
public function testTrashSubtree()
11979
{
12080
$locationId = 6;
12181
$contentId = 42;
82+
$roleId = 1;
83+
84+
$this->loggerMock->expects($this->once())->method('logCall');
85+
86+
$innerHandler = $this->setUpRoleAssignmentInvalidation($locationId, $contentId, $roleId);
87+
88+
$innerHandler
89+
->expects(self::once())
90+
->method('trashSubtree')
91+
->with($locationId)
92+
->willReturn(null);
12293

94+
$handler = $this->persistenceCacheHandler->{$this->getHandlerMethodName()}();
95+
$handler->trashSubtree($locationId);
96+
}
97+
98+
/**
99+
* @return \PHPUnit\Framework\MockObject\MockObject
100+
*/
101+
private function setUpRoleAssignmentInvalidation(int $locationId, int $contentId, int $roleId): object
102+
{
123103
$tags = [
124104
'c-' . $contentId,
125105
'lp-' . $locationId,
106+
'rarl-' . $roleId,
126107
];
127108

128109
$handlerMethodName = $this->getHandlerMethodName();
@@ -132,11 +113,17 @@ public function testTrashSubtree()
132113
$innerHandler = $this->createMock($this->getHandlerClassName());
133114
$contentHandlerMock = $this->createMock(ContentHandler::class);
134115
$locationHandlerMock = $this->createMock(LocationHandler::class);
116+
$userHandlerMock = $this->createMock(PersistenceUserHandler::class);
135117

136118
$locationHandlerMock
137119
->method('load')
138120
->willReturn(new Location(['id' => $locationId, 'contentId' => $contentId]));
139121

122+
$userHandlerMock
123+
->method('loadRoleAssignmentsByGroupId')
124+
->with($contentId)
125+
->willReturn([new RoleAssignment(['roleId' => $roleId, 'contentId' => $contentId])]);
126+
140127
$this->persistenceHandlerMock
141128
->method('contentHandler')
142129
->willReturn($contentHandlerMock);
@@ -146,32 +133,34 @@ public function testTrashSubtree()
146133
->willReturn($locationHandlerMock);
147134

148135
$this->persistenceHandlerMock
149-
->expects(self::once())
150-
->method($handlerMethodName)
151-
->willReturn($innerHandler);
136+
->method('userHandler')
137+
->willReturn($userHandlerMock);
152138

153-
$innerHandler
139+
$this->persistenceHandlerMock
154140
->expects(self::once())
155-
->method('trashSubtree')
156-
->with($locationId)
157-
->willReturn(null);
141+
->method($this->getHandlerMethodName())
142+
->willReturn($innerHandler);
158143

159144
$this->cacheIdentifierGeneratorMock
160-
->expects(self::exactly(2))
145+
->expects(self::exactly(3))
161146
->method('generateTag')
162147
->withConsecutive(
148+
['role_assignment_role_list', [$roleId], false],
163149
['content', [$contentId], false],
164150
['location_path', [$locationId], false]
165151
)
166-
->willReturnOnConsecutiveCalls(...$tags);
152+
->willReturnOnConsecutiveCalls(
153+
'rarl-' . $roleId,
154+
'c-' . $contentId,
155+
'lp-' . $locationId
156+
);
167157

168158
$this->cacheMock
169159
->expects(self::once())
170160
->method('invalidateTags')
171161
->with($tags);
172162

173-
$handler = $this->persistenceCacheHandler->$handlerMethodName();
174-
$handler->trashSubtree($locationId);
163+
return $innerHandler;
175164
}
176165

177166
public function testDeleteTrashItem()

tests/lib/Persistence/Legacy/User/_fixtures/roles.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,11 @@
134134
ContentGateway::CONTENT_ITEM_TABLE => [
135135
[
136136
'id' => '11',
137+
'status' => '1',
137138
],
138139
[
139140
'id' => '42',
141+
'status' => '1',
140142
],
141143
],
142144
];

0 commit comments

Comments
 (0)