|
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\UserPreference\Gateway; |
|
10
|
|
|
|
|
11
|
|
|
use Doctrine\DBAL\DBALException; |
|
12
|
|
|
use eZ\Publish\Core\Persistence\Legacy\UserPreference\Gateway; |
|
13
|
|
|
use eZ\Publish\SPI\Persistence\UserPreference\UserPreferenceSetStruct; |
|
14
|
|
|
use PDOException; |
|
15
|
|
|
use RuntimeException; |
|
16
|
|
|
|
|
17
|
|
|
class ExceptionConversion extends Gateway |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* The wrapped gateway. |
|
21
|
|
|
* |
|
22
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\UserPreference\Gateway |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $innerGateway; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* ExceptionConversion constructor. |
|
28
|
|
|
* |
|
29
|
|
|
* @param \eZ\Publish\Core\Persistence\Legacy\UserPreference\Gateway $innerGateway |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct(Gateway $innerGateway) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->innerGateway = $innerGateway; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* {@inheritdoc} |
|
38
|
|
|
*/ |
|
39
|
|
|
public function getUserPreferenceByUserIdAndName(int $userId, string $name): array |
|
40
|
|
|
{ |
|
41
|
|
|
try { |
|
42
|
|
|
return $this->innerGateway->getUserPreferenceByUserIdAndName($userId, $name); |
|
43
|
|
|
} catch (DBALException | PDOException $e) { |
|
44
|
|
|
throw new RuntimeException('Database error', 0, $e); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* {@inheritdoc} |
|
50
|
|
|
*/ |
|
51
|
|
|
public function countUserPreferences(int $userId): int |
|
52
|
|
|
{ |
|
53
|
|
|
try { |
|
54
|
|
|
return $this->innerGateway->countUserPreferences($userId); |
|
55
|
|
|
} catch (DBALException | PDOException $e) { |
|
56
|
|
|
throw new RuntimeException('Database error', 0, $e); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* {@inheritdoc} |
|
62
|
|
|
*/ |
|
63
|
|
|
public function loadUserPreferences(int $userId, int $offset = 0, int $limit = -1): array |
|
64
|
|
|
{ |
|
65
|
|
|
try { |
|
66
|
|
|
return $this->innerGateway->loadUserPreferences($userId, $offset, $limit); |
|
67
|
|
|
} catch (DBALException | PDOException $e) { |
|
68
|
|
|
throw new RuntimeException('Database error', 0, $e); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* {@inheritdoc} |
|
74
|
|
|
*/ |
|
75
|
|
|
public function setUserPreference(UserPreferenceSetStruct $setStruct): int |
|
76
|
|
|
{ |
|
77
|
|
|
try { |
|
78
|
|
|
return $this->innerGateway->setUserPreference($setStruct); |
|
79
|
|
|
} catch (DBALException | PDOException $e) { |
|
80
|
|
|
throw new RuntimeException('Database error', 0, $e); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|