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

Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway;
8
9 use Doctrine\DBAL\Connection;
10 use Doctrine\DBAL\Query\QueryBuilder;
11 use eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway;
12 use eZ\Publish\SPI\Persistence\Content\Language;
13 use eZ\Publish\Core\Persistence\Database\DatabaseHandler;
14 use eZ\Publish\Core\Persistence\Database\Query;
15 use RuntimeException;
16
20 class DoctrineDatabase extends Gateway
21 {
29 protected $dbHandler;
30
36 protected $connection;
37
43 public function __construct(DatabaseHandler $dbHandler)
44 {
45 $this->dbHandler = $dbHandler;
46 $this->connection = $dbHandler->getConnection();
47 }
48
56 public function insertLanguage(Language $language)
57 {
58 $query = $this->dbHandler->createSelectQuery();
59 $query->select(
60 $query->expr->max($this->dbHandler->quoteColumn('id'))
61 )->from($this->dbHandler->quoteTable('ezcontent_language'));
62
63 $statement = $query->prepare();
64 $statement->execute();
65
66 $lastId = (int)$statement->fetchColumn();
67
68 // Legacy only supports 8 * PHP_INT_SIZE - 2 languages:
69 // One bit cannot be used because PHP uses signed integers and a second one is reserved for the
70 // "always available flag".
71 if ($lastId == (2 ** (8 * PHP_INT_SIZE - 2))) {
72 throw new RuntimeException('Maximum number of languages reached!');
73 }
74 // Next power of 2 for bit masks
75 $nextId = ($lastId !== 0 ? $lastId << 1 : 2);
76
77 $query = $this->dbHandler->createInsertQuery();
78 $query->insertInto(
79 $this->dbHandler->quoteTable('ezcontent_language')
80 )->set(
81 $this->dbHandler->quoteColumn('id'),
82 $query->bindValue($nextId, null, \PDO::PARAM_INT)
83 );
84 $this->setCommonLanguageColumns($query, $language);
85
86 $query->prepare()->execute();
87
88 return $nextId;
89 }
90
97 protected function setCommonLanguageColumns(Query $query, Language $language)
98 {
99 $query->set(
100 $this->dbHandler->quoteColumn('locale'),
101 $query->bindValue($language->languageCode)
102 )->set(
103 $this->dbHandler->quoteColumn('name'),
104 $query->bindValue($language->name)
105 )->set(
106 $this->dbHandler->quoteColumn('disabled'),
107 $query->bindValue(
108 ((int)(!$language->isEnabled)),
109 null,
110 \PDO::PARAM_INT
111 )
112 );
113 }
114
120 public function updateLanguage(Language $language)
121 {
122 $query = $this->dbHandler->createUpdateQuery();
123 $query->update($this->dbHandler->quoteTable('ezcontent_language'));
124
125 $this->setCommonLanguageColumns($query, $language);
126
127 $query->where(
128 $query->expr->eq(
129 $this->dbHandler->quoteColumn('id'),
130 $query->bindValue($language->id, null, \PDO::PARAM_INT)
131 )
132 );
133
134 $query->prepare()->execute();
135 }
136
140 public function loadLanguageListData(array $ids): iterable
141 {
142 $query = $this->createFindQuery();
143 $query
144 ->where('id IN (:ids)')
145 ->setParameter('ids', $ids, Connection::PARAM_INT_ARRAY);
146
147 return $query->execute()->fetchAll();
148 }
149
153 public function loadLanguageListDataByLanguageCode(array $languageCodes): iterable
154 {
155 $query = $this->createFindQuery();
156 $query
157 ->where('locale IN (:locale)')
158 ->setParameter('locale', $languageCodes, Connection::PARAM_STR_ARRAY);
159
160 return $query->execute()->fetchAll();
161 }
162
166 protected function createFindQuery(): QueryBuilder
167 {
168 $query = $this->connection->createQueryBuilder();
169 $query
170 ->select('id', 'locale', 'name', 'disabled')
171 ->from('ezcontent_language');
172
173 return $query;
174 }
175
181 public function loadAllLanguagesData()
182 {
183 $query = $this->createFindQuery();
184
185 return $query->execute()->fetchAll();
186 }
187
193 public function deleteLanguage($id)
194 {
195 $query = $this->dbHandler->createDeleteQuery();
196 $query->deleteFrom(
197 $this->dbHandler->quoteTable('ezcontent_language')
198 )->where(
199 $query->expr->eq(
200 $this->dbHandler->quoteColumn('id'),
201 $query->bindValue($id, null, \PDO::PARAM_INT)
202 )
203 );
204
205 $query->prepare()->execute();
206 }
207
215 public function canDeleteLanguage($id)
216 {
217 $query = $this->dbHandler->createSelectQuery();
218 $query->select(
219 $query->alias($query->expr->count('*'), 'count')
220 )->from(
221 $this->dbHandler->quoteTable('ezcobj_state')
222 )->where(
223 $query->expr->lOr(
224 $query->expr->eq(
225 $this->dbHandler->quoteColumn('default_language_id'),
226 $query->bindValue($id, null, \PDO::PARAM_INT)
227 ),
228 $query->expr->gt(
229 $query->expr->bitAnd(
230 $this->dbHandler->quoteColumn('language_mask'),
231 $query->bindValue($id, null, \PDO::PARAM_INT)
232 ),
233 0
234 )
235 )
236 );
237
238 $statement = $query->prepare();
239 $statement->execute();
240
241 if ($statement->fetchColumn() > 0) {
242 return false;
243 }
244
245 $query = $this->dbHandler->createSelectQuery();
246 $query->select(
247 $query->alias($query->expr->count('*'), 'count')
248 )->from(
249 $this->dbHandler->quoteTable('ezcobj_state_group')
250 )->where(
251 $query->expr->lOr(
252 $query->expr->eq(
253 $this->dbHandler->quoteColumn('default_language_id'),
254 $query->bindValue($id, null, \PDO::PARAM_INT)
255 ),
256 $query->expr->gt(
257 $query->expr->bitAnd(
258 $this->dbHandler->quoteColumn('language_mask'),
259 $query->bindValue($id, null, \PDO::PARAM_INT)
260 ),
261 0
262 )
263 )
264 );
265
266 $statement = $query->prepare();
267 $statement->execute();
268
269 if ($statement->fetchColumn() > 0) {
270 return false;
271 }
272
273 $query = $this->dbHandler->createSelectQuery();
274 $query->select(
275 $query->alias($query->expr->count('*'), 'count')
276 )->from(
277 $this->dbHandler->quoteTable('ezcobj_state_group_language')
278 )->where(
279 $query->expr->gt(
280 $query->expr->bitAnd(
281 $this->dbHandler->quoteColumn('language_id'),
282 $query->bindValue($id, null, \PDO::PARAM_INT)
283 ),
284 0
285 )
286 );
287
288 $statement = $query->prepare();
289 $statement->execute();
290
291 if ($statement->fetchColumn() > 0) {
292 return false;
293 }
294
295 $query = $this->dbHandler->createSelectQuery();
296 $query->select(
297 $query->alias($query->expr->count('*'), 'count')
298 )->from(
299 $this->dbHandler->quoteTable('ezcobj_state_language')
300 )->where(
301 $query->expr->gt(
302 $query->expr->bitAnd(
303 $this->dbHandler->quoteColumn('language_id'),
304 $query->bindValue($id, null, \PDO::PARAM_INT)
305 ),
306 0
307 )
308 );
309
310 $statement = $query->prepare();
311 $statement->execute();
312
313 if ($statement->fetchColumn() > 0) {
314 return false;
315 }
316
317 $query = $this->dbHandler->createSelectQuery();
318 $query->select(
319 $query->alias($query->expr->count('*'), 'count')
320 )->from(
321 $this->dbHandler->quoteTable('ezcontentclass')
322 )->where(
323 $query->expr->lOr(
324 $query->expr->eq(
325 $this->dbHandler->quoteColumn('initial_language_id'),
326 $query->bindValue($id, null, \PDO::PARAM_INT)
327 ),
328 $query->expr->gt(
329 $query->expr->bitAnd(
330 $this->dbHandler->quoteColumn('language_mask'),
331 $query->bindValue($id, null, \PDO::PARAM_INT)
332 ),
333 0
334 )
335 )
336 );
337
338 $statement = $query->prepare();
339 $statement->execute();
340
341 if ($statement->fetchColumn() > 0) {
342 return false;
343 }
344
345 $query = $this->dbHandler->createSelectQuery();
346 $query->select(
347 $query->alias($query->expr->count('*'), 'count')
348 )->from(
349 $this->dbHandler->quoteTable('ezcontentclass_name')
350 )->where(
351 $query->expr->gt(
352 $query->expr->bitAnd(
353 $this->dbHandler->quoteColumn('language_id'),
354 $query->bindValue($id, null, \PDO::PARAM_INT)
355 ),
356 0
357 )
358 );
359
360 $statement = $query->prepare();
361 $statement->execute();
362
363 if ($statement->fetchColumn() > 0) {
364 return false;
365 }
366
367 $query = $this->dbHandler->createSelectQuery();
368 $query->select(
369 $query->alias($query->expr->count('*'), 'count')
370 )->from(
371 $this->dbHandler->quoteTable('ezcontentobject')
372 )->where(
373 $query->expr->lOr(
374 $query->expr->eq(
375 $this->dbHandler->quoteColumn('initial_language_id'),
376 $query->bindValue($id, null, \PDO::PARAM_INT)
377 ),
378 $query->expr->gt(
379 $query->expr->bitAnd(
380 $this->dbHandler->quoteColumn('language_mask'),
381 $query->bindValue($id, null, \PDO::PARAM_INT)
382 ),
383 0
384 )
385 )
386 );
387
388 $statement = $query->prepare();
389 $statement->execute();
390
391 if ($statement->fetchColumn() > 0) {
392 return false;
393 }
394
395 $query = $this->dbHandler->createSelectQuery();
396 $query->select(
397 $query->alias($query->expr->count('*'), 'count')
398 )->from(
399 $this->dbHandler->quoteTable('ezcontentobject_attribute')
400 )->where(
401 $query->expr->gt(
402 $query->expr->bitAnd(
403 $this->dbHandler->quoteColumn('language_id'),
404 $query->bindValue($id, null, \PDO::PARAM_INT)
405 ),
406 0
407 )
408 );
409
410 $statement = $query->prepare();
411 $statement->execute();
412
413 if ($statement->fetchColumn() > 0) {
414 return false;
415 }
416
417 $query = $this->dbHandler->createSelectQuery();
418 $query->select(
419 $query->alias($query->expr->count('*'), 'count')
420 )->from(
421 $this->dbHandler->quoteTable('ezcontentobject_name')
422 )->where(
423 $query->expr->gt(
424 $query->expr->bitAnd(
425 $this->dbHandler->quoteColumn('language_id'),
426 $query->bindValue($id, null, \PDO::PARAM_INT)
427 ),
428 0
429 )
430 );
431
432 $statement = $query->prepare();
433 $statement->execute();
434
435 if ($statement->fetchColumn() > 0) {
436 return false;
437 }
438
439 $query = $this->dbHandler->createSelectQuery();
440 $query->select(
441 $query->alias($query->expr->count('*'), 'count')
442 )->from(
443 $this->dbHandler->quoteTable('ezcontentobject_version')
444 )->where(
445 $query->expr->lOr(
446 $query->expr->eq(
447 $this->dbHandler->quoteColumn('initial_language_id'),
448 $query->bindValue($id, null, \PDO::PARAM_INT)
449 ),
450 $query->expr->gt(
451 $query->expr->bitAnd(
452 $this->dbHandler->quoteColumn('language_mask'),
453 $query->bindValue($id, null, \PDO::PARAM_INT)
454 ),
455 0
456 )
457 )
458 );
459
460 $statement = $query->prepare();
461 $statement->execute();
462
463 if ($statement->fetchColumn() > 0) {
464 return false;
465 }
466
467 $query = $this->dbHandler->createSelectQuery();
468 $query->select(
469 $query->alias($query->expr->count('*'), 'count')
470 )->from(
471 $this->dbHandler->quoteTable('ezurlalias_ml')
472 )->where(
473 $query->expr->gt(
474 $query->expr->bitAnd(
475 $this->dbHandler->quoteColumn('lang_mask'),
476 $query->bindValue($id, null, \PDO::PARAM_INT)
477 ),
478 0
479 )
480 );
481
482 $statement = $query->prepare();
483 $statement->execute();
484
485 return $statement->fetchColumn() == 0;
486 }
487 }
eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase
Doctrine database based Language Gateway.
Definition: Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php:21
eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase\__construct
__construct(DatabaseHandler $dbHandler)
Creates a new Doctrine database Section Gateway.
Definition: Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php:43
eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase\updateLanguage
updateLanguage(Language $language)
Updates the data of the given $language.
Definition: Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php:120
eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase\deleteLanguage
deleteLanguage($id)
Deletes the language with $id.
Definition: Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php:193
eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase\loadAllLanguagesData
loadAllLanguagesData()
Loads the data for all languages.
Definition: Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php:181
eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase\$dbHandler
$dbHandler
Definition: Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php:29
eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase\loadLanguageListDataByLanguageCode
loadLanguageListDataByLanguageCode(array $languageCodes)
{Loads data list for Languages by $languageCodes (eg: eng-GB).string[][]|iterable}
Definition: Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php:153
eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase\createFindQuery
createFindQuery()
Creates a Language find query.
Definition: Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php:166
eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase\$connection
$connection
Definition: Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php:36
eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase\setCommonLanguageColumns
setCommonLanguageColumns(Query $query, Language $language)
Sets columns in $query from $language.
Definition: Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php:97
eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase\canDeleteLanguage
canDeleteLanguage($id)
Check whether a language may be deleted.
Definition: Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php:215
eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase\loadLanguageListData
loadLanguageListData(array $ids)
{Loads data list for the Language with $ids.string[][]|iterable}
Definition: Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php:140
eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase\insertLanguage
insertLanguage(Language $language)
Inserts the given $language.
Definition: Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php:56
eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway
Language Handler.
Definition: Persistence/Legacy/Content/Language/Gateway.php:15
eZ\Publish\SPI\Persistence\Content\Language
Struct containing accessible properties on Language entities.
Definition: SPI/Persistence/Content/Language.php:15
eZ\Publish\Core\Persistence\Database\DatabaseHandler
Interface for relational database abstractions supported by eZ.
Definition: DatabaseHandler.php:18
eZ\Publish\Core\Persistence\Database\Query
Definition: Core/Persistence/Database/Query.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\Legacy\Content\Language\Gateway
Definition: Persistence/Legacy/Content/Language/Gateway/DoctrineDatabase.php:7
eZ\Publish\SPI\Persistence\Content\Language
Definition: SPI/Persistence/Content/Language/CreateStruct.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.