|
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 array $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 exists", |
|
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 this 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::OBJECT_DELETED => "Object deleted", |
|
65
|
|
|
self::OBJECT_PURGED => "Object purged", |
|
66
|
|
|
self::OBJECT_EXPORTED => "Object already exported", |
|
67
|
|
|
self::OBJECT_IMPORTED => "Object already imported", |
|
68
|
|
|
self::MISSED_DEPENDENCE => "Missed dependence for object", |
|
69
|
|
|
self::TREE_IS_CIRCULAR => "Circular reference found in object's tree", |
|
70
|
|
|
self::OBJECT_IS_LOCKED => "Object is locked", |
|
71
|
|
|
]; |
|
72
|
|
|
|
|
73
|
125 |
|
public function __construct($message = "Undefined error", $code = self::ERROR, ?base_exception $previous = null) |
|
74
|
|
|
{ |
|
75
|
125 |
|
midgard_connection::get_instance()->set_error($code); |
|
76
|
125 |
|
midgard_connection::get_instance()->set_error_string($message); |
|
77
|
125 |
|
parent::__construct($message, $code, $previous); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
118 |
|
public static function ok() : self |
|
81
|
|
|
{ |
|
82
|
118 |
|
return new self(self::$messages[self::OK], self::OK); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
4 |
|
public static function access_denied() : self |
|
86
|
|
|
{ |
|
87
|
4 |
|
return new self(self::$messages[self::ACCESS_DENIED], self::ACCESS_DENIED); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
4 |
|
public static function no_metadata() : self |
|
91
|
|
|
{ |
|
92
|
4 |
|
return new self(self::$messages[self::NO_METADATA], self::NO_METADATA); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public static function not_object() : self |
|
96
|
|
|
{ |
|
97
|
|
|
return new self(self::$messages[self::NOT_OBJECT], self::NOT_OBJECT); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
12 |
|
public static function not_exists() : self |
|
101
|
|
|
{ |
|
102
|
12 |
|
return new self(self::$messages[self::NOT_EXISTS], self::NOT_EXISTS); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public static function invalid_name() : self |
|
106
|
|
|
{ |
|
107
|
|
|
return new self(self::$messages[self::INVALID_NAME], self::INVALID_NAME); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
4 |
|
public static function duplicate() : self |
|
111
|
|
|
{ |
|
112
|
4 |
|
return new self(self::$messages[self::DUPLICATE], self::DUPLICATE); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
5 |
|
public static function has_dependants() : self |
|
116
|
|
|
{ |
|
117
|
5 |
|
return new self(self::$messages[self::HAS_DEPENDANTS], self::HAS_DEPENDANTS); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public static function range() : self |
|
121
|
|
|
{ |
|
122
|
|
|
return new self(self::$messages[self::RANGE], self::RANGE); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public static function not_connected() : self |
|
126
|
|
|
{ |
|
127
|
|
|
return new self(self::$messages[self::NOT_CONNECTED], self::NOT_CONNECTED); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
public static function sg_notfound() : self |
|
131
|
|
|
{ |
|
132
|
|
|
return new self(self::$messages[self::SG_NOTFOUND], self::SG_NOTFOUND); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
public static function invalid_object() : self |
|
136
|
|
|
{ |
|
137
|
|
|
return new self(self::$messages[self::INVALID_OBJECT], self::INVALID_OBJECT); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
public static function quota() : self |
|
141
|
|
|
{ |
|
142
|
|
|
return new self(self::$messages[self::QUOTA], self::QUOTA); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
2 |
|
public static function internal(base_exception $exception) : self |
|
146
|
|
|
{ |
|
147
|
2 |
|
$message = self::$messages[self::INTERNAL]; |
|
148
|
2 |
|
connection::log()->critical($message, ['exception' => $exception]); |
|
149
|
2 |
|
return new self($message . ': ' . $exception->getMessage(), self::INTERNAL, $exception); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
2 |
|
public static function object_name_exists() : self |
|
153
|
|
|
{ |
|
154
|
2 |
|
return new self(self::$messages[self::OBJECT_NAME_EXISTS], self::OBJECT_NAME_EXISTS); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
public static function object_no_storage() : self |
|
158
|
|
|
{ |
|
159
|
|
|
return new self(self::$messages[self::OBJECT_NO_STORAGE], self::OBJECT_NO_STORAGE); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
1 |
|
public static function object_no_parent() : self |
|
163
|
|
|
{ |
|
164
|
1 |
|
return new self(self::$messages[self::OBJECT_NO_PARENT], self::OBJECT_NO_PARENT); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
11 |
|
public static function invalid_property_value(?string $message = null) : self |
|
168
|
|
|
{ |
|
169
|
11 |
|
$message ??= self::$messages[self::INVALID_PROPERTY_VALUE]; |
|
170
|
11 |
|
return new self($message, self::INVALID_PROPERTY_VALUE); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
3 |
|
public static function invalid_property(string $property) : self |
|
174
|
|
|
{ |
|
175
|
3 |
|
return new self(self::$messages[self::INVALID_PROPERTY] . ' "' . $property . '"', self::INVALID_PROPERTY); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
public static function user_data(string $message = 'Unknown error') : self |
|
179
|
|
|
{ |
|
180
|
|
|
return new self($message, self::USER_DATA); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
1 |
|
public static function object_deleted() : self |
|
184
|
|
|
{ |
|
185
|
1 |
|
return new self(self::$messages[self::OBJECT_DELETED], self::OBJECT_DELETED); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
4 |
|
public static function object_purged() : self |
|
189
|
|
|
{ |
|
190
|
4 |
|
return new self(self::$messages[self::OBJECT_PURGED], self::OBJECT_PURGED); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
public static function object_exported() : self |
|
194
|
|
|
{ |
|
195
|
|
|
return new self(self::$messages[self::OBJECT_EXPORTED], self::OBJECT_EXPORTED); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
1 |
|
public static function object_imported() : self |
|
199
|
|
|
{ |
|
200
|
1 |
|
return new self(self::$messages[self::OBJECT_IMPORTED], self::OBJECT_IMPORTED); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
public static function missed_dependence() : self |
|
204
|
|
|
{ |
|
205
|
|
|
return new self(self::$messages[self::MISSED_DEPENDENCE], self::MISSED_DEPENDENCE); |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
1 |
|
public static function tree_is_circular() : self |
|
209
|
|
|
{ |
|
210
|
1 |
|
return new self(self::$messages[self::TREE_IS_CIRCULAR], self::TREE_IS_CIRCULAR); |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
1 |
|
public static function object_is_locked() : self |
|
214
|
|
|
{ |
|
215
|
1 |
|
return new self(self::$messages[self::OBJECT_IS_LOCKED], self::OBJECT_IS_LOCKED); |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
53 |
|
public static function get_error_string(int $code) : string |
|
219
|
|
|
{ |
|
220
|
53 |
|
return self::$messages[$code] ?? "Undefined error"; |
|
221
|
|
|
} |
|
222
|
|
|
} |
|
223
|
|
|
|