1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the ContentTypeGateway 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\User\Role\Gateway; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\Core\Persistence\Legacy\User\Role\Gateway; |
12
|
|
|
use eZ\Publish\SPI\Persistence\User\Policy; |
13
|
|
|
use eZ\Publish\SPI\Persistence\User\RoleUpdateStruct; |
14
|
|
|
use eZ\Publish\SPI\Persistence\User\Role; |
15
|
|
|
use Doctrine\DBAL\DBALException; |
16
|
|
|
use PDOException; |
17
|
|
|
use RuntimeException; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Base class for content type gateways. |
21
|
|
|
*/ |
22
|
|
|
class ExceptionConversion extends Gateway |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* The wrapped gateway. |
26
|
|
|
* |
27
|
|
|
* @var Gateway |
28
|
|
|
*/ |
29
|
|
|
protected $innerGateway; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Creates a new exception conversion gateway around $innerGateway. |
33
|
|
|
* |
34
|
|
|
* @param Gateway $innerGateway |
35
|
|
|
*/ |
36
|
|
|
public function __construct(Gateway $innerGateway) |
37
|
|
|
{ |
38
|
|
|
$this->innerGateway = $innerGateway; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Create new role. |
43
|
|
|
* |
44
|
|
|
* @param Role $role |
45
|
|
|
* |
46
|
|
|
* @return Role |
47
|
|
|
*/ |
48
|
|
View Code Duplication |
public function createRole(Role $role) |
49
|
|
|
{ |
50
|
|
|
try { |
51
|
|
|
return $this->innerGateway->createRole($role); |
52
|
|
|
} catch (DBALException $e) { |
53
|
|
|
throw new RuntimeException('Database error', 0, $e); |
54
|
|
|
} catch (PDOException $e) { |
55
|
|
|
throw new RuntimeException('Database error', 0, $e); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Copy an existing role. |
61
|
|
|
* |
62
|
|
|
* @param Role $role |
63
|
|
|
* |
64
|
|
|
* @return Role |
65
|
|
|
*/ |
66
|
|
View Code Duplication |
public function copyRole(Role $role) |
67
|
|
|
{ |
68
|
|
|
try { |
69
|
|
|
return $this->innerGateway->copyRole($role); |
70
|
|
|
} catch (DBALException $e) { |
71
|
|
|
throw new RuntimeException('Database error', 0, $e); |
72
|
|
|
} catch (PDOException $e) { |
73
|
|
|
throw new RuntimeException('Database error', 0, $e); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Loads a specified role by $roleId. |
79
|
|
|
* |
80
|
|
|
* @param mixed $roleId |
81
|
|
|
* @param int $status One of Role::STATUS_DEFINED|Role::STATUS_DRAFT |
82
|
|
|
* |
83
|
|
|
* @return array |
84
|
|
|
*/ |
85
|
|
View Code Duplication |
public function loadRole($roleId, $status = Role::STATUS_DEFINED) |
86
|
|
|
{ |
87
|
|
|
try { |
88
|
|
|
return $this->innerGateway->loadRole($roleId, $status); |
89
|
|
|
} catch (DBALException $e) { |
90
|
|
|
throw new RuntimeException('Database error', 0, $e); |
91
|
|
|
} catch (PDOException $e) { |
92
|
|
|
throw new RuntimeException('Database error', 0, $e); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Loads a specified role by $identifier. |
98
|
|
|
* |
99
|
|
|
* @param string $identifier |
100
|
|
|
* @param int $status One of Role::STATUS_DEFINED|Role::STATUS_DRAFT |
101
|
|
|
* |
102
|
|
|
* @return array |
103
|
|
|
*/ |
104
|
|
View Code Duplication |
public function loadRoleByIdentifier($identifier, $status = Role::STATUS_DEFINED) |
105
|
|
|
{ |
106
|
|
|
try { |
107
|
|
|
return $this->innerGateway->loadRoleByIdentifier($identifier, $status); |
108
|
|
|
} catch (DBALException $e) { |
109
|
|
|
throw new RuntimeException('Database error', 0, $e); |
110
|
|
|
} catch (PDOException $e) { |
111
|
|
|
throw new RuntimeException('Database error', 0, $e); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Loads a role draft by the original role ID. |
117
|
|
|
* |
118
|
|
|
* @param mixed $roleId ID of the role the draft was created from. |
119
|
|
|
* |
120
|
|
|
* @return array |
121
|
|
|
*/ |
122
|
|
View Code Duplication |
public function loadRoleDraftByRoleId($roleId) |
123
|
|
|
{ |
124
|
|
|
try { |
125
|
|
|
return $this->innerGateway->loadRoleDraftByRoleId($roleId); |
126
|
|
|
} catch (DBALException $e) { |
127
|
|
|
throw new RuntimeException('Database error', 0, $e); |
128
|
|
|
} catch (PDOException $e) { |
129
|
|
|
throw new RuntimeException('Database error', 0, $e); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Loads all roles. |
135
|
|
|
* |
136
|
|
|
* @param int $status One of Role::STATUS_DEFINED|Role::STATUS_DRAFT |
137
|
|
|
* |
138
|
|
|
* @return array |
139
|
|
|
*/ |
140
|
|
View Code Duplication |
public function loadRoles($status = Role::STATUS_DEFINED) |
141
|
|
|
{ |
142
|
|
|
try { |
143
|
|
|
return $this->innerGateway->loadRoles(); |
144
|
|
|
} catch (DBALException $e) { |
145
|
|
|
throw new RuntimeException('Database error', 0, $e); |
146
|
|
|
} catch (PDOException $e) { |
147
|
|
|
throw new RuntimeException('Database error', 0, $e); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Loads all roles associated with the given content objects. |
153
|
|
|
* |
154
|
|
|
* @param array $contentIds |
155
|
|
|
* @param int $status One of Role::STATUS_DEFINED|Role::STATUS_DRAFT |
156
|
|
|
* |
157
|
|
|
* @return array |
158
|
|
|
*/ |
159
|
|
View Code Duplication |
public function loadRolesForContentObjects($contentIds, $status = Role::STATUS_DEFINED) |
160
|
|
|
{ |
161
|
|
|
try { |
162
|
|
|
return $this->innerGateway->loadRolesForContentObjects($contentIds); |
163
|
|
|
} catch (DBALException $e) { |
164
|
|
|
throw new RuntimeException('Database error', 0, $e); |
165
|
|
|
} catch (PDOException $e) { |
166
|
|
|
throw new RuntimeException('Database error', 0, $e); |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Loads role assignment for specified assignment ID. |
172
|
|
|
* |
173
|
|
|
* @param mixed $roleAssignmentId |
174
|
|
|
* |
175
|
|
|
* @return array |
176
|
|
|
*/ |
177
|
|
View Code Duplication |
public function loadRoleAssignment($roleAssignmentId) |
178
|
|
|
{ |
179
|
|
|
try { |
180
|
|
|
return $this->innerGateway->loadRoleAssignment($roleAssignmentId); |
181
|
|
|
} catch (DBALException $e) { |
182
|
|
|
throw new RuntimeException('Database error', 0, $e); |
183
|
|
|
} catch (PDOException $e) { |
184
|
|
|
throw new RuntimeException('Database error', 0, $e); |
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Loads role assignments for specified content ID. |
190
|
|
|
* |
191
|
|
|
* @param mixed $groupId |
192
|
|
|
* @param bool $inherited |
193
|
|
|
* |
194
|
|
|
* @return array |
195
|
|
|
*/ |
196
|
|
View Code Duplication |
public function loadRoleAssignmentsByGroupId($groupId, $inherited = false) |
197
|
|
|
{ |
198
|
|
|
try { |
199
|
|
|
return $this->innerGateway->loadRoleAssignmentsByGroupId($groupId, $inherited); |
200
|
|
|
} catch (DBALException $e) { |
201
|
|
|
throw new RuntimeException('Database error', 0, $e); |
202
|
|
|
} catch (PDOException $e) { |
203
|
|
|
throw new RuntimeException('Database error', 0, $e); |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Loads role assignments for given role ID. |
209
|
|
|
* |
210
|
|
|
* @param mixed $roleId |
211
|
|
|
* |
212
|
|
|
* @return array |
213
|
|
|
*/ |
214
|
|
View Code Duplication |
public function loadRoleAssignmentsByRoleId($roleId) |
215
|
|
|
{ |
216
|
|
|
try { |
217
|
|
|
return $this->innerGateway->loadRoleAssignmentsByRoleId($roleId); |
218
|
|
|
} catch (DBALException $e) { |
219
|
|
|
throw new RuntimeException('Database error', 0, $e); |
220
|
|
|
} catch (PDOException $e) { |
221
|
|
|
throw new RuntimeException('Database error', 0, $e); |
222
|
|
|
} |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* Returns the user policies associated with the user. |
227
|
|
|
* |
228
|
|
|
* @param mixed $userId |
229
|
|
|
* |
230
|
|
|
* @return UserPolicy[] |
231
|
|
|
*/ |
232
|
|
View Code Duplication |
public function loadPoliciesByUserId($userId) |
233
|
|
|
{ |
234
|
|
|
try { |
235
|
|
|
return $this->innerGateway->loadPoliciesByUserId($userId); |
236
|
|
|
} catch (DBALException $e) { |
237
|
|
|
throw new RuntimeException('Database error', 0, $e); |
238
|
|
|
} catch (PDOException $e) { |
239
|
|
|
throw new RuntimeException('Database error', 0, $e); |
240
|
|
|
} |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* Update role (draft). |
245
|
|
|
* |
246
|
|
|
* @throws \eZ\Publish\Core\Base\Exceptions\NotFoundException |
247
|
|
|
* |
248
|
|
|
* @param RoleUpdateStruct $role |
249
|
|
|
*/ |
250
|
|
View Code Duplication |
public function updateRole(RoleUpdateStruct $role) |
251
|
|
|
{ |
252
|
|
|
try { |
253
|
|
|
return $this->innerGateway->updateRole($role); |
254
|
|
|
} catch (DBALException $e) { |
255
|
|
|
throw new RuntimeException('Database error', 0, $e); |
256
|
|
|
} catch (PDOException $e) { |
257
|
|
|
throw new RuntimeException('Database error', 0, $e); |
258
|
|
|
} |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* Delete the specified role (draft). |
263
|
|
|
* If it's not a draft, the role assignments will also be deleted. |
264
|
|
|
* |
265
|
|
|
* @param mixed $roleId |
266
|
|
|
* @param int $status One of Role::STATUS_DEFINED|Role::STATUS_DRAFT |
267
|
|
|
*/ |
268
|
|
View Code Duplication |
public function deleteRole($roleId, $status = Role::STATUS_DEFINED) |
269
|
|
|
{ |
270
|
|
|
try { |
271
|
|
|
return $this->innerGateway->deleteRole($roleId, $status); |
272
|
|
|
} catch (DBALException $e) { |
273
|
|
|
throw new RuntimeException('Database error', 0, $e); |
274
|
|
|
} catch (PDOException $e) { |
275
|
|
|
throw new RuntimeException('Database error', 0, $e); |
276
|
|
|
} |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* Publish the specified role draft. |
281
|
|
|
* If the draft was created from an existing role, published version will take the original role ID. |
282
|
|
|
* |
283
|
|
|
* @param mixed $roleDraftId |
284
|
|
|
* @param mixed|null $originalRoleId ID of role the draft was created from. Will be null if the role draft was completely new. |
285
|
|
|
*/ |
286
|
|
View Code Duplication |
public function publishRoleDraft($roleDraftId, $originalRoleId = null) |
287
|
|
|
{ |
288
|
|
|
try { |
289
|
|
|
return $this->innerGateway->publishRoleDraft($roleDraftId, $originalRoleId); |
290
|
|
|
} catch (DBALException $e) { |
291
|
|
|
throw new RuntimeException('Database error', 0, $e); |
292
|
|
|
} catch (PDOException $e) { |
293
|
|
|
throw new RuntimeException('Database error', 0, $e); |
294
|
|
|
} |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* Adds a policy to a role. |
299
|
|
|
* |
300
|
|
|
* @param mixed $roleId |
301
|
|
|
* @param Policy $policy |
302
|
|
|
*/ |
303
|
|
View Code Duplication |
public function addPolicy($roleId, Policy $policy) |
304
|
|
|
{ |
305
|
|
|
try { |
306
|
|
|
return $this->innerGateway->addPolicy($roleId, $policy); |
307
|
|
|
} catch (DBALException $e) { |
308
|
|
|
throw new RuntimeException('Database error', 0, $e); |
309
|
|
|
} catch (PDOException $e) { |
310
|
|
|
throw new RuntimeException('Database error', 0, $e); |
311
|
|
|
} |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* Adds limitations to an existing policy. |
316
|
|
|
* |
317
|
|
|
* @param int $policyId |
318
|
|
|
* @param array $limitations |
319
|
|
|
*/ |
320
|
|
View Code Duplication |
public function addPolicyLimitations($policyId, array $limitations) |
321
|
|
|
{ |
322
|
|
|
try { |
323
|
|
|
return $this->innerGateway->addPolicyLimitations($policyId, $limitations); |
324
|
|
|
} catch (DBALException $e) { |
325
|
|
|
throw new RuntimeException('Database error', 0, $e); |
326
|
|
|
} catch (PDOException $e) { |
327
|
|
|
throw new RuntimeException('Database error', 0, $e); |
328
|
|
|
} |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* Removes a policy from a role. |
333
|
|
|
* |
334
|
|
|
* @param mixed $policyId |
335
|
|
|
*/ |
336
|
|
View Code Duplication |
public function removePolicy($policyId) |
337
|
|
|
{ |
338
|
|
|
try { |
339
|
|
|
return $this->innerGateway->removePolicy($policyId); |
340
|
|
|
} catch (DBALException $e) { |
341
|
|
|
throw new RuntimeException('Database error', 0, $e); |
342
|
|
|
} catch (PDOException $e) { |
343
|
|
|
throw new RuntimeException('Database error', 0, $e); |
344
|
|
|
} |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* Removes a policy from a role. |
349
|
|
|
* |
350
|
|
|
* @param mixed $policyId |
351
|
|
|
*/ |
352
|
|
View Code Duplication |
public function removePolicyLimitations($policyId) |
353
|
|
|
{ |
354
|
|
|
try { |
355
|
|
|
return $this->innerGateway->removePolicyLimitations($policyId); |
356
|
|
|
} catch (DBALException $e) { |
357
|
|
|
throw new RuntimeException('Database error', 0, $e); |
358
|
|
|
} catch (PDOException $e) { |
359
|
|
|
throw new RuntimeException('Database error', 0, $e); |
360
|
|
|
} |
361
|
|
|
} |
362
|
|
|
} |
363
|
|
|
|