Skip to content

Commit 558086b

Browse files
Removed unnecessary docblock, set deprecated for loadRelations function, Corrected CS
1 parent 290d70c commit 558086b

File tree

13 files changed

+127
-174
lines changed

13 files changed

+127
-174
lines changed

phpstan-baseline.neon

+1-1
Original file line numberDiff line numberDiff line change
@@ -16187,7 +16187,7 @@ parameters:
1618716187

1618816188
-
1618916189
message: "#^Cannot call method fetchAll\\(\\) on Doctrine\\\\DBAL\\\\ForwardCompatibility\\\\Result\\|int\\|string\\.$#"
16190-
count: 17
16190+
count: 16
1619116191
path: src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php
1619216192

1619316193
-

src/contracts/Persistence/Content/Handler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ public function countRelations(
308308
*/
309309
public function loadRelationList(
310310
int $sourceContentId,
311+
int $limit,
311312
int $offset = 0,
312-
?int $limit = null,
313313
?int $sourceContentVersionNo = null,
314314
?int $type = null
315315
): array;

src/contracts/Repository/ContentService.php

+10-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
*/
3131
interface ContentService
3232
{
33+
public const DEFAULT_PAGE_SIZE = 25;
34+
3335
/**
3436
* Loads a content info object.
3537
*
@@ -398,7 +400,7 @@ public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $dest
398400
*
399401
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version
400402
*
401-
* @param \Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo $versionInfo
403+
* @deprecated since 4.5, use loadRelationList().
402404
*
403405
* @return \Ibexa\Contracts\Core\Repository\Values\Content\Relation[]
404406
*/
@@ -408,9 +410,14 @@ public function loadRelations(VersionInfo $versionInfo): iterable;
408410
* Loads all outgoing relations for the given version.
409411
*
410412
* If the user is not allowed to read specific version then UnauthorizedRelationListItem is returned
411-
* {@link \Ibexa\Contracts\Core\Repository\Values\Content\RelationList\Item\UnauthorizedRelationListItem}
413+
*
414+
* @see \Ibexa\Contracts\Core\Repository\Values\Content\RelationList\Item\UnauthorizedRelationListItem
412415
*/
413-
public function loadRelationList(VersionInfo $versionInfo, int $offset = 0, ?int $limit = null): RelationList;
416+
public function loadRelationList(
417+
VersionInfo $versionInfo,
418+
int $offset = 0,
419+
int $limit = self::DEFAULT_PAGE_SIZE
420+
): RelationList;
414421

415422
/**
416423
* Counts all outgoing relations for the given version.

src/contracts/Repository/Decorator/ContentServiceDecorator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public function countRelations(VersionInfo $versionInfo): int
198198
return $this->innerService->countRelations($versionInfo);
199199
}
200200

201-
public function loadRelationList(VersionInfo $versionInfo, int $offset = 0, ?int $limit = null): RelationList
201+
public function loadRelationList(VersionInfo $versionInfo, int $offset = 0, int $limit = self::DEFAULT_PAGE_SIZE): RelationList
202202
{
203203
return $this->innerService->loadRelationList($versionInfo, $offset, $limit);
204204
}

src/lib/Persistence/Cache/ContentHandler.php

+21-4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ class ContentHandler extends AbstractInMemoryPersistenceHandler implements Conte
3232
private const CONTENT_VERSION_INFO_IDENTIFIER = 'content_version_info';
3333
private const CONTENT_VERSION_IDENTIFIER = 'content_version';
3434
private const CONTENT_RELATIONS_COUNT_IDENTIFIER = 'content_relations_count';
35+
private const CONTENT_RELATIONS_COUNT_WITH_TYPE_IDENTIFIER = 'content_relations_count_with_type';
36+
private const CONTENT_RELATIONS_COUNT_WITH_TYPE_AND_VERSION_IDENTIFIER = 'content_relations_count_with_type_and_version';
37+
private const CONTENT_RELATIONS_COUNT_WITH_VERSION_IDENTIFIER = 'content_relations_count_with_version';
3538
private const CONTENT_REVERSE_RELATIONS_COUNT_IDENTIFIER = 'content_reverse_relations_count';
3639
private const RELATION_IDENTIFIER = 'relation';
3740

@@ -520,10 +523,24 @@ public function loadRelations($sourceContentId, $sourceContentVersionNo = null,
520523

521524
public function countRelations(int $sourceContentId, ?int $sourceContentVersionNo = null, ?int $type = null): int
522525
{
526+
$values[] = $sourceContentId;
527+
if ($sourceContentVersionNo === null && $type !== null) {
528+
$patternName = self::CONTENT_RELATIONS_COUNT_WITH_TYPE_IDENTIFIER;
529+
$values[] = $type;
530+
} elseif ($sourceContentVersionNo !== null && $type === null) {
531+
$patternName = self::CONTENT_RELATIONS_COUNT_WITH_VERSION_IDENTIFIER;
532+
$values[] = $sourceContentVersionNo;
533+
} elseif ($sourceContentVersionNo !== null && $type !== null) {
534+
$patternName = self::CONTENT_RELATIONS_COUNT_WITH_TYPE_AND_VERSION_IDENTIFIER;
535+
$values = array_merge($values, [$type, $sourceContentVersionNo]);
536+
} else {
537+
$patternName = self::CONTENT_RELATIONS_COUNT_IDENTIFIER;
538+
}
539+
523540
$cacheItem = $this->cache->getItem(
524541
$this->cacheIdentifierGenerator->generateKey(
525-
self::CONTENT_RELATIONS_COUNT_IDENTIFIER,
526-
[$sourceContentId],
542+
$patternName,
543+
$values,
527544
true
528545
)
529546
);
@@ -559,8 +576,8 @@ public function countRelations(int $sourceContentId, ?int $sourceContentVersionN
559576
*/
560577
public function loadRelationList(
561578
int $sourceContentId,
579+
int $limit,
562580
int $offset = 0,
563-
?int $limit = null,
564581
?int $sourceContentVersionNo = null,
565582
?int $type = null
566583
): array {
@@ -574,8 +591,8 @@ public function loadRelationList(
574591

575592
return $this->persistenceHandler->contentHandler()->loadRelationList(
576593
$sourceContentId,
577-
$offset,
578594
$limit,
595+
$offset,
579596
$sourceContentVersionNo,
580597
$type
581598
);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,8 @@ abstract public function countRelations(
376376
*/
377377
abstract public function listRelations(
378378
int $contentId,
379+
int $limit,
379380
int $offset = 0,
380-
?int $limit = null,
381381
?int $contentVersionNo = null,
382382
?int $relationType = null
383383
): array;

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

+31-130
Original file line numberDiff line numberDiff line change
@@ -1387,62 +1387,9 @@ public function loadRelations(
13871387
?int $relationType = null
13881388
): array {
13891389
$query = $this->queryBuilder->createRelationFindQueryBuilder();
1390-
$expr = $query->expr();
1391-
$query
1392-
->innerJoin(
1393-
'l',
1394-
'ezcontentobject',
1395-
'ezcontentobject_to',
1396-
$expr->andX(
1397-
'l.to_contentobject_id = ezcontentobject_to.id',
1398-
'ezcontentobject_to.status = :status'
1399-
)
1400-
)
1401-
->where(
1402-
'l.from_contentobject_id = :content_id'
1403-
)
1404-
->setParameter(
1405-
'status',
1406-
ContentInfo::STATUS_PUBLISHED,
1407-
ParameterType::INTEGER
1408-
)
1409-
->setParameter('content_id', $contentId, ParameterType::INTEGER);
1410-
1411-
// source version number
1412-
if (null !== $contentVersionNo) {
1413-
$query
1414-
->andWhere('l.from_contentobject_version = :version_no')
1415-
->setParameter('version_no', $contentVersionNo, ParameterType::INTEGER);
1416-
} else {
1417-
// from published version only
1418-
$query
1419-
->innerJoin(
1420-
'ezcontentobject_to',
1421-
'ezcontentobject',
1422-
'c',
1423-
$expr->andX(
1424-
'c.id = l.from_contentobject_id',
1425-
'c.current_version = l.from_contentobject_version'
1426-
)
1427-
);
1428-
}
1429-
1430-
// relation type
1431-
if (null !== $relationType) {
1432-
$query
1433-
->andWhere(
1434-
$expr->gt(
1435-
$this->databasePlatform->getBitAndComparisonExpression(
1436-
'l.relation_type',
1437-
':relation_type'
1438-
),
1439-
0
1440-
)
1441-
)
1442-
->setParameter('relation_type', $relationType, ParameterType::INTEGER);
1443-
}
1390+
$query = $this->prepareRelationQuery($query, $contentId, $contentVersionNo, $relationType);
14441391

1445-
return $query->execute()->fetchAll(FetchMode::ASSOCIATIVE);
1392+
return $query->execute()->fetchAllAssociative();
14461393
}
14471394

14481395
public function countRelations(
@@ -1451,89 +1398,50 @@ public function countRelations(
14511398
?int $relationType = null
14521399
): int {
14531400
$query = $this->connection->createQueryBuilder();
1454-
$expr = $query->expr();
1455-
$query
1456-
->select($this->databasePlatform->getCountExpression('l.id'))
1457-
->from(self::CONTENT_RELATION_TABLE, 'l')
1458-
->innerJoin(
1459-
'l',
1460-
'ezcontentobject',
1461-
'ezcontentobject_to',
1462-
$expr->and(
1463-
'l.to_contentobject_id = ezcontentobject_to.id',
1464-
'ezcontentobject_to.status = :status'
1465-
)
1466-
)
1467-
->andWhere(
1468-
'l.from_contentobject_id = :content_id'
1469-
)
1470-
->setParameter(
1471-
'status',
1472-
ContentInfo::STATUS_PUBLISHED,
1473-
ParameterType::INTEGER
1474-
)
1475-
->setParameter('content_id', $contentId, ParameterType::INTEGER);
1476-
1477-
// source version number
1478-
if (null !== $contentVersionNo) {
1479-
$query
1480-
->andWhere('l.from_contentobject_version = :version_no')
1481-
->setParameter('version_no', $contentVersionNo, ParameterType::INTEGER);
1482-
} else {
1483-
// from published version only
1484-
$query
1485-
->innerJoin(
1486-
'ezcontentobject_to',
1487-
'ezcontentobject',
1488-
'c',
1489-
$expr->and(
1490-
'c.id = l.from_contentobject_id',
1491-
'c.current_version = l.from_contentobject_version'
1492-
)
1493-
);
1494-
}
1401+
$query->select($this->databasePlatform->getCountExpression('l.id'))
1402+
->from(self::CONTENT_RELATION_TABLE, 'l');
14951403

1496-
// relation type
1497-
if (null !== $relationType) {
1498-
$query
1499-
->andWhere(
1500-
$expr->gt(
1501-
$this->databasePlatform->getBitAndComparisonExpression(
1502-
'l.relation_type',
1503-
':relation_type'
1504-
),
1505-
0
1506-
)
1507-
)
1508-
->setParameter('relation_type', $relationType, ParameterType::INTEGER);
1509-
}
1404+
$query = $this->prepareRelationQuery($query, $contentId, $contentVersionNo, $relationType);
15101405

15111406
return (int)$query->execute()->fetchOne();
15121407
}
15131408

1514-
/**
1515-
* {@inheritdoc}
1516-
*/
15171409
public function listRelations(
15181410
int $contentId,
1411+
int $limit,
15191412
int $offset = 0,
1520-
?int $limit = null,
15211413
?int $contentVersionNo = null,
15221414
?int $relationType = null
15231415
): array {
15241416
$query = $this->queryBuilder->createRelationFindQueryBuilder();
1417+
$query = $this->prepareRelationQuery($query, $contentId, $contentVersionNo, $relationType);
1418+
1419+
$query->setFirstResult($offset)
1420+
->setMaxResults($limit);
1421+
1422+
$query->orderBy('l.id', 'DESC');
1423+
1424+
return $query->execute()->fetchAllAssociative();
1425+
}
1426+
1427+
private function prepareRelationQuery(
1428+
DoctrineQueryBuilder $query,
1429+
int $contentId,
1430+
?int $contentVersionNo = null,
1431+
?int $relationType = null
1432+
): DoctrineQueryBuilder {
15251433
$expr = $query->expr();
15261434
$query
15271435
->innerJoin(
15281436
'l',
1529-
'ezcontentobject',
1437+
self::CONTENT_ITEM_TABLE,
15301438
'ezcontentobject_to',
15311439
$expr->and(
1532-
$expr->eq('l.to_contentobject_id', 'ezcontentobject_to.id'),
1533-
$expr->eq('ezcontentobject_to.status', ':status'),
1440+
'l.to_contentobject_id = ezcontentobject_to.id',
1441+
'ezcontentobject_to.status = :status'
15341442
)
15351443
)
1536-
->andWhere(
1444+
->where(
15371445
'l.from_contentobject_id = :content_id'
15381446
)
15391447
->setParameter(
@@ -1544,7 +1452,7 @@ public function listRelations(
15441452
->setParameter('content_id', $contentId, ParameterType::INTEGER);
15451453

15461454
// source version number
1547-
if (null !== $contentVersionNo) {
1455+
if ($contentVersionNo !== null) {
15481456
$query
15491457
->andWhere('l.from_contentobject_version = :version_no')
15501458
->setParameter('version_no', $contentVersionNo, ParameterType::INTEGER);
@@ -1553,11 +1461,11 @@ public function listRelations(
15531461
$query
15541462
->innerJoin(
15551463
'ezcontentobject_to',
1556-
'ezcontentobject',
1464+
self::CONTENT_ITEM_TABLE,
15571465
'c',
15581466
$expr->and(
1559-
$expr->eq('c.id', 'l.from_contentobject_id'),
1560-
$expr->eq('c.current_version', 'l.from_contentobject_version'),
1467+
'c.id = l.from_contentobject_id',
1468+
'c.current_version = l.from_contentobject_version'
15611469
)
15621470
);
15631471
}
@@ -1577,14 +1485,7 @@ public function listRelations(
15771485
->setParameter('relation_type', $relationType, ParameterType::INTEGER);
15781486
}
15791487

1580-
$query->setFirstResult($offset);
1581-
if ($limit !== null) {
1582-
$query->setMaxResults($limit);
1583-
}
1584-
1585-
$query->orderBy('l.id', 'DESC');
1586-
1587-
return $query->execute()->fetchAllAssociative();
1488+
return $query;
15881489
}
15891490

15901491
public function countReverseRelations(int $toContentId, ?int $relationType = null): int

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -409,16 +409,16 @@ public function countRelations(
409409
*/
410410
public function listRelations(
411411
int $contentId,
412+
int $limit,
412413
int $offset = 0,
413-
?int $limit = null,
414414
?int $contentVersionNo = null,
415415
?int $relationType = null
416416
): array {
417417
try {
418418
return $this->innerGateway->listRelations(
419419
$contentId,
420-
$offset,
421420
$limit,
421+
$offset,
422422
$contentVersionNo,
423423
$relationType
424424
);

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -832,13 +832,13 @@ public function countRelations(int $sourceContentId, ?int $sourceContentVersionN
832832
*/
833833
public function loadRelationList(
834834
int $sourceContentId,
835+
int $limit,
835836
int $offset = 0,
836-
?int $limit = null,
837837
?int $sourceContentVersionNo = null,
838838
?int $type = null
839839
): array {
840840
return $this->mapper->extractRelationsFromRows(
841-
$this->contentGateway->listRelations($sourceContentId, $offset, $limit, $sourceContentVersionNo, $type)
841+
$this->contentGateway->listRelations($sourceContentId, $limit, $offset, $sourceContentVersionNo, $type)
842842
);
843843
}
844844

0 commit comments

Comments
 (0)