Completed
Push — EZP-31644 ( 2e0a1e...93bb44 )
by
unknown
19:12
created

ExceptionConversion::insertObjectStateGroup()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 10
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the 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 eZ\Publish\Core\Persistence\Legacy\Content\ObjectState\Gateway;
12
use eZ\Publish\SPI\Persistence\Content\ObjectState;
13
use eZ\Publish\SPI\Persistence\Content\ObjectState\Group;
14
use Doctrine\DBAL\DBALException;
15
use PDOException;
16
use RuntimeException;
17
18
/**
19
 * ObjectState Gateway.
20
 */
21
class ExceptionConversion extends Gateway
22
{
23
    /**
24
     * The wrapped gateway.
25
     *
26
     * @var Gateway
27
     */
28
    protected $innerGateway;
29
30
    /**
31
     * Creates a new exception conversion gateway around $innerGateway.
32
     *
33
     * @param Gateway $innerGateway
34
     */
35
    public function __construct(Gateway $innerGateway)
36
    {
37
        $this->innerGateway = $innerGateway;
38
    }
39
40
    /**
41
     * Loads data for an object state.
42
     *
43
     * @param mixed $stateId
44
     *
45
     * @return array
46
     */
47 View Code Duplication
    public function loadObjectStateData($stateId)
48
    {
49
        try {
50
            return $this->innerGateway->loadObjectStateData($stateId);
51
        } catch (DBALException $e) {
52
            throw new RuntimeException('Database error', 0, $e);
53
        } catch (PDOException $e) {
54
            throw new RuntimeException('Database error', 0, $e);
55
        }
56
    }
57
58
    /**
59
     * Loads data for an object state by identifier.
60
     *
61
     * @param string $identifier
62
     * @param mixed $groupId
63
     *
64
     * @return array
65
     */
66 View Code Duplication
    public function loadObjectStateDataByIdentifier($identifier, $groupId)
67
    {
68
        try {
69
            return $this->innerGateway->loadObjectStateDataByIdentifier($identifier, $groupId);
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 data for all object states belonging to group with $groupId ID.
79
     *
80
     * @param mixed $groupId
81
     *
82
     * @return array
83
     */
84 View Code Duplication
    public function loadObjectStateListData($groupId)
85
    {
86
        try {
87
            return $this->innerGateway->loadObjectStateListData($groupId);
88
        } catch (DBALException $e) {
89
            throw new RuntimeException('Database error', 0, $e);
90
        } catch (PDOException $e) {
91
            throw new RuntimeException('Database error', 0, $e);
92
        }
93
    }
94
95
    /**
96
     * Loads data for an object state group.
97
     *
98
     * @param mixed $groupId
99
     *
100
     * @return array
101
     */
102 View Code Duplication
    public function loadObjectStateGroupData($groupId)
103
    {
104
        try {
105
            return $this->innerGateway->loadObjectStateGroupData($groupId);
106
        } catch (DBALException $e) {
107
            throw new RuntimeException('Database error', 0, $e);
108
        } catch (PDOException $e) {
109
            throw new RuntimeException('Database error', 0, $e);
110
        }
111
    }
112
113
    /**
114
     * Loads data for an object state group by identifier.
115
     *
116
     * @param string $identifier
117
     *
118
     * @return array
119
     */
120 View Code Duplication
    public function loadObjectStateGroupDataByIdentifier($identifier)
121
    {
122
        try {
123
            return $this->innerGateway->loadObjectStateGroupDataByIdentifier($identifier);
124
        } catch (DBALException $e) {
125
            throw new RuntimeException('Database error', 0, $e);
126
        } catch (PDOException $e) {
127
            throw new RuntimeException('Database error', 0, $e);
128
        }
129
    }
130
131
    /**
132
     * Loads data for all object state groups, filtered by $offset and $limit.
133
     *
134
     * @param int $offset
135
     * @param int $limit
136
     *
137
     * @return array
138
     */
139 View Code Duplication
    public function loadObjectStateGroupListData($offset, $limit)
140
    {
141
        try {
142
            return $this->innerGateway->loadObjectStateGroupListData($offset, $limit);
143
        } catch (DBALException $e) {
144
            throw new RuntimeException('Database error', 0, $e);
145
        } catch (PDOException $e) {
146
            throw new RuntimeException('Database error', 0, $e);
147
        }
148
    }
149
150
    /**
151
     * Inserts a new object state into database.
152
     *
153
     * @param \eZ\Publish\SPI\Persistence\Content\ObjectState $objectState
154
     * @param int $groupId
155
     */
156 View Code Duplication
    public function insertObjectState(ObjectState $objectState, $groupId)
157
    {
158
        try {
159
            return $this->innerGateway->insertObjectState($objectState, $groupId);
160
        } catch (DBALException $e) {
161
            throw new RuntimeException('Database error', 0, $e);
162
        } catch (PDOException $e) {
163
            throw new RuntimeException('Database error', 0, $e);
164
        }
165
    }
166
167
    /**
168
     * Updates the stored object state with provided data.
169
     *
170
     * @param \eZ\Publish\SPI\Persistence\Content\ObjectState $objectState
171
     */
172 View Code Duplication
    public function updateObjectState(ObjectState $objectState)
173
    {
174
        try {
175
            return $this->innerGateway->updateObjectState($objectState);
176
        } catch (DBALException $e) {
177
            throw new RuntimeException('Database error', 0, $e);
178
        } catch (PDOException $e) {
179
            throw new RuntimeException('Database error', 0, $e);
180
        }
181
    }
182
183
    /**
184
     * Deletes object state identified by $stateId.
185
     *
186
     * @param int $stateId
187
     */
188 View Code Duplication
    public function deleteObjectState($stateId)
189
    {
190
        try {
191
            return $this->innerGateway->deleteObjectState($stateId);
192
        } catch (DBALException $e) {
193
            throw new RuntimeException('Database error', 0, $e);
194
        } catch (PDOException $e) {
195
            throw new RuntimeException('Database error', 0, $e);
196
        }
197
    }
198
199
    /**
200
     * Update object state links from $oldStateId to $newStateId.
201
     *
202
     * @param int $oldStateId
203
     * @param int $newStateId
204
     */
205 View Code Duplication
    public function updateObjectStateLinks($oldStateId, $newStateId)
206
    {
207
        try {
208
            return $this->innerGateway->updateObjectStateLinks($oldStateId, $newStateId);
209
        } catch (DBALException $e) {
210
            throw new RuntimeException('Database error', 0, $e);
211
        } catch (PDOException $e) {
212
            throw new RuntimeException('Database error', 0, $e);
213
        }
214
    }
215
216
    /**
217
     * Deletes object state links identified by $stateId.
218
     *
219
     * @param int $stateId
220
     */
221 View Code Duplication
    public function deleteObjectStateLinks($stateId)
222
    {
223
        try {
224
            return $this->innerGateway->deleteObjectStateLinks($stateId);
225
        } catch (DBALException $e) {
226
            throw new RuntimeException('Database error', 0, $e);
227
        } catch (PDOException $e) {
228
            throw new RuntimeException('Database error', 0, $e);
229
        }
230
    }
231
232
    /**
233
     * Inserts a new object state group into database.
234
     *
235
     * @param \eZ\Publish\SPI\Persistence\Content\ObjectState\Group $objectStateGroup
236
     */
237 View Code Duplication
    public function insertObjectStateGroup(Group $objectStateGroup)
238
    {
239
        try {
240
            return $this->innerGateway->insertObjectStateGroup($objectStateGroup);
241
        } catch (DBALException $e) {
242
            throw new RuntimeException('Database error', 0, $e);
243
        } catch (PDOException $e) {
244
            throw new RuntimeException('Database error', 0, $e);
245
        }
246
    }
247
248
    /**
249
     * Updates the stored object state group with provided data.
250
     *
251
     * @param \eZ\Publish\SPI\Persistence\Content\ObjectState\Group $objectStateGroup
252
     */
253 View Code Duplication
    public function updateObjectStateGroup(Group $objectStateGroup)
254
    {
255
        try {
256
            return $this->innerGateway->updateObjectStateGroup($objectStateGroup);
257
        } catch (DBALException $e) {
258
            throw new RuntimeException('Database error', 0, $e);
259
        } catch (PDOException $e) {
260
            throw new RuntimeException('Database error', 0, $e);
261
        }
262
    }
263
264
    /**
265
     * Deletes the object state group identified by $groupId.
266
     *
267
     * @param mixed $groupId
268
     */
269 View Code Duplication
    public function deleteObjectStateGroup($groupId)
270
    {
271
        try {
272
            return $this->innerGateway->deleteObjectStateGroup($groupId);
273
        } catch (DBALException $e) {
274
            throw new RuntimeException('Database error', 0, $e);
275
        } catch (PDOException $e) {
276
            throw new RuntimeException('Database error', 0, $e);
277
        }
278
    }
279
280
    /**
281
     * Sets the object state $stateId to content with $contentId ID.
282
     *
283
     * @param mixed $contentId
284
     * @param mixed $groupId
285
     * @param mixed $stateId
286
     */
287 View Code Duplication
    public function setContentState($contentId, $groupId, $stateId)
288
    {
289
        try {
290
            return $this->innerGateway->setContentState($contentId, $groupId, $stateId);
291
        } catch (DBALException $e) {
292
            throw new RuntimeException('Database error', 0, $e);
293
        } catch (PDOException $e) {
294
            throw new RuntimeException('Database error', 0, $e);
295
        }
296
    }
297
298
    /**
299
     * Loads object state data for $contentId content from $stateGroupId state group.
300
     *
301
     * @param int $contentId
302
     * @param int $stateGroupId
303
     *
304
     * @return array
305
     */
306 View Code Duplication
    public function loadObjectStateDataForContent($contentId, $stateGroupId)
307
    {
308
        try {
309
            return $this->innerGateway->loadObjectStateDataForContent($contentId, $stateGroupId);
310
        } catch (DBALException $e) {
311
            throw new RuntimeException('Database error', 0, $e);
312
        } catch (PDOException $e) {
313
            throw new RuntimeException('Database error', 0, $e);
314
        }
315
    }
316
317
    /**
318
     * Returns the number of objects which are in this state.
319
     *
320
     * @param mixed $stateId
321
     *
322
     * @return int
323
     */
324 View Code Duplication
    public function getContentCount($stateId)
325
    {
326
        try {
327
            return $this->innerGateway->getContentCount($stateId);
328
        } catch (DBALException $e) {
329
            throw new RuntimeException('Database error', 0, $e);
330
        } catch (PDOException $e) {
331
            throw new RuntimeException('Database error', 0, $e);
332
        }
333
    }
334
335
    /**
336
     * Updates the object state priority to provided value.
337
     *
338
     * @param mixed $stateId
339
     * @param int $priority
340
     */
341 View Code Duplication
    public function updateObjectStatePriority($stateId, $priority)
342
    {
343
        try {
344
            return $this->innerGateway->updateObjectStatePriority($stateId, $priority);
345
        } catch (DBALException $e) {
346
            throw new RuntimeException('Database error', 0, $e);
347
        } catch (PDOException $e) {
348
            throw new RuntimeException('Database error', 0, $e);
349
        }
350
    }
351
}
352