1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author CONTENT CONTROL http://www.contentcontrol-berlin.de/ |
4
|
|
|
* @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/ |
5
|
|
|
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License |
6
|
|
|
*/ |
7
|
|
|
namespace midgard\portable\api\error; |
8
|
|
|
|
9
|
|
|
use midgard\portable\storage\connection; |
10
|
|
|
use midgard_connection; |
11
|
|
|
use Exception as base_exception; |
12
|
|
|
|
13
|
|
|
class exception extends base_exception |
14
|
|
|
{ |
15
|
|
|
const OK = 0; |
16
|
|
|
const ERROR = -1; |
17
|
|
|
const ACCESS_DENIED = -2; |
18
|
|
|
const NO_METADATA = -3; |
19
|
|
|
const NOT_OBJECT = -4; |
20
|
|
|
const NOT_EXISTS = -5; |
21
|
|
|
const INVALID_NAME = -6; |
22
|
|
|
const DUPLICATE = -7; |
23
|
|
|
const HAS_DEPENDANTS = -8; |
24
|
|
|
const RANGE = -9; |
25
|
|
|
const NOT_CONNECTED = -10; |
26
|
|
|
const SG_NOTFOUND = -11; |
27
|
|
|
const INVALID_OBJECT = -12; |
28
|
|
|
const QUOTA = -13; |
29
|
|
|
const INTERNAL = -14; |
30
|
|
|
const OBJECT_NAME_EXISTS = -15; |
31
|
|
|
const OBJECT_NO_STORAGE = -16; |
32
|
|
|
const OBJECT_NO_PARENT = -17; |
33
|
|
|
const INVALID_PROPERTY_VALUE = -18; |
34
|
|
|
const INVALID_PROPERTY = -19; |
35
|
|
|
const USER_DATA = -20; |
36
|
|
|
const OBJECT_DELETED = -21; |
37
|
|
|
const OBJECT_PURGED = -22; |
38
|
|
|
const OBJECT_EXPORTED = -23; |
39
|
|
|
const OBJECT_IMPORTED = -24; |
40
|
|
|
const MISSED_DEPENDENCE = -25; |
41
|
|
|
const TREE_IS_CIRCULAR = -26; |
42
|
|
|
const OBJECT_IS_LOCKED = -27; |
43
|
|
|
|
44
|
|
|
private static $messages = [ |
45
|
|
|
self::OK => "MGD_ERR_OK", |
46
|
|
|
self::ACCESS_DENIED => "Access Denied.", |
47
|
|
|
self::NO_METADATA => "Metadata class not defined.", |
48
|
|
|
self::NOT_OBJECT => "Not Midgard Object.", |
49
|
|
|
self::NOT_EXISTS => "Object does not exist.", |
50
|
|
|
self::INVALID_NAME => "Invalid characters in object's name.", |
51
|
|
|
self::DUPLICATE => "Object already exist.", |
52
|
|
|
self::HAS_DEPENDANTS => "Object has dependants.", |
53
|
|
|
self::RANGE => "Date range error.", |
54
|
|
|
self::NOT_CONNECTED => "Not connected to the Midgard database.", |
55
|
|
|
self::SG_NOTFOUND => "Sitegroup not found.", |
56
|
|
|
self::INVALID_OBJECT => "Object not registered as Midgard Object.", |
57
|
|
|
self::QUOTA => "Quota limit reached.", |
58
|
|
|
self::INTERNAL => "Critical internal error. ", |
59
|
|
|
self::OBJECT_NAME_EXISTS => "Object with such name exists in tree.", |
60
|
|
|
self::OBJECT_NO_STORAGE => "Storage table not defined for object.", |
61
|
|
|
self::OBJECT_NO_PARENT => "Parent object in tree not defined.", |
62
|
|
|
self::INVALID_PROPERTY_VALUE => "Invalid property value.", |
63
|
|
|
self::INVALID_PROPERTY => "Invalid property.", |
64
|
|
|
self::USER_DATA => "", |
65
|
|
|
self::OBJECT_DELETED => "Object deleted.", |
66
|
|
|
self::OBJECT_PURGED => "Object purged.", |
67
|
|
|
self::OBJECT_EXPORTED => "Object already exported.", |
68
|
|
|
self::OBJECT_IMPORTED => "Object already imported.", |
69
|
|
|
self::MISSED_DEPENDENCE => "Missed dependence for object.", |
70
|
|
|
self::TREE_IS_CIRCULAR => "Circular reference found in object's tree.", |
71
|
|
|
self::OBJECT_IS_LOCKED => "Object is locked", |
72
|
|
|
]; |
73
|
|
|
|
74
|
122 |
|
public function __construct($message = "Undefined error", $code = self::ERROR, base_exception $previous = null) |
75
|
|
|
{ |
76
|
122 |
|
midgard_connection::get_instance()->set_error($code); |
77
|
122 |
|
midgard_connection::get_instance()->set_error_string($message); |
78
|
122 |
|
parent::__construct($message, $code, $previous); |
79
|
|
|
} |
80
|
|
|
|
81
|
115 |
|
public static function ok() : self |
82
|
|
|
{ |
83
|
115 |
|
return new self(self::$messages[self::OK], self::OK); |
84
|
|
|
} |
85
|
|
|
|
86
|
4 |
|
public static function access_denied() : self |
87
|
|
|
{ |
88
|
4 |
|
return new self(self::$messages[self::ACCESS_DENIED], self::ACCESS_DENIED); |
89
|
|
|
} |
90
|
|
|
|
91
|
4 |
|
public static function no_metadata() : self |
92
|
|
|
{ |
93
|
4 |
|
return new self(self::$messages[self::NO_METADATA], self::NO_METADATA); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public static function not_object() : self |
97
|
|
|
{ |
98
|
|
|
return new self(self::$messages[self::NOT_OBJECT], self::NOT_OBJECT); |
99
|
|
|
} |
100
|
|
|
|
101
|
11 |
|
public static function not_exists() : self |
102
|
|
|
{ |
103
|
11 |
|
return new self(self::$messages[self::NOT_EXISTS], self::NOT_EXISTS); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public static function invalid_name() : self |
107
|
|
|
{ |
108
|
|
|
return new self(self::$messages[self::INVALID_NAME], self::INVALID_NAME); |
109
|
|
|
} |
110
|
|
|
|
111
|
4 |
|
public static function duplicate() : self |
112
|
|
|
{ |
113
|
4 |
|
return new self(self::$messages[self::DUPLICATE], self::DUPLICATE); |
114
|
|
|
} |
115
|
|
|
|
116
|
5 |
|
public static function has_dependants() : self |
117
|
|
|
{ |
118
|
5 |
|
return new self(self::$messages[self::HAS_DEPENDANTS], self::HAS_DEPENDANTS); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public static function range() : self |
122
|
|
|
{ |
123
|
|
|
return new self(self::$messages[self::RANGE], self::RANGE); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public static function not_connected() : self |
127
|
|
|
{ |
128
|
|
|
return new self(self::$messages[self::NOT_CONNECTED], self::NOT_CONNECTED); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public static function sg_notfound() : self |
132
|
|
|
{ |
133
|
|
|
return new self(self::$messages[self::SG_NOTFOUND], self::SG_NOTFOUND); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public static function invalid_object() : self |
137
|
|
|
{ |
138
|
|
|
return new self(self::$messages[self::INVALID_OBJECT], self::INVALID_OBJECT); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public static function quota() : self |
142
|
|
|
{ |
143
|
|
|
return new self(self::$messages[self::QUOTA], self::QUOTA); |
144
|
|
|
} |
145
|
|
|
|
146
|
1 |
|
public static function internal(base_exception $exception) : self |
147
|
|
|
{ |
148
|
1 |
|
$message = self::$messages[self::INTERNAL]; |
149
|
1 |
|
connection::log()->critical($message, ['exception' => $exception]); |
150
|
1 |
|
return new self($message . '. ' . $exception->getMessage(), self::INTERNAL, $exception); |
151
|
|
|
} |
152
|
|
|
|
153
|
2 |
|
public static function object_name_exists() : self |
154
|
|
|
{ |
155
|
2 |
|
return new self(self::$messages[self::OBJECT_NAME_EXISTS], self::OBJECT_NAME_EXISTS); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
public static function object_no_storage() : self |
159
|
|
|
{ |
160
|
|
|
return new self(self::$messages[self::OBJECT_NO_STORAGE], self::OBJECT_NO_STORAGE); |
161
|
|
|
} |
162
|
|
|
|
163
|
1 |
|
public static function object_no_parent() : self |
164
|
|
|
{ |
165
|
1 |
|
return new self(self::$messages[self::OBJECT_NO_PARENT], self::OBJECT_NO_PARENT); |
166
|
|
|
} |
167
|
|
|
|
168
|
11 |
|
public static function invalid_property_value(string $message = null) : self |
169
|
|
|
{ |
170
|
11 |
|
if ($message === null) { |
171
|
9 |
|
$message = self::$messages[self::INVALID_PROPERTY_VALUE]; |
172
|
|
|
} |
173
|
11 |
|
return new self($message, self::INVALID_PROPERTY_VALUE); |
174
|
|
|
} |
175
|
|
|
|
176
|
3 |
|
public static function invalid_property(string $property) : self |
177
|
|
|
{ |
178
|
3 |
|
return new self(self::$messages[self::INVALID_PROPERTY] . ': ' . $property, self::INVALID_PROPERTY); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
public static function user_data(string $message = 'Unknown error') : self |
182
|
|
|
{ |
183
|
|
|
return new self($message, self::USER_DATA); |
184
|
|
|
} |
185
|
|
|
|
186
|
1 |
|
public static function object_deleted() : self |
187
|
|
|
{ |
188
|
1 |
|
return new self(self::$messages[self::OBJECT_DELETED], self::OBJECT_DELETED); |
189
|
|
|
} |
190
|
|
|
|
191
|
3 |
|
public static function object_purged() : self |
192
|
|
|
{ |
193
|
3 |
|
return new self(self::$messages[self::OBJECT_PURGED], self::OBJECT_PURGED); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
public static function object_exported() : self |
197
|
|
|
{ |
198
|
|
|
return new self(self::$messages[self::OBJECT_EXPORTED], self::OBJECT_EXPORTED); |
199
|
|
|
} |
200
|
|
|
|
201
|
1 |
|
public static function object_imported() : self |
202
|
|
|
{ |
203
|
1 |
|
return new self(self::$messages[self::OBJECT_IMPORTED], self::OBJECT_IMPORTED); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
public static function missed_dependence() : self |
207
|
|
|
{ |
208
|
|
|
return new self(self::$messages[self::MISSED_DEPENDENCE], self::MISSED_DEPENDENCE); |
209
|
|
|
} |
210
|
|
|
|
211
|
1 |
|
public static function tree_is_circular() : self |
212
|
|
|
{ |
213
|
1 |
|
return new self(self::$messages[self::TREE_IS_CIRCULAR], self::TREE_IS_CIRCULAR); |
214
|
|
|
} |
215
|
|
|
|
216
|
1 |
|
public static function object_is_locked() : self |
217
|
|
|
{ |
218
|
1 |
|
return new self(self::$messages[self::OBJECT_IS_LOCKED], self::OBJECT_IS_LOCKED); |
219
|
|
|
} |
220
|
|
|
|
221
|
52 |
|
public static function get_error_string(int $code) : string |
222
|
|
|
{ |
223
|
52 |
|
return self::$messages[$code] ?? "Undefined error"; |
224
|
|
|
} |
225
|
|
|
} |
226
|
|
|
|