1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the Language 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\Language\Gateway; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway; |
12
|
|
|
use eZ\Publish\SPI\Persistence\Content\Language; |
13
|
|
|
use Doctrine\DBAL\DBALException; |
14
|
|
|
use PDOException; |
15
|
|
|
use RuntimeException; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Language Handler. |
19
|
|
|
*/ |
20
|
|
|
class ExceptionConversion extends Gateway |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* The wrapped gateway. |
24
|
|
|
* |
25
|
|
|
* @var Gateway |
26
|
|
|
*/ |
27
|
|
|
protected $innerGateway; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Creates a new exception conversion gateway around $innerGateway. |
31
|
|
|
* |
32
|
|
|
* @param Gateway $innerGateway |
33
|
|
|
*/ |
34
|
|
|
public function __construct(Gateway $innerGateway) |
35
|
|
|
{ |
36
|
|
|
$this->innerGateway = $innerGateway; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Inserts the given $language. |
41
|
|
|
* |
42
|
|
|
* @param Language $language |
43
|
|
|
* |
44
|
|
|
* @return int ID of the new language |
45
|
|
|
*/ |
46
|
|
|
public function insertLanguage(Language $language) |
47
|
|
|
{ |
48
|
|
|
try { |
49
|
|
|
return $this->innerGateway->insertLanguage($language); |
50
|
|
|
} catch (DBALException $e) { |
51
|
|
|
throw new RuntimeException('Database error', 0, $e); |
52
|
|
|
} catch (PDOException $e) { |
53
|
|
|
throw new RuntimeException('Database error', 0, $e); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Updates the data of the given $language. |
59
|
|
|
* |
60
|
|
|
* @param Language $language |
61
|
|
|
*/ |
62
|
|
|
public function updateLanguage(Language $language) |
63
|
|
|
{ |
64
|
|
|
try { |
65
|
|
|
return $this->innerGateway->updateLanguage($language); |
66
|
|
|
} catch (DBALException $e) { |
67
|
|
|
throw new RuntimeException('Database error', 0, $e); |
68
|
|
|
} catch (PDOException $e) { |
69
|
|
|
throw new RuntimeException('Database error', 0, $e); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritdoc} |
75
|
|
|
*/ |
76
|
|
View Code Duplication |
public function loadLanguageListData(array $ids): iterable |
77
|
|
|
{ |
78
|
|
|
try { |
79
|
|
|
return $this->innerGateway->loadLanguageListData($ids); |
80
|
|
|
} catch (DBALException $e) { |
81
|
|
|
throw new RuntimeException('Database error', 0, $e); |
82
|
|
|
} catch (PDOException $e) { |
83
|
|
|
throw new RuntimeException('Database error', 0, $e); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* {@inheritdoc} |
89
|
|
|
*/ |
90
|
|
View Code Duplication |
public function loadLanguageListDataByLanguageCode(array $languageCodes): iterable |
91
|
|
|
{ |
92
|
|
|
try { |
93
|
|
|
return $this->innerGateway->loadLanguageListDataByLanguageCode($languageCodes); |
94
|
|
|
} catch (DBALException $e) { |
95
|
|
|
throw new RuntimeException('Database error', 0, $e); |
96
|
|
|
} catch (PDOException $e) { |
97
|
|
|
throw new RuntimeException('Database error', 0, $e); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Loads the data for all languages. |
103
|
|
|
* |
104
|
|
|
* @return string[][] |
105
|
|
|
*/ |
106
|
|
View Code Duplication |
public function loadAllLanguagesData() |
107
|
|
|
{ |
108
|
|
|
try { |
109
|
|
|
return $this->innerGateway->loadAllLanguagesData(); |
110
|
|
|
} catch (DBALException $e) { |
111
|
|
|
throw new RuntimeException('Database error', 0, $e); |
112
|
|
|
} catch (PDOException $e) { |
113
|
|
|
throw new RuntimeException('Database error', 0, $e); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Deletes the language with $id. |
119
|
|
|
* |
120
|
|
|
* @param int $id |
121
|
|
|
*/ |
122
|
|
View Code Duplication |
public function deleteLanguage($id) |
123
|
|
|
{ |
124
|
|
|
try { |
125
|
|
|
return $this->innerGateway->deleteLanguage($id); |
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
|
|
|
* Check whether a language may be deleted. |
135
|
|
|
* |
136
|
|
|
* @param int $id |
137
|
|
|
* |
138
|
|
|
* @return bool |
139
|
|
|
*/ |
140
|
|
View Code Duplication |
public function canDeleteLanguage($id) |
141
|
|
|
{ |
142
|
|
|
try { |
143
|
|
|
return $this->innerGateway->canDeleteLanguage($id); |
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
|
|
|
|