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

Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\Search\Legacy\Content\Location\Gateway;
8
9 use eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter;
10 use eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseConverter;
11 use eZ\Publish\Core\Search\Legacy\Content\Location\Gateway;
12 use eZ\Publish\Core\Persistence\Database\DatabaseHandler;
13 use eZ\Publish\API\Repository\Values\Content\Query;
14 use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
15 use eZ\Publish\SPI\Persistence\Content\Language\Handler as LanguageHandler;
16 use PDO;
17
21 class DoctrineDatabase extends Gateway
22 {
27 const MAX_LIMIT = 1073741824;
28
34 protected $handler;
35
37 private $criteriaConverter;
38
40 private $sortClauseConverter;
41
47 protected $languageHandler;
48
57 public function __construct(
58 DatabaseHandler $handler,
59 CriteriaConverter $criteriaConverter,
60 SortClauseConverter $sortClauseConverter,
61 LanguageHandler $languageHandler
62 ) {
63 $this->handler = $handler;
64 $this->criteriaConverter = $criteriaConverter;
65 $this->sortClauseConverter = $sortClauseConverter;
66 $this->languageHandler = $languageHandler;
67 }
68
81 public function find(
82 Criterion $criterion,
83 $offset,
84 $limit,
85 array $sortClauses = null,
86 array $languageFilter = [],
87 $doCount = true
88 ) {
89 $count = $doCount ? $this->getTotalCount($criterion, $languageFilter) : null;
90
91 if (!$doCount && $limit === 0) {
92 throw new \RuntimeException('Invalid query, can not disable count and request 0 items at the same time');
93 }
94
95 if ($limit === 0 || ($count !== null && $count <= $offset)) {
96 return ['count' => $count, 'rows' => []];
97 }
98
99 $selectQuery = $this->handler->createSelectQuery();
100 $selectQuery->select(
101 'ezcontentobject_tree.*',
102 $this->handler->quoteColumn('language_mask', 'ezcontentobject'),
103 $this->handler->quoteColumn('initial_language_id', 'ezcontentobject')
104 );
105
106 if ($sortClauses !== null) {
107 $this->sortClauseConverter->applySelect($selectQuery, $sortClauses);
108 }
109
110 $selectQuery
111 ->from($this->handler->quoteTable('ezcontentobject_tree'))
112 ->innerJoin(
113 'ezcontentobject',
114 'ezcontentobject_tree.contentobject_id',
115 'ezcontentobject.id'
116 )
117 ->innerJoin(
118 'ezcontentobject_version',
119 'ezcontentobject.id',
120 'ezcontentobject_version.contentobject_id'
121 );
122
123 if ($sortClauses !== null) {
124 $this->sortClauseConverter->applyJoin($selectQuery, $sortClauses, $languageFilter);
125 }
126
127 $selectQuery->where(
128 $this->criteriaConverter->convertCriteria($selectQuery, $criterion, $languageFilter),
129 $selectQuery->expr->eq(
130 'ezcontentobject.status',
131 //ContentInfo::STATUS_PUBLISHED
132 $selectQuery->bindValue(1, null, PDO::PARAM_INT)
133 ),
134 $selectQuery->expr->eq(
135 'ezcontentobject_version.status',
136 //VersionInfo::STATUS_PUBLISHED
137 $selectQuery->bindValue(1, null, PDO::PARAM_INT)
138 ),
139 $selectQuery->expr->neq(
140 $this->handler->quoteColumn('depth', 'ezcontentobject_tree'),
141 $selectQuery->bindValue(0, null, PDO::PARAM_INT)
142 )
143 );
144
145 // If not main-languages query
146 if (!empty($languageFilter['languages'])) {
147 $selectQuery->where(
148 $selectQuery->expr->gt(
149 $selectQuery->expr->bitAnd(
150 $this->handler->quoteColumn('language_mask', 'ezcontentobject'),
151 $selectQuery->bindValue(
152 $this->getLanguageMask($languageFilter),
153 null,
154 PDO::PARAM_INT
155 )
156 ),
157 $selectQuery->bindValue(0, null, PDO::PARAM_INT)
158 )
159 );
160 }
161
162 if ($sortClauses !== null) {
163 $this->sortClauseConverter->applyOrderBy($selectQuery);
164 }
165
166 $selectQuery->limit($limit, $offset);
167
168 $statement = $selectQuery->prepare();
169 $statement->execute();
170
171 return [
172 'count' => $count,
173 'rows' => $statement->fetchAll(PDO::FETCH_ASSOC),
174 ];
175 }
176
185 protected function getTotalCount(Criterion $criterion, array $languageFilter)
186 {
187 $query = $this->handler->createSelectQuery();
188 $query
189 ->select($query->alias($query->expr->count('*'), 'count'))
190 ->from($this->handler->quoteTable('ezcontentobject_tree'))
191 ->innerJoin(
192 'ezcontentobject',
193 'ezcontentobject_tree.contentobject_id',
194 'ezcontentobject.id'
195 )
196 ->innerJoin(
197 'ezcontentobject_version',
198 'ezcontentobject.id',
199 'ezcontentobject_version.contentobject_id'
200 );
201
202 $query->where(
203 $this->criteriaConverter->convertCriteria($query, $criterion, $languageFilter),
204 $query->expr->eq(
205 'ezcontentobject.status',
206 //ContentInfo::STATUS_PUBLISHED
207 $query->bindValue(1, null, PDO::PARAM_INT)
208 ),
209 $query->expr->eq(
210 'ezcontentobject_version.status',
211 //VersionInfo::STATUS_PUBLISHED
212 $query->bindValue(1, null, PDO::PARAM_INT)
213 ),
214 $query->expr->neq(
215 $this->handler->quoteColumn('depth', 'ezcontentobject_tree'),
216 $query->bindValue(0, null, PDO::PARAM_INT)
217 )
218 );
219
220 // If not main-languages query
221 if (!empty($languageFilter['languages'])) {
222 $query->where(
223 $query->expr->gt(
224 $query->expr->bitAnd(
225 $this->handler->quoteColumn('language_mask', 'ezcontentobject'),
226 $query->bindValue(
227 $this->getLanguageMask($languageFilter),
228 null,
229 PDO::PARAM_INT
230 )
231 ),
232 $query->bindValue(0, null, PDO::PARAM_INT)
233 )
234 );
235 }
236
237 $statement = $query->prepare();
238 $statement->execute();
239
240 return (int)$statement->fetchColumn();
241 }
242
250 protected function getLanguageMask(array $languageFilter)
251 {
252 if (!isset($languageFilter['languages'])) {
253 $languageFilter['languages'] = [];
254 }
255
256 if (!isset($languageFilter['useAlwaysAvailable'])) {
257 $languageFilter['useAlwaysAvailable'] = true;
258 }
259
260 $mask = 0;
261 if ($languageFilter['useAlwaysAvailable']) {
262 $mask |= 1;
263 }
264
265 foreach ($languageFilter['languages'] as $languageCode) {
266 $mask |= $this->languageHandler->loadByLanguageCode($languageCode)->id;
267 }
268
269 return $mask;
270 }
271 }
eZ\Publish\API\Repository\Values\Content\Query\Criterion
Definition: API/Repository/Values/Content/Query/Criterion.php:15
eZ\Publish\API\Repository\Values\Content\Query
This class is used to perform a Content query.
Definition: API/Repository/Values/Content/Query.php:15
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter
Content locator gateway implementation using the DoctrineDatabase.
Definition: Search/Legacy/Content/Common/Gateway/CriteriaConverter.php:17
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseConverter
Converter manager for sort clauses.
Definition: SortClauseConverter.php:17
eZ\Publish\Core\Search\Legacy\Content\Location\Gateway\DoctrineDatabase
Location gateway implementation using the Doctrine database.
Definition: Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php:22
eZ\Publish\Core\Search\Legacy\Content\Location\Gateway\DoctrineDatabase\getLanguageMask
getLanguageMask(array $languageFilter)
Generates a language mask from the given $languageFilter.
Definition: Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php:250
eZ\Publish\Core\Search\Legacy\Content\Location\Gateway\DoctrineDatabase\find
find(Criterion $criterion, $offset, $limit, array $sortClauses=null, array $languageFilter=[], $doCount=true)
Returns total count and data for all Locations satisfying the parameters.
Definition: Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php:81
eZ\Publish\Core\Search\Legacy\Content\Location\Gateway\DoctrineDatabase\$languageHandler
$languageHandler
Definition: Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php:47
eZ\Publish\Core\Search\Legacy\Content\Location\Gateway\DoctrineDatabase\$handler
$handler
Definition: Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php:34
eZ\Publish\Core\Search\Legacy\Content\Location\Gateway\DoctrineDatabase\$sortClauseConverter
$sortClauseConverter
Definition: Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php:40
eZ\Publish\Core\Search\Legacy\Content\Location\Gateway\DoctrineDatabase\getTotalCount
getTotalCount(Criterion $criterion, array $languageFilter)
Returns total results count for $criterion and $sortClauses.
Definition: Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php:185
eZ\Publish\Core\Search\Legacy\Content\Location\Gateway\DoctrineDatabase\$criteriaConverter
$criteriaConverter
Definition: Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php:37
eZ\Publish\Core\Search\Legacy\Content\Location\Gateway\DoctrineDatabase\MAX_LIMIT
const MAX_LIMIT
2^30, since PHP_INT_MAX can cause overflows in DB systems, if PHP is run on 64 bit systems.
Definition: Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php:27
eZ\Publish\Core\Search\Legacy\Content\Location\Gateway\DoctrineDatabase\__construct
__construct(DatabaseHandler $handler, CriteriaConverter $criteriaConverter, SortClauseConverter $sortClauseConverter, LanguageHandler $languageHandler)
Construct from database handler.
Definition: Search/Legacy/Content/Location/Gateway/DoctrineDatabase.php:57
eZ\Publish\Core\Search\Legacy\Content\Location\Gateway
Base class for location search gateways.
Definition: Search/Legacy/Content/Location/Gateway.php:15
eZ\Publish\Core\Persistence\Database\DatabaseHandler
Interface for relational database abstractions supported by eZ.
Definition: DatabaseHandler.php:18
eZ\Publish\SPI\Persistence\Content\Language\Handler
Language Handler interface.
Definition: SPI/Persistence/Content/Language/Handler.php:15
eZ\Publish\API\Repository\Values\Content\Query\Criterion
Definition: API/Repository/Values/Content/Query/Criterion/Ancestor.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.