Skip to content

Commit 67cbdaa

Browse files
committed
Added 'includeSystem' parameter to loadAllGroups and related methods
1 parent fb60a60 commit 67cbdaa

File tree

16 files changed

+114
-34
lines changed

16 files changed

+114
-34
lines changed

src/contracts/Persistence/Content/Type/Handler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function loadGroupByIdentifier($identifier);
7070
/**
7171
* @return \Ibexa\Contracts\Core\Persistence\Content\Type\Group[]
7272
*/
73-
public function loadAllGroups();
73+
public function loadAllGroups(bool $includeSystem = false);
7474

7575
/**
7676
* @param mixed $groupId

src/contracts/Repository/ContentTypeService.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ public function loadContentTypeGroupByIdentifier(string $contentTypeGroupIdentif
6464
* Get all content type groups.
6565
*
6666
* @param string[] $prioritizedLanguages Used as prioritized language code on translated properties of returned object.
67+
* @param bool $includeSystem When true also returns system ContentTypeGroups. Default false.
6768
*
6869
* @return \Ibexa\Contracts\Core\Repository\Values\ContentType\ContentTypeGroup[]
6970
*/
70-
public function loadContentTypeGroups(array $prioritizedLanguages = []): iterable;
71+
public function loadContentTypeGroups(array $prioritizedLanguages = [], bool $includeSystem = false): iterable;
7172

7273
/**
7374
* Update a content type group object.

src/contracts/Repository/Decorator/ContentTypeServiceDecorator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public function loadContentTypeGroupByIdentifier(
5252
return $this->innerService->loadContentTypeGroupByIdentifier($contentTypeGroupIdentifier, $prioritizedLanguages);
5353
}
5454

55-
public function loadContentTypeGroups(array $prioritizedLanguages = []): iterable
55+
public function loadContentTypeGroups(array $prioritizedLanguages = [], bool $includeSystem = false): iterable
5656
{
57-
return $this->innerService->loadContentTypeGroups($prioritizedLanguages);
57+
return $this->innerService->loadContentTypeGroups($prioritizedLanguages, $includeSystem);
5858
}
5959

6060
public function updateContentTypeGroup(

src/lib/Persistence/Cache/ContentTypeHandler.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public function createGroup(GroupCreateStruct $struct)
100100
$this->logger->logCall(__METHOD__, ['struct' => $struct]);
101101
$this->cache->deleteItems([
102102
$this->cacheIdentifierGenerator->generateKey(self::CONTENT_TYPE_GROUP_LIST_IDENTIFIER, [], true),
103+
$this->cacheIdentifierGenerator->generateKey(self::CONTENT_TYPE_GROUP_LIST_IDENTIFIER, [true], true),
103104
]);
104105

105106
return $this->persistenceHandler->contentTypeHandler()->createGroup($struct);
@@ -115,6 +116,7 @@ public function updateGroup(GroupUpdateStruct $struct)
115116

116117
$this->cache->deleteItems([
117118
$this->cacheIdentifierGenerator->generateKey(self::CONTENT_TYPE_GROUP_LIST_IDENTIFIER, [], true),
119+
$this->cacheIdentifierGenerator->generateKey(self::CONTENT_TYPE_GROUP_LIST_IDENTIFIER, [true], true),
118120
$this->cacheIdentifierGenerator->generateKey(self::CONTENT_TYPE_GROUP_IDENTIFIER, [$struct->id], true),
119121
$this->cacheIdentifierGenerator->generateKey(
120122
self::CONTENT_TYPE_GROUP_WITH_ID_SUFFIX_IDENTIFIER,
@@ -137,6 +139,10 @@ public function deleteGroup($groupId)
137139
$this->cache->invalidateTags([
138140
$this->cacheIdentifierGenerator->generateTag(self::TYPE_GROUP_IDENTIFIER, [$groupId]),
139141
]);
142+
$this->cache->deleteItems([
143+
$this->cacheIdentifierGenerator->generateKey(self::CONTENT_TYPE_GROUP_LIST_IDENTIFIER, [], true),
144+
$this->cacheIdentifierGenerator->generateKey(self::CONTENT_TYPE_GROUP_LIST_IDENTIFIER, [true], true),
145+
]);
140146

141147
return $return;
142148
}
@@ -193,12 +199,12 @@ function () use ($identifier) {
193199
/**
194200
* {@inheritdoc}
195201
*/
196-
public function loadAllGroups()
202+
public function loadAllGroups(bool $includeSystem = false)
197203
{
198204
return $this->getListCacheValue(
199-
$this->cacheIdentifierGenerator->generateKey(self::CONTENT_TYPE_GROUP_LIST_IDENTIFIER, [], true),
200-
function () {
201-
return $this->persistenceHandler->contentTypeHandler()->loadAllGroups();
205+
$this->cacheIdentifierGenerator->generateKey(self::CONTENT_TYPE_GROUP_LIST_IDENTIFIER, [$includeSystem], true),
206+
function () use ($includeSystem) {
207+
return $this->persistenceHandler->contentTypeHandler()->loadAllGroups($includeSystem);
202208
},
203209
$this->getGroupTags,
204210
$this->getGroupKeys

src/lib/Persistence/Legacy/Content/Type/Gateway.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ abstract public function loadGroupData(array $groupIds): array;
5252

5353
abstract public function loadGroupDataByIdentifier(string $identifier): array;
5454

55-
abstract public function loadAllGroupsData(): array;
55+
abstract public function loadAllGroupsData(bool $includeSystem = false): array;
5656

5757
/**
5858
* Load data for all content types of the given status, belonging to the given Group.

src/lib/Persistence/Legacy/Content/Type/Gateway/DoctrineDatabase.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -547,16 +547,18 @@ public function loadGroupDataByIdentifier(string $identifier): array
547547
return $query->execute()->fetchAll(FetchMode::ASSOCIATIVE);
548548
}
549549

550-
public function loadAllGroupsData(): array
550+
public function loadAllGroupsData(bool $includeSystem = false): array
551551
{
552552
$query = $this->createGroupLoadQuery();
553553

554-
$query->andWhere(
555-
$query->expr()->eq(
556-
'is_system',
557-
$query->createPositionalParameter(false, ParameterType::BOOLEAN)
558-
)
559-
);
554+
if (!$includeSystem) {
555+
$query->andWhere(
556+
$query->expr()->eq(
557+
'is_system',
558+
$query->createPositionalParameter(false, ParameterType::BOOLEAN)
559+
)
560+
);
561+
}
560562

561563
return $query->execute()->fetchAll(FetchMode::ASSOCIATIVE);
562564
}

src/lib/Persistence/Legacy/Content/Type/Gateway/ExceptionConversion.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ public function loadGroupDataByIdentifier(string $identifier): array
113113
}
114114
}
115115

116-
public function loadAllGroupsData(): array
116+
public function loadAllGroupsData(bool $includeSystem = false): array
117117
{
118118
try {
119-
return $this->innerGateway->loadAllGroupsData();
119+
return $this->innerGateway->loadAllGroupsData($includeSystem);
120120
} catch (DBALException | PDOException $e) {
121121
throw DatabaseException::wrap($e);
122122
}

src/lib/Persistence/Legacy/Content/Type/Handler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ public function loadGroupByIdentifier($identifier)
168168
/**
169169
* @return \Ibexa\Contracts\Core\Persistence\Content\Type\Group[]
170170
*/
171-
public function loadAllGroups()
171+
public function loadAllGroups(bool $includeSystem = false)
172172
{
173173
return $this->mapper->extractGroupsFromRows(
174-
$this->contentTypeGateway->loadAllGroupsData()
174+
$this->contentTypeGateway->loadAllGroupsData($includeSystem)
175175
);
176176
}
177177

src/lib/Persistence/Legacy/Content/Type/MemoryCachingHandler.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function createGroup(GroupCreateStruct $createStruct): Group
5353
$this->storeGroupCache([$group]);
5454
$this->cache->deleteMulti([
5555
$this->generator->generateKey(self::CONTENT_TYPE_GROUP_LIST, [], true),
56+
$this->generator->generateKey(self::CONTENT_TYPE_GROUP_LIST, [true], true),
5657
]);
5758

5859
return $group;
@@ -64,6 +65,7 @@ public function updateGroup(GroupUpdateStruct $struct): Group
6465
$this->storeGroupCache([$group]);
6566
$this->cache->deleteMulti([
6667
$this->generator->generateKey(self::CONTENT_TYPE_GROUP_LIST, [], true),
68+
$this->generator->generateKey(self::CONTENT_TYPE_GROUP_LIST, [true], true),
6769
]);
6870

6971
return $group;
@@ -76,6 +78,7 @@ public function deleteGroup($groupId): void
7678
$this->cache->deleteMulti([
7779
$this->generator->generateKey(self::CONTENT_TYPE_GROUP, [$groupId], true),
7880
$this->generator->generateKey(self::CONTENT_TYPE_GROUP_LIST, [], true),
81+
$this->generator->generateKey(self::CONTENT_TYPE_GROUP_LIST, [true], true),
7982
]);
8083
}
8184

@@ -139,13 +142,13 @@ public function loadGroupByIdentifier($identifier): Group
139142
/**
140143
* @return \Ibexa\Contracts\Core\Persistence\Content\Type\Group[]
141144
*/
142-
public function loadAllGroups(): array
145+
public function loadAllGroups(bool $includeSystem = false): array
143146
{
144-
$contentTypeGroupListKey = $this->generator->generateKey(self::CONTENT_TYPE_GROUP_LIST, [], true);
147+
$contentTypeGroupListKey = $this->generator->generateKey(self::CONTENT_TYPE_GROUP_LIST, [$includeSystem], true);
145148
$groups = $this->cache->get($contentTypeGroupListKey);
146149

147150
if ($groups === null) {
148-
$groups = $this->innerHandler->loadAllGroups();
151+
$groups = $this->innerHandler->loadAllGroups($includeSystem);
149152
$this->storeGroupCache($groups, $contentTypeGroupListKey);
150153
}
151154

src/lib/Repository/ContentTypeService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,9 @@ public function loadContentTypeGroupByIdentifier(string $contentTypeGroupIdentif
206206
/**
207207
* {@inheritdoc}
208208
*/
209-
public function loadContentTypeGroups(array $prioritizedLanguages = []): iterable
209+
public function loadContentTypeGroups(array $prioritizedLanguages = [], bool $includeSystem = false): iterable
210210
{
211-
$spiGroups = $this->contentTypeHandler->loadAllGroups();
211+
$spiGroups = $this->contentTypeHandler->loadAllGroups($includeSystem);
212212

213213
$groups = [];
214214
foreach ($spiGroups as $spiGroup) {

0 commit comments

Comments
 (0)