|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only |
|
5
|
|
|
* SPDX-FileCopyrightText: Copyright 2007-2016 Zarafa Deutschland GmbH |
|
6
|
|
|
* SPDX-FileCopyrightText: Copyright 2020-2022 grommunio GmbH |
|
7
|
|
|
* |
|
8
|
|
|
* Defines general behavior of sub-WBXML entities (Sync* objects) that can be |
|
9
|
|
|
* parsed directly (as a stream) from WBXML. They are automatically decoded |
|
10
|
|
|
* according to $mapping by the Streamer and the Sync WBXML mappings. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
abstract class SyncObject extends Streamer implements Stringable { |
|
14
|
|
|
public const STREAMER_CHECKS = 6; |
|
15
|
|
|
public const STREAMER_CHECK_REQUIRED = 7; |
|
16
|
|
|
public const STREAMER_CHECK_ZEROORONE = 8; |
|
17
|
|
|
public const STREAMER_CHECK_NOTALLOWED = 9; |
|
18
|
|
|
public const STREAMER_CHECK_ONEVALUEOF = 10; |
|
19
|
|
|
public const STREAMER_CHECK_SETZERO = "setToValue0"; |
|
20
|
|
|
public const STREAMER_CHECK_SETONE = "setToValue1"; |
|
21
|
|
|
public const STREAMER_CHECK_SETTWO = "setToValue2"; |
|
22
|
|
|
public const STREAMER_CHECK_SETEMPTY = "setToValueEmpty"; |
|
23
|
|
|
public const STREAMER_CHECK_CMPLOWER = 13; |
|
24
|
|
|
public const STREAMER_CHECK_CMPHIGHER = 14; |
|
25
|
|
|
public const STREAMER_CHECK_LENGTHMAX = 15; |
|
26
|
|
|
public const STREAMER_CHECK_EMAIL = 16; |
|
27
|
|
|
|
|
28
|
|
|
protected $unsetVars; |
|
29
|
|
|
protected $supportsPrivateStripping; |
|
30
|
|
|
protected $checkedParameters; |
|
31
|
|
|
|
|
32
|
|
|
public function __construct($mapping) { |
|
33
|
|
|
$this->unsetVars = []; |
|
34
|
|
|
$this->supportsPrivateStripping = false; |
|
35
|
|
|
$this->checkedParameters = false; |
|
36
|
|
|
parent::__construct($mapping); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Sets all supported but not transmitted variables |
|
41
|
|
|
* of this SyncObject to an "empty" value, so they are deleted when being saved. |
|
42
|
|
|
* |
|
43
|
|
|
* @param array $supportedFields array with all supported fields, if available |
|
44
|
|
|
* |
|
45
|
|
|
* @return bool |
|
46
|
|
|
*/ |
|
47
|
|
|
public function emptySupported($supportedFields) { |
|
48
|
|
|
// Some devices do not send supported tag. In such a case remove all not set properties. |
|
49
|
|
|
if ($supportedFields === false || !is_array($supportedFields) || (empty($supportedFields))) { |
|
|
|
|
|
|
50
|
|
|
if (defined('UNSET_UNDEFINED_PROPERTIES') && |
|
51
|
|
|
UNSET_UNDEFINED_PROPERTIES && |
|
52
|
|
|
( |
|
53
|
|
|
$this instanceof SyncContact || |
|
54
|
|
|
$this instanceof SyncAppointment || |
|
55
|
|
|
$this instanceof SyncTask |
|
56
|
|
|
)) { |
|
57
|
|
|
SLog::Write(LOGLEVEL_INFO, sprintf("%s->emptySupported(): no supported list available, emptying all not set parameters", static::class)); |
|
58
|
|
|
$supportedFields = array_keys($this->mapping); |
|
59
|
|
|
} |
|
60
|
|
|
else { |
|
61
|
|
|
return false; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
foreach ($supportedFields as $field) { |
|
66
|
|
|
if (!isset($this->mapping[$field])) { |
|
67
|
|
|
SLog::Write(LOGLEVEL_WARN, sprintf("Field '%s' is supposed to be emptied but is not defined for '%s'", $field, static::class)); |
|
68
|
|
|
|
|
69
|
|
|
continue; |
|
70
|
|
|
} |
|
71
|
|
|
$var = $this->mapping[$field][self::STREAMER_VAR]; |
|
72
|
|
|
// add var to $this->unsetVars if $var is not set |
|
73
|
|
|
if (!isset($this->{$var})) { |
|
74
|
|
|
$this->unsetVars[] = $var; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
SLog::Write(LOGLEVEL_DEBUG, sprintf("Supported variables to be unset: %s", implode(',', $this->unsetVars))); |
|
78
|
|
|
|
|
79
|
|
|
return true; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Compares this a SyncObject to another. |
|
84
|
|
|
* In case that all available mapped fields are exactly EQUAL, it returns true. |
|
85
|
|
|
* |
|
86
|
|
|
* @see SyncObject |
|
87
|
|
|
* |
|
88
|
|
|
* @param SyncObject $odo other SyncObject |
|
89
|
|
|
* @param bool $log flag to turn on logging |
|
90
|
|
|
* @param bool $strictTypeCompare to enforce type matching |
|
91
|
|
|
* |
|
92
|
|
|
* @return bool |
|
93
|
|
|
*/ |
|
94
|
|
|
public function equals($odo, $log = false, $strictTypeCompare = false) { |
|
|
|
|
|
|
95
|
|
|
if ($odo === false) { |
|
|
|
|
|
|
96
|
|
|
return false; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
// check objecttype |
|
100
|
|
|
if (!$odo instanceof SyncObject) { |
|
|
|
|
|
|
101
|
|
|
SLog::Write(LOGLEVEL_DEBUG, "SyncObject->equals() the target object is not a SyncObject"); |
|
102
|
|
|
|
|
103
|
|
|
return false; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
// check for mapped fields |
|
107
|
|
|
foreach ($this->mapping as $v) { |
|
108
|
|
|
$val = $v[self::STREAMER_VAR]; |
|
109
|
|
|
// array of values? |
|
110
|
|
|
if (isset($v[self::STREAMER_ARRAY])) { |
|
111
|
|
|
// if neither array is created then don't fail the comparison |
|
112
|
|
|
if (!isset($this->{$val}) && !isset($odo->{$val})) { |
|
113
|
|
|
SLog::Write(LOGLEVEL_DEBUG, sprintf("SyncObject->equals() array '%s' is NOT SET in either object", $val)); |
|
114
|
|
|
|
|
115
|
|
|
continue; |
|
116
|
|
|
} |
|
117
|
|
|
if (is_array($this->{$val}) && is_array($odo->{$val})) { |
|
118
|
|
|
// if both arrays exist then seek for differences in the arrays |
|
119
|
|
|
if (count(array_diff($this->{$val}, $odo->{$val})) + count(array_diff($odo->{$val}, $this->{$val})) > 0) { |
|
120
|
|
|
SLog::Write(LOGLEVEL_DEBUG, sprintf("SyncObject->equals() items in array '%s' differ", $val)); |
|
121
|
|
|
|
|
122
|
|
|
return false; |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
else { |
|
126
|
|
|
SLog::Write(LOGLEVEL_DEBUG, sprintf("SyncObject->equals() array '%s' is set in one but not the other object", $val)); |
|
127
|
|
|
|
|
128
|
|
|
return false; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
else { |
|
132
|
|
|
if (isset($this->{$val}, $odo->{$val})) { |
|
133
|
|
|
if ($strictTypeCompare) { |
|
134
|
|
|
if ($this->{$val} !== $odo->{$val}) { |
|
135
|
|
|
SLog::Write(LOGLEVEL_DEBUG, sprintf("SyncObject->equals() false on field '%s': '%s' != '%s' using strictTypeCompare", $val, Utils::PrintAsString($this->{$val}), Utils::PrintAsString($odo->{$val}))); |
|
136
|
|
|
|
|
137
|
|
|
return false; |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
else { |
|
141
|
|
|
if ($this->{$val} != $odo->{$val}) { |
|
142
|
|
|
SLog::Write(LOGLEVEL_DEBUG, sprintf("SyncObject->equals() false on field '%s': '%s' != '%s'", $val, Utils::PrintAsString($this->{$val}), Utils::PrintAsString($odo->{$val}))); |
|
143
|
|
|
|
|
144
|
|
|
return false; |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
elseif (!isset($this->{$val}) && !isset($odo->{$val})) { |
|
149
|
|
|
continue; |
|
150
|
|
|
} |
|
151
|
|
|
else { |
|
152
|
|
|
SLog::Write(LOGLEVEL_DEBUG, sprintf("SyncObject->equals() false because field '%s' is only defined at one obj: '%s' != '%s'", $val, Utils::PrintAsString(isset($this->{$val})), Utils::PrintAsString(isset($odo->{$val})))); |
|
153
|
|
|
|
|
154
|
|
|
return false; |
|
155
|
|
|
} |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
return true; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* String representation of the object. |
|
164
|
|
|
*/ |
|
165
|
|
|
public function __toString(): string { |
|
166
|
|
|
$str = static::class . " (\n"; |
|
167
|
|
|
|
|
168
|
|
|
$streamerVars = []; |
|
169
|
|
|
foreach ($this->mapping as $k => $v) { |
|
170
|
|
|
$streamerVars[$v[self::STREAMER_VAR]] = $v[self::STREAMER_TYPE] ?? false; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
foreach (get_object_vars($this) as $k => $v) { |
|
174
|
|
|
if ($k == "mapping") { |
|
175
|
|
|
continue; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
if (array_key_exists($k, $streamerVars)) { |
|
179
|
|
|
$strV = "(S) "; |
|
180
|
|
|
} |
|
181
|
|
|
else { |
|
182
|
|
|
$strV = ""; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
// self::STREAMER_ARRAY ? |
|
186
|
|
|
if (is_array($v)) { |
|
187
|
|
|
$str .= "\t" . $strV . $k . "(Array) size: " . count($v) . "\n"; |
|
188
|
|
|
foreach ($v as $value) { |
|
189
|
|
|
$str .= "\t\t" . Utils::PrintAsString($value) . "\n"; |
|
190
|
|
|
} |
|
191
|
|
|
} |
|
192
|
|
|
elseif ($v instanceof SyncObject) { |
|
193
|
|
|
$str .= "\t" . $strV . $k . " => " . str_replace("\n", "\n\t\t\t", $v->__toString()) . "\n"; |
|
194
|
|
|
} |
|
195
|
|
|
else { |
|
196
|
|
|
$str .= "\t" . $strV . $k . " => " . (isset($this->{$k}) ? Utils::PrintAsString($this->{$k}) : "null") . "\n"; |
|
197
|
|
|
} |
|
198
|
|
|
} |
|
199
|
|
|
$str .= ")"; |
|
200
|
|
|
|
|
201
|
|
|
return $str; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* Returns the properties which have to be unset on the server. |
|
206
|
|
|
* |
|
207
|
|
|
* @return array |
|
208
|
|
|
*/ |
|
209
|
|
|
public function getUnsetVars() { |
|
210
|
|
|
return $this->unsetVars; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* Removes not necessary data from the object. |
|
215
|
|
|
* |
|
216
|
|
|
* @param mixed $flags |
|
217
|
|
|
* |
|
218
|
|
|
* @return bool |
|
219
|
|
|
*/ |
|
220
|
|
|
#[Override] |
|
221
|
|
|
public function StripData($flags = 0) { |
|
222
|
|
|
if ($flags === 0 && isset($this->unsetVars)) { |
|
223
|
|
|
unset($this->unsetVars); |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
return parent::StripData($flags); |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
/** |
|
230
|
|
|
* Indicates if a SyncObject supports the private flag and stripping of private data. |
|
231
|
|
|
* If an object does not support it, it will not be sent to the client but permanently be excluded from the sync. |
|
232
|
|
|
* |
|
233
|
|
|
* @return bool - default false defined in constructor - overwritten by implementation |
|
234
|
|
|
*/ |
|
235
|
|
|
public function SupportsPrivateStripping() { |
|
236
|
|
|
return $this->supportsPrivateStripping; |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
/** |
|
240
|
|
|
* Indicates the amount of parameters that were set before Checks were executed and potentially set other parameters. |
|
241
|
|
|
* |
|
242
|
|
|
* @return bool/int - returns false if Check() was not executed |
|
|
|
|
|
|
243
|
|
|
*/ |
|
244
|
|
|
public function getCheckedParameters() { |
|
245
|
|
|
return $this->checkedParameters; |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* Method checks if the object has the minimum of required parameters |
|
250
|
|
|
* and fulfills semantic dependencies. |
|
251
|
|
|
* |
|
252
|
|
|
* General checks: |
|
253
|
|
|
* STREAMER_CHECK_REQUIRED may have as value false (do not fix, ignore object!) or set-to-values: STREAMER_CHECK_SETZERO/ONE/TWO, STREAMER_CHECK_SETEMPTY |
|
254
|
|
|
* STREAMER_CHECK_ZEROORONE may be 0 or 1, if none of these, set-to-values: STREAMER_CHECK_SETZERO or STREAMER_CHECK_SETONE |
|
255
|
|
|
* STREAMER_CHECK_NOTALLOWED fails if is set |
|
256
|
|
|
* STREAMER_CHECK_ONEVALUEOF expects an array with accepted values, fails if value is not in array |
|
257
|
|
|
* |
|
258
|
|
|
* Comparison: |
|
259
|
|
|
* STREAMER_CHECK_CMPLOWER compares if the current parameter is lower as a literal or another parameter of the same object |
|
260
|
|
|
* STREAMER_CHECK_CMPHIGHER compares if the current parameter is higher as a literal or another parameter of the same object |
|
261
|
|
|
* |
|
262
|
|
|
* @param bool $logAsDebug (opt) default is false, so messages are logged in WARN log level |
|
263
|
|
|
* |
|
264
|
|
|
* @return bool |
|
265
|
|
|
*/ |
|
266
|
|
|
public function Check($logAsDebug = false) { |
|
267
|
|
|
// semantic checks general "turn off switch" |
|
268
|
|
|
if (defined("DO_SEMANTIC_CHECKS") && DO_SEMANTIC_CHECKS === false) { |
|
|
|
|
|
|
269
|
|
|
SLog::Write(LOGLEVEL_DEBUG, "SyncObject->Check(): semantic checks disabled. Check your config for 'DO_SEMANTIC_CHECKS'."); |
|
270
|
|
|
|
|
271
|
|
|
return true; |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
$defaultLogLevel = LOGLEVEL_WARN; |
|
275
|
|
|
$this->checkedParameters = 0; |
|
276
|
|
|
|
|
277
|
|
|
// in some cases non-false checks should not provoke a WARN log but only a DEBUG log |
|
278
|
|
|
if ($logAsDebug) { |
|
279
|
|
|
$defaultLogLevel = LOGLEVEL_DEBUG; |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
$objClass = static::class; |
|
283
|
|
|
foreach ($this->mapping as $k => $v) { |
|
284
|
|
|
// check sub-objects recursively |
|
285
|
|
|
if (isset($v[self::STREAMER_TYPE], $this->{$v[self::STREAMER_VAR]})) { |
|
286
|
|
|
if ($this->{$v[self::STREAMER_VAR]} instanceof SyncObject) { |
|
287
|
|
|
if (!$this->{$v[self::STREAMER_VAR]}->Check($logAsDebug)) { |
|
288
|
|
|
return false; |
|
289
|
|
|
} |
|
290
|
|
|
} |
|
291
|
|
|
elseif (is_array($this->{$v[self::STREAMER_VAR]})) { |
|
292
|
|
|
foreach ($this->{$v[self::STREAMER_VAR]} as $subobj) { |
|
293
|
|
|
if ($subobj instanceof SyncObject && !$subobj->Check($logAsDebug)) { |
|
294
|
|
|
return false; |
|
295
|
|
|
} |
|
296
|
|
|
} |
|
297
|
|
|
} |
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
if (isset($v[self::STREAMER_CHECKS])) { |
|
301
|
|
|
foreach ($v[self::STREAMER_CHECKS] as $rule => $condition) { |
|
302
|
|
|
// count parameter if it's set |
|
303
|
|
|
if (isset($this->{$v[self::STREAMER_VAR]})) { |
|
304
|
|
|
++$this->checkedParameters; |
|
305
|
|
|
} |
|
306
|
|
|
|
|
307
|
|
|
// check REQUIRED settings |
|
308
|
|
|
if ($rule === self::STREAMER_CHECK_REQUIRED && (!isset($this->{$v[self::STREAMER_VAR]}) || $this->{$v[self::STREAMER_VAR]} === '')) { |
|
309
|
|
|
// parameter is not set but .. |
|
310
|
|
|
// requested to set to 0 |
|
311
|
|
|
if ($condition === self::STREAMER_CHECK_SETZERO) { |
|
312
|
|
|
$this->{$v[self::STREAMER_VAR]} = 0; |
|
313
|
|
|
SLog::Write($defaultLogLevel, sprintf("SyncObject->Check(): Fixed object from type %s: parameter '%s' is set to 0", $objClass, $v[self::STREAMER_VAR])); |
|
314
|
|
|
} |
|
315
|
|
|
// requested to be set to 1 |
|
316
|
|
|
elseif ($condition === self::STREAMER_CHECK_SETONE) { |
|
317
|
|
|
$this->{$v[self::STREAMER_VAR]} = 1; |
|
318
|
|
|
SLog::Write($defaultLogLevel, sprintf("SyncObject->Check(): Fixed object from type %s: parameter '%s' is set to 1", $objClass, $v[self::STREAMER_VAR])); |
|
319
|
|
|
} |
|
320
|
|
|
// requested to be set to 2 |
|
321
|
|
|
elseif ($condition === self::STREAMER_CHECK_SETTWO) { |
|
322
|
|
|
$this->{$v[self::STREAMER_VAR]} = 2; |
|
323
|
|
|
SLog::Write($defaultLogLevel, sprintf("SyncObject->Check(): Fixed object from type %s: parameter '%s' is set to 2", $objClass, $v[self::STREAMER_VAR])); |
|
324
|
|
|
} |
|
325
|
|
|
// requested to be set to '' |
|
326
|
|
|
elseif ($condition === self::STREAMER_CHECK_SETEMPTY) { |
|
327
|
|
|
if (!isset($this->{$v[self::STREAMER_VAR]})) { |
|
328
|
|
|
$this->{$v[self::STREAMER_VAR]} = ''; |
|
329
|
|
|
SLog::Write($defaultLogLevel, sprintf("SyncObject->Check(): Fixed object from type %s: parameter '%s' is set to ''", $objClass, $v[self::STREAMER_VAR])); |
|
330
|
|
|
} |
|
331
|
|
|
} |
|
332
|
|
|
// there is another value !== false |
|
333
|
|
|
elseif ($condition !== false) { |
|
334
|
|
|
$this->{$v[self::STREAMER_VAR]} = $condition; |
|
335
|
|
|
SLog::Write($defaultLogLevel, sprintf("SyncObject->Check(): Fixed object from type %s: parameter '%s' is set to '%s'", $objClass, $v[self::STREAMER_VAR], $condition)); |
|
336
|
|
|
} |
|
337
|
|
|
// no fix available! |
|
338
|
|
|
else { |
|
339
|
|
|
SLog::Write($defaultLogLevel, sprintf("SyncObject->Check(): Unmet condition in object from type %s: parameter '%s' is required but not set. Check failed!", $objClass, $v[self::STREAMER_VAR])); |
|
340
|
|
|
|
|
341
|
|
|
return false; |
|
342
|
|
|
} |
|
343
|
|
|
} // end STREAMER_CHECK_REQUIRED |
|
344
|
|
|
|
|
345
|
|
|
// check STREAMER_CHECK_ZEROORONE |
|
346
|
|
|
if ($rule === self::STREAMER_CHECK_ZEROORONE && isset($this->{$v[self::STREAMER_VAR]})) { |
|
347
|
|
|
if ($this->{$v[self::STREAMER_VAR]} != 0 && $this->{$v[self::STREAMER_VAR]} != 1) { |
|
348
|
|
|
$newval = $condition === self::STREAMER_CHECK_SETZERO ? 0 : 1; |
|
349
|
|
|
$this->{$v[self::STREAMER_VAR]} = $newval; |
|
350
|
|
|
SLog::Write($defaultLogLevel, sprintf("SyncObject->Check(): Fixed object from type %s: parameter '%s' is set to '%s' as it was not 0 or 1", $objClass, $v[self::STREAMER_VAR], $newval)); |
|
351
|
|
|
} |
|
352
|
|
|
}// end STREAMER_CHECK_ZEROORONE |
|
353
|
|
|
|
|
354
|
|
|
// check STREAMER_CHECK_ONEVALUEOF |
|
355
|
|
|
if ($rule === self::STREAMER_CHECK_ONEVALUEOF && isset($this->{$v[self::STREAMER_VAR]})) { |
|
356
|
|
|
if (!in_array($this->{$v[self::STREAMER_VAR]}, $condition)) { |
|
357
|
|
|
SLog::Write($defaultLogLevel, sprintf("SyncObject->Check(): object from type %s: parameter '%s'->'%s' is not in the range of allowed values.", $objClass, $v[self::STREAMER_VAR], $this->{$v[self::STREAMER_VAR]})); |
|
358
|
|
|
|
|
359
|
|
|
return false; |
|
360
|
|
|
} |
|
361
|
|
|
}// end STREAMER_CHECK_ONEVALUEOF |
|
362
|
|
|
|
|
363
|
|
|
// Check value compared to other value or literal |
|
364
|
|
|
if ($rule === self::STREAMER_CHECK_CMPHIGHER || $rule === self::STREAMER_CHECK_CMPLOWER) { |
|
365
|
|
|
if (isset($this->{$v[self::STREAMER_VAR]})) { |
|
366
|
|
|
$cmp = false; |
|
367
|
|
|
// directly compare against literals |
|
368
|
|
|
if (is_int($condition)) { |
|
369
|
|
|
$cmp = $condition; |
|
370
|
|
|
} |
|
371
|
|
|
// check for invalid compare-to |
|
372
|
|
|
elseif (!isset($this->mapping[$condition])) { |
|
373
|
|
|
SLog::Write(LOGLEVEL_ERROR, sprintf("SyncObject->Check(): Can not compare parameter '%s' against the other value '%s' as it is not defined object from type %s. Please report this! Check skipped!", $objClass, $v[self::STREAMER_VAR], $condition)); |
|
374
|
|
|
|
|
375
|
|
|
continue; |
|
376
|
|
|
} |
|
377
|
|
|
else { |
|
378
|
|
|
$cmpPar = $this->mapping[$condition][self::STREAMER_VAR]; |
|
379
|
|
|
if (isset($this->{$cmpPar})) { |
|
380
|
|
|
$cmp = $this->{$cmpPar}; |
|
381
|
|
|
} |
|
382
|
|
|
} |
|
383
|
|
|
|
|
384
|
|
|
if ($cmp === false) { |
|
385
|
|
|
SLog::Write(LOGLEVEL_WARN, sprintf("SyncObject->Check(): Unmet condition in object from type %s: parameter '%s' can not be compared, as the comparable is not set. Check failed!", $objClass, $v[self::STREAMER_VAR])); |
|
386
|
|
|
|
|
387
|
|
|
return false; |
|
388
|
|
|
} |
|
389
|
|
|
if ( |
|
390
|
|
|
($rule == self::STREAMER_CHECK_CMPHIGHER && intval($this->{$v[self::STREAMER_VAR]}) < $cmp) || |
|
391
|
|
|
($rule == self::STREAMER_CHECK_CMPLOWER && intval($this->{$v[self::STREAMER_VAR]}) > $cmp) |
|
392
|
|
|
) { |
|
393
|
|
|
SLog::Write(LOGLEVEL_WARN, sprintf( |
|
394
|
|
|
"SyncObject->Check(): Unmet condition in object from type %s: parameter '%s' is %s than '%s'. Check failed!", |
|
395
|
|
|
$objClass, |
|
396
|
|
|
$v[self::STREAMER_VAR], |
|
397
|
|
|
($rule === self::STREAMER_CHECK_CMPHIGHER) ? 'LOWER' : 'HIGHER', |
|
398
|
|
|
$cmpPar ?? $condition |
|
399
|
|
|
)); |
|
400
|
|
|
|
|
401
|
|
|
return false; |
|
402
|
|
|
} |
|
403
|
|
|
} |
|
404
|
|
|
} // STREAMER_CHECK_CMP* |
|
405
|
|
|
|
|
406
|
|
|
// check STREAMER_CHECK_LENGTHMAX |
|
407
|
|
|
if ($rule === self::STREAMER_CHECK_LENGTHMAX && isset($this->{$v[self::STREAMER_VAR]})) { |
|
408
|
|
|
if (is_array($this->{$v[self::STREAMER_VAR]})) { |
|
409
|
|
|
// implosion takes 2bytes, so we just assume ", " here |
|
410
|
|
|
$chkstr = implode(", ", $this->{$v[self::STREAMER_VAR]}); |
|
411
|
|
|
} |
|
412
|
|
|
else { |
|
413
|
|
|
$chkstr = $this->{$v[self::STREAMER_VAR]}; |
|
414
|
|
|
} |
|
415
|
|
|
|
|
416
|
|
|
if (strlen((string) $chkstr) > $condition) { |
|
417
|
|
|
SLog::Write(LOGLEVEL_WARN, sprintf("SyncObject->Check(): object from type %s: parameter '%s' is longer than %d. Check failed", $objClass, $v[self::STREAMER_VAR], $condition)); |
|
418
|
|
|
|
|
419
|
|
|
return false; |
|
420
|
|
|
} |
|
421
|
|
|
}// end STREAMER_CHECK_LENGTHMAX |
|
422
|
|
|
|
|
423
|
|
|
// check STREAMER_CHECK_EMAIL |
|
424
|
|
|
// if $condition is false then the check really fails. Otherwise invalid emails are removed. |
|
425
|
|
|
// if nothing is left (all emails were false), the parameter is set to condition |
|
426
|
|
|
if ($rule === self::STREAMER_CHECK_EMAIL && isset($this->{$v[self::STREAMER_VAR]})) { |
|
427
|
|
|
if ($condition === false && ((is_array($this->{$v[self::STREAMER_VAR]}) && empty($this->{$v[self::STREAMER_VAR]})) || strlen($this->{$v[self::STREAMER_VAR]}) == 0)) { |
|
428
|
|
|
continue; |
|
429
|
|
|
} |
|
430
|
|
|
|
|
431
|
|
|
$as_array = false; |
|
432
|
|
|
|
|
433
|
|
|
if (is_array($this->{$v[self::STREAMER_VAR]})) { |
|
434
|
|
|
$mails = $this->{$v[self::STREAMER_VAR]}; |
|
435
|
|
|
$as_array = true; |
|
436
|
|
|
} |
|
437
|
|
|
else { |
|
438
|
|
|
$mails = [$this->{$v[self::STREAMER_VAR]}]; |
|
439
|
|
|
} |
|
440
|
|
|
|
|
441
|
|
|
$output = []; |
|
442
|
|
|
foreach ($mails as $mail) { |
|
443
|
|
|
if (!Utils::CheckEmail($mail)) { |
|
444
|
|
|
SLog::Write(LOGLEVEL_WARN, sprintf("SyncObject->Check(): object from type %s: parameter '%s' contains an invalid email address '%s'. Address is removed.", $objClass, $v[self::STREAMER_VAR], $mail)); |
|
445
|
|
|
} |
|
446
|
|
|
else { |
|
447
|
|
|
$output[] = $mail; |
|
448
|
|
|
} |
|
449
|
|
|
} |
|
450
|
|
|
if (count($mails) != count($output)) { |
|
451
|
|
|
if ($condition === false) { |
|
452
|
|
|
return false; |
|
453
|
|
|
} |
|
454
|
|
|
|
|
455
|
|
|
// nothing left, use $condition as new value |
|
456
|
|
|
if (count($output) == 0) { |
|
457
|
|
|
$output[] = $condition; |
|
458
|
|
|
} |
|
459
|
|
|
|
|
460
|
|
|
// if we are allowed to rewrite the attribute, we do that |
|
461
|
|
|
if ($as_array) { |
|
462
|
|
|
$this->{$v[self::STREAMER_VAR]} = $output; |
|
463
|
|
|
} |
|
464
|
|
|
else { |
|
465
|
|
|
$this->{$v[self::STREAMER_VAR]} = $output[0]; |
|
466
|
|
|
} |
|
467
|
|
|
} |
|
468
|
|
|
}// end STREAMER_CHECK_EMAIL |
|
469
|
|
|
} // foreach CHECKS |
|
470
|
|
|
} // isset CHECKS |
|
471
|
|
|
} // foreach mapping |
|
472
|
|
|
|
|
473
|
|
|
return true; |
|
474
|
|
|
} |
|
475
|
|
|
|
|
476
|
|
|
/** |
|
477
|
|
|
* Returns human friendly property name from its value if a mapping is available. |
|
478
|
|
|
* |
|
479
|
|
|
* @param array $v |
|
480
|
|
|
* @param mixed $val |
|
481
|
|
|
* |
|
482
|
|
|
* @return mixed |
|
483
|
|
|
*/ |
|
484
|
|
|
public function GetNameFromPropertyValue($v, $val) { |
|
485
|
|
|
return $v[self::STREAMER_VALUEMAP][$val] ?? $val; |
|
486
|
|
|
} |
|
487
|
|
|
|
|
488
|
|
|
/** |
|
489
|
|
|
* Called after the SyncObject was unserialized. |
|
490
|
|
|
* |
|
491
|
|
|
* @return bool |
|
492
|
|
|
*/ |
|
493
|
|
|
public function postUnserialize() { |
|
494
|
|
|
return true; |
|
495
|
|
|
} |
|
496
|
|
|
} |
|
497
|
|
|
|