Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

Core/Search/Legacy/Content/IndexerGateway.php
Go to the documentation of this file.
1 <?php
2
7 declare(strict_types=1);
8
9 namespace eZ\Publish\Core\Search\Legacy\Content;
10
11 use DateTimeInterface;
12 use Doctrine\DBAL\Connection;
13 use Doctrine\DBAL\Driver\ResultStatement;
14 use Doctrine\DBAL\ParameterType;
15 use Doctrine\DBAL\Query\QueryBuilder;
16 use eZ\Publish\SPI\Persistence\Content\ContentInfo;
17 use eZ\Publish\SPI\Search\Content\IndexerGateway as SPIIndexerGateway;
18 use Generator;
19
23 final class IndexerGateway implements SPIIndexerGateway
24 {
26 private $connection;
27
28 public function __construct(Connection $connection)
29 {
30 $this->connection = $connection;
31 }
32
33 public function getContentSince(DateTimeInterface $since, int $iterationCount): Generator
34 {
35 $query = $this->buildQueryForContentSince($since);
36 $query->orderBy('c.modified');
37
38 yield from $this->fetchIteration($query->execute(), $iterationCount);
39 }
40
41 public function countContentSince(DateTimeInterface $since): int
42 {
43 $query = $this->buildCountingQuery(
44 $this->buildQueryForContentSince($since)
45 );
46
47 return (int)$query->execute()->fetchOne();
48 }
49
50 public function getContentInSubtree(string $locationPath, int $iterationCount): Generator
51 {
52 $query = $this->buildQueryForContentInSubtree($locationPath);
53
54 yield from $this->fetchIteration($query->execute(), $iterationCount);
55 }
56
57 public function countContentInSubtree(string $locationPath): int
58 {
59 $query = $this->buildCountingQuery(
60 $this->buildQueryForContentInSubtree($locationPath)
61 );
62
63 return (int)$query->execute()->fetchOne();
64 }
65
66 public function getAllContent(int $iterationCount): Generator
67 {
68 $query = $this->buildQueryForAllContent();
69
70 yield from $this->fetchIteration($query->execute(), $iterationCount);
71 }
72
73 public function countAllContent(): int
74 {
75 $query = $this->buildCountingQuery(
76 $this->buildQueryForAllContent()
77 );
78
79 return (int)$query->execute()->fetchOne();
80 }
81
82 private function buildQueryForContentSince(DateTimeInterface $since): QueryBuilder
83 {
84 return $this->connection->createQueryBuilder()
85 ->select('c.id')
86 ->from('ezcontentobject', 'c')
87 ->where('c.status = :status')->andWhere('c.modified >= :since')
88 ->setParameter('status', ContentInfo::STATUS_PUBLISHED, ParameterType::INTEGER)
89 ->setParameter('since', $since->getTimestamp(), ParameterType::INTEGER);
90 }
91
92 private function buildQueryForContentInSubtree(string $locationPath): QueryBuilder
93 {
94 return $this->connection->createQueryBuilder()
95 ->select('DISTINCT c.id')
96 ->from('ezcontentobject', 'c')
97 ->innerJoin('c', 'ezcontentobject_tree', 't', 't.contentobject_id = c.id')
98 ->where('c.status = :status')
99 ->andWhere('t.path_string LIKE :path')
100 ->setParameter('status', ContentInfo::STATUS_PUBLISHED, ParameterType::INTEGER)
101 ->setParameter('path', $locationPath . '%', ParameterType::STRING);
102 }
103
104 private function buildQueryForAllContent(): QueryBuilder
105 {
106 return $this->connection->createQueryBuilder()
107 ->select('c.id')
108 ->from('ezcontentobject', 'c')
109 ->where('c.status = :status')
110 ->setParameter('status', ContentInfo::STATUS_PUBLISHED, ParameterType::INTEGER);
111 }
112
116 private function buildCountingQuery(QueryBuilder $query): QueryBuilder
117 {
118 $databasePlatform = $this->connection->getDatabasePlatform();
119
120 // wrap existing select part in count expression
121 $query->select(
122 $databasePlatform->getCountExpression(
123 $query->getQueryPart('select')[0]
124 )
125 );
126
127 return $query;
128 }
129
130 private function fetchIteration(ResultStatement $statement, int $iterationCount): Generator
131 {
132 do {
133 $contentIds = [];
134 for ($i = 0; $i < $iterationCount; ++$i) {
135 if ($contentId = $statement->fetchOne()) {
136 $contentIds[] = $contentId;
137 } elseif (empty($contentIds)) {
138 return;
139 } else {
140 break;
141 }
142 }
143
144 yield $contentIds;
145 } while (!empty($contentId));
146 }
147 }
eZ\Publish\Core\Search\Legacy\Content\IndexerGateway
Definition: Core/Search/Legacy/Content/IndexerGateway.php:24
eZ\Publish\Core\Search\Legacy\Content\IndexerGateway\countContentInSubtree
countContentInSubtree(string $locationPath)
Definition: Core/Search/Legacy/Content/IndexerGateway.php:57
eZ\Publish\Core\Search\Legacy\Content\IndexerGateway\buildQueryForAllContent
buildQueryForAllContent()
Definition: Core/Search/Legacy/Content/IndexerGateway.php:104
eZ\Publish\Core\Search\Legacy\Content\IndexerGateway\getContentSince
getContentSince(DateTimeInterface $since, int $iterationCount)
Definition: Core/Search/Legacy/Content/IndexerGateway.php:33
eZ\Publish\Core\Search\Legacy\Content\IndexerGateway\buildQueryForContentSince
buildQueryForContentSince(DateTimeInterface $since)
Definition: Core/Search/Legacy/Content/IndexerGateway.php:82
eZ\Publish\Core\Search\Legacy\Content\IndexerGateway\getAllContent
getAllContent(int $iterationCount)
Definition: Core/Search/Legacy/Content/IndexerGateway.php:66
eZ\Publish\Core\Search\Legacy\Content\IndexerGateway\__construct
__construct(Connection $connection)
Definition: Core/Search/Legacy/Content/IndexerGateway.php:28
eZ\Publish\Core\Search\Legacy\Content\IndexerGateway\getContentInSubtree
getContentInSubtree(string $locationPath, int $iterationCount)
Definition: Core/Search/Legacy/Content/IndexerGateway.php:50
eZ\Publish\Core\Search\Legacy\Content\IndexerGateway\$connection
$connection
Definition: Core/Search/Legacy/Content/IndexerGateway.php:26
eZ\Publish\Core\Search\Legacy\Content\IndexerGateway\buildCountingQuery
buildCountingQuery(QueryBuilder $query)
Definition: Core/Search/Legacy/Content/IndexerGateway.php:116
eZ\Publish\Core\Search\Legacy\Content\IndexerGateway\countAllContent
countAllContent()
Definition: Core/Search/Legacy/Content/IndexerGateway.php:73
eZ\Publish\Core\Search\Legacy\Content\IndexerGateway\countContentSince
countContentSince(DateTimeInterface $since)
Definition: Core/Search/Legacy/Content/IndexerGateway.php:41
eZ\Publish\Core\Search\Legacy\Content\IndexerGateway\buildQueryForContentInSubtree
buildQueryForContentInSubtree(string $locationPath)
Definition: Core/Search/Legacy/Content/IndexerGateway.php:92
eZ\Publish\Core\Search\Legacy\Content\IndexerGateway\fetchIteration
fetchIteration(ResultStatement $statement, int $iterationCount)
Definition: Core/Search/Legacy/Content/IndexerGateway.php:130
eZ\Publish\SPI\Persistence\Content\ContentInfo
This class provides all version independent information of the content object.
Definition: SPI/Persistence/Content/ContentInfo.php:17
eZ\Publish\SPI\Persistence\Content\ContentInfo\STATUS_PUBLISHED
const STATUS_PUBLISHED
Definition: SPI/Persistence/Content/ContentInfo.php:19
eZ\Publish\SPI\Search\Content\IndexerGateway
Definition: SPI/Search/Content/IndexerGateway.php:18
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.