1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the DoctrineDatabase ObjectState Gateway class. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
namespace eZ\Publish\Core\Persistence\Legacy\Content\ObjectState\Gateway; |
10
|
|
|
|
11
|
|
|
use Doctrine\DBAL\ParameterType; |
12
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\ObjectState\Gateway; |
13
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\Language\MaskGenerator; |
14
|
|
|
use eZ\Publish\Core\Persistence\Database\DatabaseHandler; |
15
|
|
|
use eZ\Publish\SPI\Persistence\Content\ObjectState; |
16
|
|
|
use eZ\Publish\SPI\Persistence\Content\ObjectState\Group; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* ObjectState Doctrine database Gateway. |
20
|
|
|
*/ |
21
|
|
|
class DoctrineDatabase extends Gateway |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Database handler. |
25
|
|
|
* |
26
|
|
|
* @var \eZ\Publish\Core\Persistence\Database\DatabaseHandler |
27
|
|
|
* @deprecated Start to use DBAL $connection instead. |
28
|
|
|
*/ |
29
|
|
|
protected $dbHandler; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Language mask generator. |
33
|
|
|
* |
34
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\Content\Language\MaskGenerator |
35
|
|
|
*/ |
36
|
|
|
protected $maskGenerator; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Creates a new Doctrine database ObjectState Gateway. |
40
|
|
|
* |
41
|
|
|
* @param \eZ\Publish\Core\Persistence\Database\DatabaseHandler $dbHandler |
42
|
|
|
* @param \eZ\Publish\Core\Persistence\Legacy\Content\Language\MaskGenerator $maskGenerator |
43
|
|
|
*/ |
44
|
|
|
public function __construct(DatabaseHandler $dbHandler, MaskGenerator $maskGenerator) |
45
|
|
|
{ |
46
|
|
|
$this->dbHandler = $dbHandler; |
47
|
|
|
$this->maskGenerator = $maskGenerator; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Loads data for an object state. |
52
|
|
|
* |
53
|
|
|
* @param mixed $stateId |
54
|
|
|
* |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
|
View Code Duplication |
public function loadObjectStateData($stateId) |
58
|
|
|
{ |
59
|
|
|
$query = $this->createObjectStateFindQuery(); |
60
|
|
|
$query->where( |
61
|
|
|
$query->expr->eq( |
62
|
|
|
$this->dbHandler->quoteColumn('id', 'ezcobj_state'), |
63
|
|
|
$query->bindValue($stateId, null, \PDO::PARAM_INT) |
64
|
|
|
) |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
$statement = $query->prepare(); |
68
|
|
|
$statement->execute(); |
69
|
|
|
|
70
|
|
|
return $statement->fetchAll(\PDO::FETCH_ASSOC); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Loads data for an object state by identifier. |
75
|
|
|
* |
76
|
|
|
* @param string $identifier |
77
|
|
|
* @param mixed $groupId |
78
|
|
|
* |
79
|
|
|
* @return array |
80
|
|
|
*/ |
81
|
|
View Code Duplication |
public function loadObjectStateDataByIdentifier($identifier, $groupId) |
82
|
|
|
{ |
83
|
|
|
$query = $this->createObjectStateFindQuery(); |
84
|
|
|
$query->where( |
85
|
|
|
$query->expr->lAnd( |
86
|
|
|
$query->expr->eq( |
87
|
|
|
$this->dbHandler->quoteColumn('identifier', 'ezcobj_state'), |
88
|
|
|
$query->bindValue($identifier, null, \PDO::PARAM_STR) |
89
|
|
|
), |
90
|
|
|
$query->expr->eq( |
91
|
|
|
$this->dbHandler->quoteColumn('group_id', 'ezcobj_state'), |
92
|
|
|
$query->bindValue($groupId, null, \PDO::PARAM_INT) |
93
|
|
|
) |
94
|
|
|
) |
95
|
|
|
); |
96
|
|
|
|
97
|
|
|
$statement = $query->prepare(); |
98
|
|
|
$statement->execute(); |
99
|
|
|
|
100
|
|
|
return $statement->fetchAll(\PDO::FETCH_ASSOC); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Loads data for all object states belonging to group with $groupId ID. |
105
|
|
|
* |
106
|
|
|
* @param mixed $groupId |
107
|
|
|
* |
108
|
|
|
* @return array |
109
|
|
|
*/ |
110
|
|
|
public function loadObjectStateListData($groupId) |
111
|
|
|
{ |
112
|
|
|
$query = $this->createObjectStateFindQuery(); |
113
|
|
|
$query->where( |
114
|
|
|
$query->expr->eq( |
115
|
|
|
$this->dbHandler->quoteColumn('group_id', 'ezcobj_state'), |
116
|
|
|
$query->bindValue($groupId, null, \PDO::PARAM_INT) |
117
|
|
|
) |
118
|
|
|
)->orderBy($this->dbHandler->quoteColumn('priority', 'ezcobj_state'), $query::ASC); |
119
|
|
|
|
120
|
|
|
$statement = $query->prepare(); |
121
|
|
|
$statement->execute(); |
122
|
|
|
|
123
|
|
|
$rows = array(); |
124
|
|
|
while ($row = $statement->fetch(\PDO::FETCH_ASSOC)) { |
125
|
|
|
$rows[$row['ezcobj_state_id']][] = $row; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
return array_values($rows); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Loads data for an object state group. |
133
|
|
|
* |
134
|
|
|
* @param mixed $groupId |
135
|
|
|
* |
136
|
|
|
* @return array |
137
|
|
|
*/ |
138
|
|
View Code Duplication |
public function loadObjectStateGroupData($groupId) |
139
|
|
|
{ |
140
|
|
|
$query = $this->createObjectStateGroupFindQuery(); |
141
|
|
|
$query->where( |
142
|
|
|
$query->expr->eq( |
143
|
|
|
$this->dbHandler->quoteColumn('id', 'ezcobj_state_group'), |
144
|
|
|
$query->bindValue($groupId, null, \PDO::PARAM_INT) |
145
|
|
|
) |
146
|
|
|
); |
147
|
|
|
|
148
|
|
|
$statement = $query->prepare(); |
149
|
|
|
$statement->execute(); |
150
|
|
|
|
151
|
|
|
return $statement->fetchAll(\PDO::FETCH_ASSOC); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Loads data for an object state group by identifier. |
156
|
|
|
* |
157
|
|
|
* @param string $identifier |
158
|
|
|
* |
159
|
|
|
* @return array |
160
|
|
|
*/ |
161
|
|
View Code Duplication |
public function loadObjectStateGroupDataByIdentifier($identifier) |
162
|
|
|
{ |
163
|
|
|
$query = $this->createObjectStateGroupFindQuery(); |
164
|
|
|
$query->where( |
165
|
|
|
$query->expr->eq( |
166
|
|
|
$this->dbHandler->quoteColumn('identifier', 'ezcobj_state_group'), |
167
|
|
|
$query->bindValue($identifier, null, \PDO::PARAM_STR) |
168
|
|
|
) |
169
|
|
|
); |
170
|
|
|
|
171
|
|
|
$statement = $query->prepare(); |
172
|
|
|
$statement->execute(); |
173
|
|
|
|
174
|
|
|
return $statement->fetchAll(\PDO::FETCH_ASSOC); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Loads data for all object state groups, filtered by $offset and $limit. |
179
|
|
|
* |
180
|
|
|
* @param int $offset |
181
|
|
|
* @param int $limit |
182
|
|
|
* |
183
|
|
|
* @return array |
184
|
|
|
*/ |
185
|
|
|
public function loadObjectStateGroupListData($offset, $limit) |
186
|
|
|
{ |
187
|
|
|
$query = $this->createObjectStateGroupFindQuery(); |
188
|
|
|
$query->limit($limit > 0 ? $limit : PHP_INT_MAX, $offset); |
189
|
|
|
|
190
|
|
|
$statement = $query->prepare(); |
191
|
|
|
$statement->execute(); |
192
|
|
|
|
193
|
|
|
$rows = array(); |
194
|
|
|
while ($row = $statement->fetch(\PDO::FETCH_ASSOC)) { |
195
|
|
|
$rows[$row['ezcobj_state_group_id']][] = $row; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
return array_values($rows); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Inserts a new object state into database. |
203
|
|
|
* |
204
|
|
|
* @param \eZ\Publish\SPI\Persistence\Content\ObjectState $objectState |
205
|
|
|
* @param int $groupId |
206
|
|
|
*/ |
207
|
|
|
public function insertObjectState(ObjectState $objectState, $groupId) |
208
|
|
|
{ |
209
|
|
|
$query = $this->dbHandler->createSelectQuery(); |
210
|
|
|
$query->select( |
211
|
|
|
$query->expr->max($this->dbHandler->quoteColumn('priority')) |
212
|
|
|
)->from( |
213
|
|
|
$this->dbHandler->quoteTable('ezcobj_state') |
214
|
|
|
)->where( |
215
|
|
|
$query->expr->eq( |
216
|
|
|
$this->dbHandler->quoteColumn('group_id'), |
217
|
|
|
$query->bindValue($groupId, null, \PDO::PARAM_INT) |
218
|
|
|
) |
219
|
|
|
); |
220
|
|
|
|
221
|
|
|
$statement = $query->prepare(); |
222
|
|
|
$statement->execute(); |
223
|
|
|
|
224
|
|
|
$maxPriority = $statement->fetchColumn(); |
225
|
|
|
|
226
|
|
|
$objectState->priority = $maxPriority === null ? 0 : (int)$maxPriority + 1; |
227
|
|
|
$objectState->groupId = (int)$groupId; |
228
|
|
|
|
229
|
|
|
$query = $this->dbHandler->createInsertQuery(); |
230
|
|
|
$query->insertInto( |
231
|
|
|
$this->dbHandler->quoteTable('ezcobj_state') |
232
|
|
|
)->set( |
233
|
|
|
$this->dbHandler->quoteColumn('id'), |
234
|
|
|
$this->dbHandler->getAutoIncrementValue('ezcobj_state', 'id') |
235
|
|
|
)->set( |
236
|
|
|
$this->dbHandler->quoteColumn('group_id'), |
237
|
|
|
$query->bindValue($objectState->groupId, null, \PDO::PARAM_INT) |
238
|
|
|
)->set( |
239
|
|
|
$this->dbHandler->quoteColumn('default_language_id'), |
240
|
|
|
$query->bindValue( |
241
|
|
|
$this->maskGenerator->generateLanguageIndicator($objectState->defaultLanguage, false), |
242
|
|
|
null, |
243
|
|
|
\PDO::PARAM_INT |
244
|
|
|
) |
245
|
|
|
)->set( |
246
|
|
|
$this->dbHandler->quoteColumn('identifier'), |
247
|
|
|
$query->bindValue($objectState->identifier) |
248
|
|
|
)->set( |
249
|
|
|
$this->dbHandler->quoteColumn('language_mask'), |
250
|
|
|
$query->bindValue( |
251
|
|
|
$this->maskGenerator->generateLanguageMaskFromLanguageCodes($objectState->languageCodes, true), |
252
|
|
|
null, |
253
|
|
|
ParameterType::INTEGER |
254
|
|
|
) |
255
|
|
|
)->set( |
256
|
|
|
$this->dbHandler->quoteColumn('priority'), |
257
|
|
|
$query->bindValue($objectState->priority, null, \PDO::PARAM_INT) |
258
|
|
|
); |
259
|
|
|
|
260
|
|
|
$query->prepare()->execute(); |
261
|
|
|
|
262
|
|
|
$objectState->id = (int)$this->dbHandler->lastInsertId( |
263
|
|
|
$this->dbHandler->getSequenceName('ezcobj_state', 'id') |
264
|
|
|
); |
265
|
|
|
|
266
|
|
|
$this->insertObjectStateTranslations($objectState); |
267
|
|
|
|
268
|
|
|
// If this is a first state in group, assign it to all content objects |
269
|
|
|
if ($maxPriority === null) { |
270
|
|
|
// @todo Hm... How do we perform this with query object? |
271
|
|
|
$this->dbHandler->prepare( |
272
|
|
|
"INSERT INTO ezcobj_state_link (contentobject_id, contentobject_state_id) |
273
|
|
|
SELECT id, {$objectState->id} FROM ezcontentobject" |
274
|
|
|
)->execute(); |
275
|
|
|
} |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* Updates the stored object state with provided data. |
280
|
|
|
* |
281
|
|
|
* @param \eZ\Publish\SPI\Persistence\Content\ObjectState $objectState |
282
|
|
|
*/ |
283
|
|
View Code Duplication |
public function updateObjectState(ObjectState $objectState) |
284
|
|
|
{ |
285
|
|
|
// First update the state |
286
|
|
|
$query = $this->dbHandler->createUpdateQuery(); |
287
|
|
|
$query->update( |
288
|
|
|
$this->dbHandler->quoteTable('ezcobj_state') |
289
|
|
|
)->set( |
290
|
|
|
$this->dbHandler->quoteColumn('default_language_id'), |
291
|
|
|
$query->bindValue( |
292
|
|
|
$this->maskGenerator->generateLanguageIndicator($objectState->defaultLanguage, false), |
293
|
|
|
null, |
294
|
|
|
\PDO::PARAM_INT |
295
|
|
|
) |
296
|
|
|
)->set( |
297
|
|
|
$this->dbHandler->quoteColumn('identifier'), |
298
|
|
|
$query->bindValue($objectState->identifier) |
299
|
|
|
)->set( |
300
|
|
|
$this->dbHandler->quoteColumn('language_mask'), |
301
|
|
|
$query->bindValue( |
302
|
|
|
$this->maskGenerator->generateLanguageMaskFromLanguageCodes($objectState->languageCodes, true), |
303
|
|
|
null, |
304
|
|
|
ParameterType::INTEGER |
305
|
|
|
) |
306
|
|
|
)->where( |
307
|
|
|
$query->expr->eq( |
308
|
|
|
$this->dbHandler->quoteColumn('id'), |
309
|
|
|
$query->bindValue($objectState->id, null, \PDO::PARAM_INT) |
310
|
|
|
) |
311
|
|
|
); |
312
|
|
|
|
313
|
|
|
$query->prepare()->execute(); |
314
|
|
|
|
315
|
|
|
// And then refresh object state translations |
316
|
|
|
// by removing existing ones and adding new ones |
317
|
|
|
$this->deleteObjectStateTranslations($objectState->id); |
318
|
|
|
$this->insertObjectStateTranslations($objectState); |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* Deletes object state identified by $stateId. |
323
|
|
|
* |
324
|
|
|
* @param int $stateId |
325
|
|
|
*/ |
326
|
|
|
public function deleteObjectState($stateId) |
327
|
|
|
{ |
328
|
|
|
$this->deleteObjectStateTranslations($stateId); |
329
|
|
|
|
330
|
|
|
$query = $this->dbHandler->createDeleteQuery(); |
331
|
|
|
$query->deleteFrom( |
332
|
|
|
$this->dbHandler->quoteTable('ezcobj_state') |
333
|
|
|
)->where( |
334
|
|
|
$query->expr->eq( |
335
|
|
|
$this->dbHandler->quoteColumn('id'), |
336
|
|
|
$query->bindValue($stateId, null, \PDO::PARAM_INT) |
337
|
|
|
) |
338
|
|
|
); |
339
|
|
|
|
340
|
|
|
$query->prepare()->execute(); |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
/** |
344
|
|
|
* Update object state links to $newStateId. |
345
|
|
|
* |
346
|
|
|
* @param int $oldStateId |
347
|
|
|
* @param int $newStateId |
348
|
|
|
*/ |
349
|
|
View Code Duplication |
public function updateObjectStateLinks($oldStateId, $newStateId) |
350
|
|
|
{ |
351
|
|
|
$query = $this->dbHandler->createUpdateQuery(); |
352
|
|
|
$query->update( |
353
|
|
|
$this->dbHandler->quoteTable('ezcobj_state_link') |
354
|
|
|
)->set( |
355
|
|
|
$this->dbHandler->quoteColumn('contentobject_state_id'), |
356
|
|
|
$query->bindValue($newStateId, null, \PDO::PARAM_INT) |
357
|
|
|
)->where( |
358
|
|
|
$query->expr->eq( |
359
|
|
|
$this->dbHandler->quoteColumn('contentobject_state_id'), |
360
|
|
|
$query->bindValue($oldStateId, null, \PDO::PARAM_INT) |
361
|
|
|
) |
362
|
|
|
); |
363
|
|
|
|
364
|
|
|
$query->prepare()->execute(); |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
/** |
368
|
|
|
* Deletes object state links identified by $stateId. |
369
|
|
|
* |
370
|
|
|
* @param int $stateId |
371
|
|
|
*/ |
372
|
|
|
public function deleteObjectStateLinks($stateId) |
373
|
|
|
{ |
374
|
|
|
$query = $this->dbHandler->createDeleteQuery(); |
375
|
|
|
$query->deleteFrom( |
376
|
|
|
$this->dbHandler->quoteTable('ezcobj_state_link') |
377
|
|
|
)->where( |
378
|
|
|
$query->expr->eq( |
379
|
|
|
$this->dbHandler->quoteColumn('contentobject_state_id'), |
380
|
|
|
$query->bindValue($stateId, null, \PDO::PARAM_INT) |
381
|
|
|
) |
382
|
|
|
); |
383
|
|
|
|
384
|
|
|
$query->prepare()->execute(); |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
/** |
388
|
|
|
* Inserts a new object state group into database. |
389
|
|
|
* |
390
|
|
|
* @param \eZ\Publish\SPI\Persistence\Content\ObjectState\Group $objectStateGroup |
391
|
|
|
*/ |
392
|
|
|
public function insertObjectStateGroup(Group $objectStateGroup) |
393
|
|
|
{ |
394
|
|
|
$query = $this->dbHandler->createInsertQuery(); |
395
|
|
|
$query->insertInto( |
396
|
|
|
$this->dbHandler->quoteTable('ezcobj_state_group') |
397
|
|
|
)->set( |
398
|
|
|
$this->dbHandler->quoteColumn('id'), |
399
|
|
|
$this->dbHandler->getAutoIncrementValue('ezcobj_state_group', 'id') |
400
|
|
|
)->set( |
401
|
|
|
$this->dbHandler->quoteColumn('default_language_id'), |
402
|
|
|
$query->bindValue( |
403
|
|
|
$this->maskGenerator->generateLanguageIndicator($objectStateGroup->defaultLanguage, false), |
404
|
|
|
null, |
405
|
|
|
\PDO::PARAM_INT |
406
|
|
|
) |
407
|
|
|
)->set( |
408
|
|
|
$this->dbHandler->quoteColumn('identifier'), |
409
|
|
|
$query->bindValue($objectStateGroup->identifier) |
410
|
|
|
)->set( |
411
|
|
|
$this->dbHandler->quoteColumn('language_mask'), |
412
|
|
|
$query->bindValue( |
413
|
|
|
$this->maskGenerator->generateLanguageMaskFromLanguageCodes($objectStateGroup->languageCodes, true), |
414
|
|
|
null, |
415
|
|
|
ParameterType::INTEGER |
416
|
|
|
) |
417
|
|
|
); |
418
|
|
|
|
419
|
|
|
$query->prepare()->execute(); |
420
|
|
|
|
421
|
|
|
$objectStateGroup->id = (int)$this->dbHandler->lastInsertId( |
422
|
|
|
$this->dbHandler->getSequenceName('ezcobj_state_group', 'id') |
423
|
|
|
); |
424
|
|
|
|
425
|
|
|
$this->insertObjectStateGroupTranslations($objectStateGroup); |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
/** |
429
|
|
|
* Updates the stored object state group with provided data. |
430
|
|
|
* |
431
|
|
|
* @param \eZ\Publish\SPI\Persistence\Content\ObjectState\Group $objectStateGroup |
432
|
|
|
*/ |
433
|
|
View Code Duplication |
public function updateObjectStateGroup(Group $objectStateGroup) |
434
|
|
|
{ |
435
|
|
|
// First update the group |
436
|
|
|
$query = $this->dbHandler->createUpdateQuery(); |
437
|
|
|
$query->update( |
438
|
|
|
$this->dbHandler->quoteTable('ezcobj_state_group') |
439
|
|
|
)->set( |
440
|
|
|
$this->dbHandler->quoteColumn('default_language_id'), |
441
|
|
|
$query->bindValue( |
442
|
|
|
$this->maskGenerator->generateLanguageIndicator($objectStateGroup->defaultLanguage, false), |
443
|
|
|
null, |
444
|
|
|
\PDO::PARAM_INT |
445
|
|
|
) |
446
|
|
|
)->set( |
447
|
|
|
$this->dbHandler->quoteColumn('identifier'), |
448
|
|
|
$query->bindValue($objectStateGroup->identifier) |
449
|
|
|
)->set( |
450
|
|
|
$this->dbHandler->quoteColumn('language_mask'), |
451
|
|
|
$query->bindValue( |
452
|
|
|
$this->maskGenerator->generateLanguageMaskFromLanguageCodes($objectStateGroup->languageCodes, true), |
453
|
|
|
null, |
454
|
|
|
ParameterType::INTEGER |
455
|
|
|
) |
456
|
|
|
)->where( |
457
|
|
|
$query->expr->eq( |
458
|
|
|
$this->dbHandler->quoteColumn('id'), |
459
|
|
|
$query->bindValue($objectStateGroup->id, null, \PDO::PARAM_INT) |
460
|
|
|
) |
461
|
|
|
); |
462
|
|
|
|
463
|
|
|
$query->prepare()->execute(); |
464
|
|
|
|
465
|
|
|
// And then refresh group translations |
466
|
|
|
// by removing old ones and adding new ones |
467
|
|
|
$this->deleteObjectStateGroupTranslations($objectStateGroup->id); |
468
|
|
|
$this->insertObjectStateGroupTranslations($objectStateGroup); |
469
|
|
|
} |
470
|
|
|
|
471
|
|
|
/** |
472
|
|
|
* Deletes the object state group identified by $groupId. |
473
|
|
|
* |
474
|
|
|
* @param mixed $groupId |
475
|
|
|
*/ |
476
|
|
|
public function deleteObjectStateGroup($groupId) |
477
|
|
|
{ |
478
|
|
|
$this->deleteObjectStateGroupTranslations($groupId); |
479
|
|
|
|
480
|
|
|
$query = $this->dbHandler->createDeleteQuery(); |
481
|
|
|
$query->deleteFrom( |
482
|
|
|
$this->dbHandler->quoteTable('ezcobj_state_group') |
483
|
|
|
)->where( |
484
|
|
|
$query->expr->eq( |
485
|
|
|
$this->dbHandler->quoteColumn('id'), |
486
|
|
|
$query->bindValue($groupId, null, \PDO::PARAM_INT) |
487
|
|
|
) |
488
|
|
|
); |
489
|
|
|
|
490
|
|
|
$query->prepare()->execute(); |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
/** |
494
|
|
|
* Sets the object state $stateId to content with $contentId ID. |
495
|
|
|
* |
496
|
|
|
* @param mixed $contentId |
497
|
|
|
* @param mixed $groupId |
498
|
|
|
* @param mixed $stateId |
499
|
|
|
*/ |
500
|
|
|
public function setContentState($contentId, $groupId, $stateId) |
501
|
|
|
{ |
502
|
|
|
// First find out if $contentId is related to existing states in $groupId |
503
|
|
|
$query = $this->dbHandler->createSelectQuery(); |
504
|
|
|
$query->select( |
505
|
|
|
$this->dbHandler->aliasedColumn($query, 'id', 'ezcobj_state') |
506
|
|
|
)->from( |
507
|
|
|
$this->dbHandler->quoteTable('ezcobj_state') |
508
|
|
|
)->innerJoin( |
509
|
|
|
$this->dbHandler->quoteTable('ezcobj_state_link'), |
510
|
|
|
$query->expr->eq( |
511
|
|
|
$this->dbHandler->quoteColumn('id', 'ezcobj_state'), |
512
|
|
|
$this->dbHandler->quoteColumn('contentobject_state_id', 'ezcobj_state_link') |
513
|
|
|
) |
514
|
|
|
)->where( |
515
|
|
|
$query->expr->lAnd( |
516
|
|
|
$query->expr->eq( |
517
|
|
|
$this->dbHandler->quoteColumn('group_id', 'ezcobj_state'), |
518
|
|
|
$query->bindValue($groupId, null, \PDO::PARAM_INT) |
519
|
|
|
), |
520
|
|
|
$query->expr->eq( |
521
|
|
|
$this->dbHandler->quoteColumn('contentobject_id', 'ezcobj_state_link'), |
522
|
|
|
$query->bindValue($contentId, null, \PDO::PARAM_INT) |
523
|
|
|
) |
524
|
|
|
) |
525
|
|
|
); |
526
|
|
|
|
527
|
|
|
$statement = $query->prepare(); |
528
|
|
|
$statement->execute(); |
529
|
|
|
|
530
|
|
|
$rows = $statement->fetchAll(\PDO::FETCH_ASSOC); |
531
|
|
|
|
532
|
|
|
if (!empty($rows)) { |
533
|
|
|
// We already have a state assigned to $contentId, update to new one |
534
|
|
|
$query = $this->dbHandler->createUpdateQuery(); |
535
|
|
|
$query->update( |
536
|
|
|
$this->dbHandler->quoteTable('ezcobj_state_link') |
537
|
|
|
)->set( |
538
|
|
|
$this->dbHandler->quoteColumn('contentobject_state_id'), |
539
|
|
|
$query->bindValue($stateId, null, \PDO::PARAM_INT) |
540
|
|
|
)->where( |
541
|
|
|
$query->expr->lAnd( |
542
|
|
|
$query->expr->eq( |
543
|
|
|
$this->dbHandler->quoteColumn('contentobject_id'), |
544
|
|
|
$query->bindValue($contentId, null, \PDO::PARAM_INT) |
545
|
|
|
), |
546
|
|
|
$query->expr->eq( |
547
|
|
|
$this->dbHandler->quoteColumn('contentobject_state_id'), |
548
|
|
|
$query->bindValue($rows[0]['ezcobj_state_id'], null, \PDO::PARAM_INT) |
549
|
|
|
) |
550
|
|
|
) |
551
|
|
|
); |
552
|
|
|
|
553
|
|
|
$query->prepare()->execute(); |
554
|
|
|
} else { |
555
|
|
|
// No state assigned to $contentId from specified group, create assignment |
556
|
|
|
$query = $this->dbHandler->createInsertQuery(); |
557
|
|
|
$query->insertInto( |
558
|
|
|
$this->dbHandler->quoteTable('ezcobj_state_link') |
559
|
|
|
)->set( |
560
|
|
|
$this->dbHandler->quoteColumn('contentobject_id'), |
561
|
|
|
$query->bindValue($contentId, null, \PDO::PARAM_INT) |
562
|
|
|
)->set( |
563
|
|
|
$this->dbHandler->quoteColumn('contentobject_state_id'), |
564
|
|
|
$query->bindValue($stateId, null, \PDO::PARAM_INT) |
565
|
|
|
); |
566
|
|
|
|
567
|
|
|
$query->prepare()->execute(); |
568
|
|
|
} |
569
|
|
|
} |
570
|
|
|
|
571
|
|
|
/** |
572
|
|
|
* Loads object state data for $contentId content from $stateGroupId state group. |
573
|
|
|
* |
574
|
|
|
* @param int $contentId |
575
|
|
|
* @param int $stateGroupId |
576
|
|
|
* |
577
|
|
|
* @return array |
578
|
|
|
*/ |
579
|
|
View Code Duplication |
public function loadObjectStateDataForContent($contentId, $stateGroupId) |
580
|
|
|
{ |
581
|
|
|
$query = $this->createObjectStateFindQuery(); |
582
|
|
|
$query->innerJoin( |
583
|
|
|
$this->dbHandler->quoteTable('ezcobj_state_link'), |
584
|
|
|
$query->expr->eq( |
585
|
|
|
$this->dbHandler->quoteColumn('id', 'ezcobj_state'), |
586
|
|
|
$this->dbHandler->quoteColumn('contentobject_state_id', 'ezcobj_state_link') |
587
|
|
|
) |
588
|
|
|
)->where( |
589
|
|
|
$query->expr->lAnd( |
590
|
|
|
$query->expr->eq( |
591
|
|
|
$this->dbHandler->quoteColumn('group_id', 'ezcobj_state'), |
592
|
|
|
$query->bindValue($stateGroupId, null, \PDO::PARAM_INT) |
593
|
|
|
), |
594
|
|
|
$query->expr->eq( |
595
|
|
|
$this->dbHandler->quoteColumn('contentobject_id', 'ezcobj_state_link'), |
596
|
|
|
$query->bindValue($contentId, null, \PDO::PARAM_INT) |
597
|
|
|
) |
598
|
|
|
) |
599
|
|
|
); |
600
|
|
|
|
601
|
|
|
$statement = $query->prepare(); |
602
|
|
|
$statement->execute(); |
603
|
|
|
|
604
|
|
|
return $statement->fetchAll(\PDO::FETCH_ASSOC); |
605
|
|
|
} |
606
|
|
|
|
607
|
|
|
/** |
608
|
|
|
* Returns the number of objects which are in this state. |
609
|
|
|
* |
610
|
|
|
* @param mixed $stateId |
611
|
|
|
* |
612
|
|
|
* @return int |
613
|
|
|
*/ |
614
|
|
|
public function getContentCount($stateId) |
615
|
|
|
{ |
616
|
|
|
$query = $this->dbHandler->createSelectQuery(); |
617
|
|
|
$query->select( |
618
|
|
|
$query->alias($query->expr->count('*'), 'count') |
619
|
|
|
)->from( |
620
|
|
|
$this->dbHandler->quoteTable('ezcobj_state_link') |
621
|
|
|
)->where( |
622
|
|
|
$query->expr->eq( |
623
|
|
|
$this->dbHandler->quoteColumn('contentobject_state_id'), |
624
|
|
|
$query->bindValue($stateId, null, \PDO::PARAM_INT) |
625
|
|
|
) |
626
|
|
|
); |
627
|
|
|
|
628
|
|
|
$statement = $query->prepare(); |
629
|
|
|
$statement->execute(); |
630
|
|
|
|
631
|
|
|
$count = $statement->fetchColumn(); |
632
|
|
|
|
633
|
|
|
return $count !== null ? (int)$count : 0; |
634
|
|
|
} |
635
|
|
|
|
636
|
|
|
/** |
637
|
|
|
* Updates the object state priority to provided value. |
638
|
|
|
* |
639
|
|
|
* @param mixed $stateId |
640
|
|
|
* @param int $priority |
641
|
|
|
*/ |
642
|
|
View Code Duplication |
public function updateObjectStatePriority($stateId, $priority) |
643
|
|
|
{ |
644
|
|
|
$query = $this->dbHandler->createUpdateQuery(); |
645
|
|
|
$query->update( |
646
|
|
|
$this->dbHandler->quoteTable('ezcobj_state') |
647
|
|
|
)->set( |
648
|
|
|
$this->dbHandler->quoteColumn('priority'), |
649
|
|
|
$query->bindValue($priority, null, \PDO::PARAM_INT) |
650
|
|
|
)->where( |
651
|
|
|
$query->expr->eq( |
652
|
|
|
$this->dbHandler->quoteColumn('id'), |
653
|
|
|
$query->bindValue($stateId, null, \PDO::PARAM_INT) |
654
|
|
|
) |
655
|
|
|
); |
656
|
|
|
|
657
|
|
|
$query->prepare()->execute(); |
658
|
|
|
} |
659
|
|
|
|
660
|
|
|
/** |
661
|
|
|
* Creates a generalized query for fetching object state(s). |
662
|
|
|
* |
663
|
|
|
* @return \eZ\Publish\Core\Persistence\Database\SelectQuery |
664
|
|
|
*/ |
665
|
|
View Code Duplication |
protected function createObjectStateFindQuery() |
666
|
|
|
{ |
667
|
|
|
$query = $this->dbHandler->createSelectQuery(); |
668
|
|
|
$query->select( |
669
|
|
|
// Object state |
670
|
|
|
$this->dbHandler->aliasedColumn($query, 'default_language_id', 'ezcobj_state'), |
671
|
|
|
$this->dbHandler->aliasedColumn($query, 'group_id', 'ezcobj_state'), |
672
|
|
|
$this->dbHandler->aliasedColumn($query, 'id', 'ezcobj_state'), |
673
|
|
|
$this->dbHandler->aliasedColumn($query, 'identifier', 'ezcobj_state'), |
674
|
|
|
$this->dbHandler->aliasedColumn($query, 'language_mask', 'ezcobj_state'), |
675
|
|
|
$this->dbHandler->aliasedColumn($query, 'priority', 'ezcobj_state'), |
676
|
|
|
// Object state language |
677
|
|
|
$this->dbHandler->aliasedColumn($query, 'description', 'ezcobj_state_language'), |
678
|
|
|
$this->dbHandler->aliasedColumn($query, 'language_id', 'ezcobj_state_language'), |
679
|
|
|
$this->dbHandler->aliasedColumn($query, 'name', 'ezcobj_state_language') |
680
|
|
|
)->from( |
681
|
|
|
$this->dbHandler->quoteTable('ezcobj_state') |
682
|
|
|
)->innerJoin( |
683
|
|
|
$this->dbHandler->quoteTable('ezcobj_state_language'), |
684
|
|
|
$query->expr->eq( |
685
|
|
|
$this->dbHandler->quoteColumn('id', 'ezcobj_state'), |
686
|
|
|
$this->dbHandler->quoteColumn('contentobject_state_id', 'ezcobj_state_language') |
687
|
|
|
) |
688
|
|
|
); |
689
|
|
|
|
690
|
|
|
return $query; |
691
|
|
|
} |
692
|
|
|
|
693
|
|
|
/** |
694
|
|
|
* Creates a generalized query for fetching object state group(s). |
695
|
|
|
* |
696
|
|
|
* @return \eZ\Publish\Core\Persistence\Database\SelectQuery |
697
|
|
|
*/ |
698
|
|
View Code Duplication |
protected function createObjectStateGroupFindQuery() |
699
|
|
|
{ |
700
|
|
|
$query = $this->dbHandler->createSelectQuery(); |
701
|
|
|
$query->select( |
702
|
|
|
// Object state group |
703
|
|
|
$this->dbHandler->aliasedColumn($query, 'default_language_id', 'ezcobj_state_group'), |
704
|
|
|
$this->dbHandler->aliasedColumn($query, 'id', 'ezcobj_state_group'), |
705
|
|
|
$this->dbHandler->aliasedColumn($query, 'identifier', 'ezcobj_state_group'), |
706
|
|
|
$this->dbHandler->aliasedColumn($query, 'language_mask', 'ezcobj_state_group'), |
707
|
|
|
// Object state group language |
708
|
|
|
$this->dbHandler->aliasedColumn($query, 'description', 'ezcobj_state_group_language'), |
709
|
|
|
$this->dbHandler->aliasedColumn($query, 'language_id', 'ezcobj_state_group_language'), |
710
|
|
|
$this->dbHandler->aliasedColumn($query, 'real_language_id', 'ezcobj_state_group_language'), |
711
|
|
|
$this->dbHandler->aliasedColumn($query, 'name', 'ezcobj_state_group_language') |
712
|
|
|
)->from( |
713
|
|
|
$this->dbHandler->quoteTable('ezcobj_state_group') |
714
|
|
|
)->innerJoin( |
715
|
|
|
$this->dbHandler->quoteTable('ezcobj_state_group_language'), |
716
|
|
|
$query->expr->eq( |
717
|
|
|
$this->dbHandler->quoteColumn('id', 'ezcobj_state_group'), |
718
|
|
|
$this->dbHandler->quoteColumn('contentobject_state_group_id', 'ezcobj_state_group_language') |
719
|
|
|
) |
720
|
|
|
); |
721
|
|
|
|
722
|
|
|
return $query; |
723
|
|
|
} |
724
|
|
|
|
725
|
|
|
/** |
726
|
|
|
* Inserts object state group translations into database. |
727
|
|
|
* |
728
|
|
|
* @param \eZ\Publish\SPI\Persistence\Content\ObjectState $objectState |
729
|
|
|
*/ |
730
|
|
|
protected function insertObjectStateTranslations(ObjectState $objectState) |
731
|
|
|
{ |
732
|
|
|
foreach ($objectState->languageCodes as $languageCode) { |
733
|
|
|
$query = $this->dbHandler->createInsertQuery(); |
734
|
|
|
$query->insertInto( |
735
|
|
|
$this->dbHandler->quoteTable('ezcobj_state_language') |
736
|
|
|
)->set( |
737
|
|
|
$this->dbHandler->quoteColumn('contentobject_state_id'), |
738
|
|
|
$query->bindValue($objectState->id, null, \PDO::PARAM_INT) |
739
|
|
|
)->set( |
740
|
|
|
$this->dbHandler->quoteColumn('description'), |
741
|
|
|
$query->bindValue($objectState->description[$languageCode]) |
742
|
|
|
)->set( |
743
|
|
|
$this->dbHandler->quoteColumn('name'), |
744
|
|
|
$query->bindValue($objectState->name[$languageCode]) |
745
|
|
|
)->set( |
746
|
|
|
$this->dbHandler->quoteColumn('language_id'), |
747
|
|
|
$query->bindValue( |
748
|
|
|
$this->maskGenerator->generateLanguageIndicator( |
749
|
|
|
$languageCode, |
750
|
|
|
$languageCode === $objectState->defaultLanguage |
751
|
|
|
), |
752
|
|
|
null, |
753
|
|
|
\PDO::PARAM_INT |
754
|
|
|
) |
755
|
|
|
); |
756
|
|
|
|
757
|
|
|
$query->prepare()->execute(); |
758
|
|
|
} |
759
|
|
|
} |
760
|
|
|
|
761
|
|
|
/** |
762
|
|
|
* Deletes all translations of the $stateId state. |
763
|
|
|
* |
764
|
|
|
* @param mixed $stateId |
765
|
|
|
*/ |
766
|
|
|
protected function deleteObjectStateTranslations($stateId) |
767
|
|
|
{ |
768
|
|
|
$query = $this->dbHandler->createDeleteQuery(); |
769
|
|
|
$query->deleteFrom( |
770
|
|
|
$this->dbHandler->quoteTable('ezcobj_state_language') |
771
|
|
|
)->where( |
772
|
|
|
$query->expr->eq( |
773
|
|
|
$this->dbHandler->quoteColumn('contentobject_state_id'), |
774
|
|
|
$query->bindValue($stateId, null, \PDO::PARAM_INT) |
775
|
|
|
) |
776
|
|
|
); |
777
|
|
|
|
778
|
|
|
$query->prepare()->execute(); |
779
|
|
|
} |
780
|
|
|
|
781
|
|
|
/** |
782
|
|
|
* Inserts object state group translations into database. |
783
|
|
|
* |
784
|
|
|
* @param \eZ\Publish\SPI\Persistence\Content\ObjectState\Group $objectStateGroup |
785
|
|
|
*/ |
786
|
|
|
protected function insertObjectStateGroupTranslations(Group $objectStateGroup) |
787
|
|
|
{ |
788
|
|
|
foreach ($objectStateGroup->languageCodes as $languageCode) { |
789
|
|
|
$languageId = $this->maskGenerator->generateLanguageIndicator( |
790
|
|
|
$languageCode, |
791
|
|
|
$languageCode === $objectStateGroup->defaultLanguage |
792
|
|
|
); |
793
|
|
|
|
794
|
|
|
$query = $this->dbHandler->createInsertQuery(); |
795
|
|
|
$query->insertInto( |
796
|
|
|
$this->dbHandler->quoteTable('ezcobj_state_group_language') |
797
|
|
|
)->set( |
798
|
|
|
$this->dbHandler->quoteColumn('contentobject_state_group_id'), |
799
|
|
|
$query->bindValue($objectStateGroup->id, null, \PDO::PARAM_INT) |
800
|
|
|
)->set( |
801
|
|
|
$this->dbHandler->quoteColumn('description'), |
802
|
|
|
$query->bindValue($objectStateGroup->description[$languageCode]) |
803
|
|
|
)->set( |
804
|
|
|
$this->dbHandler->quoteColumn('name'), |
805
|
|
|
$query->bindValue($objectStateGroup->name[$languageCode]) |
806
|
|
|
)->set( |
807
|
|
|
$this->dbHandler->quoteColumn('language_id'), |
808
|
|
|
$query->bindValue($languageId, null, \PDO::PARAM_INT) |
809
|
|
|
)->set( |
810
|
|
|
$this->dbHandler->quoteColumn('real_language_id'), |
811
|
|
|
$query->bindValue($languageId & ~1, null, \PDO::PARAM_INT) |
812
|
|
|
); |
813
|
|
|
|
814
|
|
|
$query->prepare()->execute(); |
815
|
|
|
} |
816
|
|
|
} |
817
|
|
|
|
818
|
|
|
/** |
819
|
|
|
* Deletes all translations of the $groupId state group. |
820
|
|
|
* |
821
|
|
|
* @param mixed $groupId |
822
|
|
|
*/ |
823
|
|
|
protected function deleteObjectStateGroupTranslations($groupId) |
824
|
|
|
{ |
825
|
|
|
$query = $this->dbHandler->createDeleteQuery(); |
826
|
|
|
$query->deleteFrom( |
827
|
|
|
$this->dbHandler->quoteTable('ezcobj_state_group_language') |
828
|
|
|
)->where( |
829
|
|
|
$query->expr->eq( |
830
|
|
|
$this->dbHandler->quoteColumn('contentobject_state_group_id'), |
831
|
|
|
$query->bindValue($groupId, null, \PDO::PARAM_INT) |
832
|
|
|
) |
833
|
|
|
); |
834
|
|
|
|
835
|
|
|
$query->prepare()->execute(); |
836
|
|
|
} |
837
|
|
|
} |
838
|
|
|
|