|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
declare(strict_types=1); |
|
8
|
|
|
|
|
9
|
|
|
namespace eZ\Publish\Core\Persistence\Legacy\Notification\Gateway; |
|
10
|
|
|
|
|
11
|
|
|
use Doctrine\DBAL\DBALException; |
|
12
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Notification\Gateway; |
|
13
|
|
|
use eZ\Publish\SPI\Persistence\Notification\CreateStruct; |
|
14
|
|
|
use eZ\Publish\SPI\Persistence\Notification\Notification; |
|
15
|
|
|
use PDOException; |
|
16
|
|
|
use RuntimeException; |
|
17
|
|
|
|
|
18
|
|
|
class ExceptionConversion extends Gateway |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* The wrapped gateway. |
|
22
|
|
|
* |
|
23
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\Notification\Gateway |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $innerGateway; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* ExceptionConversion constructor. |
|
29
|
|
|
* |
|
30
|
|
|
* @param \eZ\Publish\Core\Persistence\Legacy\Notification\Gateway $innerGateway |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct(Gateway $innerGateway) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->innerGateway = $innerGateway; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* {@inheritdoc} |
|
39
|
|
|
*/ |
|
40
|
|
|
public function getNotificationById(int $notificationId): array |
|
41
|
|
|
{ |
|
42
|
|
|
try { |
|
43
|
|
|
return $this->innerGateway->getNotificationById($notificationId); |
|
44
|
|
|
} catch (DBALException | PDOException $e) { |
|
45
|
|
|
throw new RuntimeException('Database error', 0, $e); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritdoc} |
|
51
|
|
|
*/ |
|
52
|
|
|
public function updateNotification(Notification $notification): void |
|
53
|
|
|
{ |
|
54
|
|
|
try { |
|
55
|
|
|
$this->innerGateway->updateNotification($notification); |
|
56
|
|
|
} catch (DBALException | PDOException $e) { |
|
57
|
|
|
throw new RuntimeException('Database error', 0, $e); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* {@inheritdoc} |
|
63
|
|
|
*/ |
|
64
|
|
|
public function countUserNotifications(int $userId): int |
|
65
|
|
|
{ |
|
66
|
|
|
try { |
|
67
|
|
|
return $this->innerGateway->countUserNotifications($userId); |
|
68
|
|
|
} catch (DBALException | PDOException $e) { |
|
69
|
|
|
throw new RuntimeException('Database error', 0, $e); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* {@inheritdoc} |
|
75
|
|
|
*/ |
|
76
|
|
|
public function countUserPendingNotifications(int $userId): int |
|
77
|
|
|
{ |
|
78
|
|
|
try { |
|
79
|
|
|
return $this->innerGateway->countUserPendingNotifications($userId); |
|
80
|
|
|
} catch (DBALException | PDOException $e) { |
|
81
|
|
|
throw new RuntimeException('Database error', 0, $e); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* {@inheritdoc} |
|
87
|
|
|
*/ |
|
88
|
|
|
public function loadUserNotifications(int $userId, int $offset = 0, int $limit = -1): array |
|
89
|
|
|
{ |
|
90
|
|
|
try { |
|
91
|
|
|
return $this->innerGateway->loadUserNotifications($userId, $offset, $limit); |
|
92
|
|
|
} catch (DBALException | PDOException $e) { |
|
93
|
|
|
throw new RuntimeException('Database error', 0, $e); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Store Notification ValueObject in persistent storage. |
|
99
|
|
|
* |
|
100
|
|
|
* @param \eZ\Publish\SPI\Persistence\Notification\CreateStruct $notification |
|
101
|
|
|
* |
|
102
|
|
|
* @return int |
|
103
|
|
|
*/ |
|
104
|
|
|
public function insert(CreateStruct $notification): int |
|
105
|
|
|
{ |
|
106
|
|
|
try { |
|
107
|
|
|
return $this->innerGateway->insert($notification); |
|
108
|
|
|
} catch (DBALException | PDOException $e) { |
|
109
|
|
|
throw new RuntimeException('Database error', 0, $e); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @param int $notificationId |
|
115
|
|
|
*/ |
|
116
|
|
|
public function delete(int $notificationId): void |
|
117
|
|
|
{ |
|
118
|
|
|
try { |
|
119
|
|
|
$this->innerGateway->delete($notificationId); |
|
120
|
|
|
} catch (DBALException | PDOException $e) { |
|
121
|
|
|
throw new RuntimeException('Database error', 0, $e); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|