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

Search/Legacy/Content/Gateway/DoctrineDatabase.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\Search\Legacy\Content\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\Gateway;
12 use eZ\Publish\Core\Persistence\Database\DatabaseHandler;
13 use eZ\Publish\SPI\Persistence\Content\ContentInfo;
14 use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
15 use eZ\Publish\API\Repository\Values\Content\VersionInfo;
16 use eZ\Publish\Core\Persistence\Database\SelectQuery;
17 use eZ\Publish\SPI\Persistence\Content\Language\Handler as LanguageHandler;
18 use PDO;
19
23 class DoctrineDatabase extends Gateway
24 {
30 protected $handler;
31
37 protected $criteriaConverter;
38
44 protected $sortClauseConverter;
45
51 protected $languageHandler;
52
61 public function __construct(
62 DatabaseHandler $handler,
63 CriteriaConverter $criteriaConverter,
64 SortClauseConverter $sortClauseConverter,
65 LanguageHandler $languageHandler
66 ) {
67 $this->handler = $handler;
68 $this->criteriaConverter = $criteriaConverter;
69 $this->sortClauseConverter = $sortClauseConverter;
70 $this->languageHandler = $languageHandler;
71 }
72
87 public function find(
88 Criterion $criterion,
89 $offset,
90 $limit,
91 array $sort = null,
92 array $languageFilter = [],
93 $doCount = true
94 ) {
95 $count = $doCount ? $this->getResultCount($criterion, $languageFilter) : null;
96
97 if (!$doCount && $limit === 0) {
98 throw new \RuntimeException('Invalid query, can not disable count and request 0 items at the same time');
99 }
100
101 if ($limit === 0 || ($count !== null && $count <= $offset)) {
102 return ['count' => $count, 'rows' => []];
103 }
104
105 $contentInfoList = $this->getContentInfoList($criterion, $sort, $offset, $limit, $languageFilter);
106
107 return [
108 'count' => $count,
109 'rows' => $contentInfoList,
110 ];
111 }
112
120 protected function getLanguageMask(array $languageSettings)
121 {
122 $mask = 0;
123 if ($languageSettings['useAlwaysAvailable']) {
124 $mask |= 1;
125 }
126
127 foreach ($languageSettings['languages'] as $languageCode) {
128 $mask |= $this->languageHandler->loadByLanguageCode($languageCode)->id;
129 }
130
131 return $mask;
132 }
133
143 protected function getQueryCondition(
144 Criterion $filter,
145 SelectQuery $query,
146 array $languageFilter
147 ) {
148 $condition = $query->expr->lAnd(
149 $this->criteriaConverter->convertCriteria($query, $filter, $languageFilter),
150 $query->expr->eq(
151 'ezcontentobject.status',
152 ContentInfo::STATUS_PUBLISHED
153 ),
154 $query->expr->eq(
155 'ezcontentobject_version.status',
156 VersionInfo::STATUS_PUBLISHED
157 )
158 );
159
160 // If not main-languages query
161 if (!empty($languageFilter['languages'])) {
162 $condition = $query->expr->lAnd(
163 $condition,
164 $query->expr->gt(
165 $query->expr->bitAnd(
166 $this->handler->quoteColumn('language_mask', 'ezcontentobject'),
167 $query->bindValue(
168 $this->getLanguageMask($languageFilter),
169 null,
170 PDO::PARAM_INT
171 )
172 ),
173 $query->bindValue(0, null, PDO::PARAM_INT)
174 )
175 );
176 }
177
178 return $condition;
179 }
180
189 protected function getResultCount(Criterion $filter, array $languageFilter)
190 {
191 $query = $this->handler->createSelectQuery();
192
193 $columnName = $this->handler->quoteColumn('id', 'ezcontentobject');
194 $query
195 ->select("COUNT( DISTINCT $columnName )")
196 ->from($this->handler->quoteTable('ezcontentobject'))
197 ->innerJoin(
198 'ezcontentobject_version',
199 'ezcontentobject.id',
200 'ezcontentobject_version.contentobject_id'
201 );
202
203 $query->where(
204 $this->getQueryCondition($filter, $query, $languageFilter)
205 );
206
207 $statement = $query->prepare();
208 $statement->execute();
209
210 return (int)$statement->fetchColumn();
211 }
212
224 protected function getContentInfoList(
225 Criterion $filter,
226 $sort,
227 $offset,
228 $limit,
229 array $languageFilter
230 ) {
231 $query = $this->handler->createSelectQuery();
232 $query->selectDistinct(
233 'ezcontentobject.*',
234 $this->handler->aliasedColumn($query, 'main_node_id', 'main_tree')
235 );
236
237 if ($sort !== null) {
238 $this->sortClauseConverter->applySelect($query, $sort);
239 }
240
241 $query->from(
242 $this->handler->quoteTable('ezcontentobject')
243 )->innerJoin(
244 'ezcontentobject_version',
245 'ezcontentobject.id',
246 'ezcontentobject_version.contentobject_id'
247 )->leftJoin(
248 $this->handler->alias(
249 $this->handler->quoteTable('ezcontentobject_tree'),
250 $this->handler->quoteIdentifier('main_tree')
251 ),
252 $query->expr->lAnd(
253 $query->expr->eq(
254 $this->handler->quoteColumn('contentobject_id', 'main_tree'),
255 $this->handler->quoteColumn('id', 'ezcontentobject')
256 ),
257 $query->expr->eq(
258 $this->handler->quoteColumn('main_node_id', 'main_tree'),
259 $this->handler->quoteColumn('node_id', 'main_tree')
260 )
261 )
262 );
263
264 if ($sort !== null) {
265 $this->sortClauseConverter->applyJoin($query, $sort, $languageFilter);
266 }
267
268 $query->where(
269 $this->getQueryCondition($filter, $query, $languageFilter)
270 );
271
272 if ($sort !== null) {
273 $this->sortClauseConverter->applyOrderBy($query);
274 }
275
276 $query->limit($limit, $offset);
277
278 $statement = $query->prepare();
279 $statement->execute();
280
281 return $statement->fetchAll(PDO::FETCH_ASSOC);
282 }
283 }
eZ\Publish\API\Repository\Values\Content\Query\Criterion
Definition: API/Repository/Values/Content/Query/Criterion.php:15
eZ\Publish\API\Repository\Values\Content\VersionInfo
Definition: API/Repository/Values/Content/VersionInfo.php:27
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\Gateway\DoctrineDatabase
Content locator gateway implementation using the Doctrine database.
Definition: Search/Legacy/Content/Gateway/DoctrineDatabase.php:24
eZ\Publish\Core\Search\Legacy\Content\Gateway\DoctrineDatabase\$languageHandler
$languageHandler
Definition: Search/Legacy/Content/Gateway/DoctrineDatabase.php:51
eZ\Publish\Core\Search\Legacy\Content\Gateway\DoctrineDatabase\getQueryCondition
getQueryCondition(Criterion $filter, SelectQuery $query, array $languageFilter)
Get query condition.
Definition: Search/Legacy/Content/Gateway/DoctrineDatabase.php:143
eZ\Publish\Core\Search\Legacy\Content\Gateway\DoctrineDatabase\$sortClauseConverter
$sortClauseConverter
Definition: Search/Legacy/Content/Gateway/DoctrineDatabase.php:44
eZ\Publish\Core\Search\Legacy\Content\Gateway\DoctrineDatabase\find
find(Criterion $criterion, $offset, $limit, array $sort=null, array $languageFilter=[], $doCount=true)
Returns a list of object satisfying the $filter.
Definition: Search/Legacy/Content/Gateway/DoctrineDatabase.php:87
eZ\Publish\Core\Search\Legacy\Content\Gateway\DoctrineDatabase\getContentInfoList
getContentInfoList(Criterion $filter, $sort, $offset, $limit, array $languageFilter)
Get sorted arrays of content IDs, which should be returned.
Definition: Search/Legacy/Content/Gateway/DoctrineDatabase.php:224
eZ\Publish\Core\Search\Legacy\Content\Gateway\DoctrineDatabase\$handler
$handler
Definition: Search/Legacy/Content/Gateway/DoctrineDatabase.php:30
eZ\Publish\Core\Search\Legacy\Content\Gateway\DoctrineDatabase\getResultCount
getResultCount(Criterion $filter, array $languageFilter)
Get result count.
Definition: Search/Legacy/Content/Gateway/DoctrineDatabase.php:189
eZ\Publish\Core\Search\Legacy\Content\Gateway\DoctrineDatabase\__construct
__construct(DatabaseHandler $handler, CriteriaConverter $criteriaConverter, SortClauseConverter $sortClauseConverter, LanguageHandler $languageHandler)
Construct from handler handler.
Definition: Search/Legacy/Content/Gateway/DoctrineDatabase.php:61
eZ\Publish\Core\Search\Legacy\Content\Gateway\DoctrineDatabase\$criteriaConverter
$criteriaConverter
Definition: Search/Legacy/Content/Gateway/DoctrineDatabase.php:37
eZ\Publish\Core\Search\Legacy\Content\Gateway\DoctrineDatabase\getLanguageMask
getLanguageMask(array $languageSettings)
Generates a language mask from the given $languageSettings.
Definition: Search/Legacy/Content/Gateway/DoctrineDatabase.php:120
eZ\Publish\Core\Search\Legacy\Content\Gateway
The Content Search Gateway provides the implementation for one database to retrieve the desired conte...
Definition: Search/Legacy/Content/Gateway.php:16
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\Core\Persistence\Database\DatabaseHandler
Interface for relational database abstractions supported by eZ.
Definition: DatabaseHandler.php:18
eZ\Publish\Core\Persistence\Database\Query\bindValue
bindValue($value, $placeHolder=null, $type=PDO::PARAM_STR)
Binds the value $value to the specified variable name $placeHolder.
eZ\Publish\Core\Persistence\Database\SelectQuery
Definition: SelectQuery.php:16
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+.