new: [sync] Block pulled events from being saved if they contain no attributes/objects

pull/4610/merge
iglocska 2019-06-04 14:51:31 +02:00
parent 2590b27334
commit 0bd0d7e090
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
1 changed files with 30 additions and 1 deletions

View File

@ -2202,6 +2202,31 @@ class Server extends AppModel
return $event;
}
private function __checkIfEventSaveAble($event) {
if (!empty($event['Event']['Attribute'])) {
foreach ($event['Event']['Attribute'] as $attribute) {
if (empty($attribute['deleted'])) {
return true;
}
}
}
if (!empty($event['Event']['Object'])) {
foreach ($event['Event']['Object'] as $object) {
if (!empty($object['deleted'])) {
continue;
}
if (!empty($object['Attribute'])) {
foreach ($object['Attribute'] as $attribute) {
if (empty($attribute['deleted'])) {
return true;
}
}
}
}
}
return false;
}
private function __checkIfPulledEventExistsAndAddOrUpdate($event, $eventId, &$successes, &$fails, $eventModel, $server, $user, $jobId)
{
// check if the event already exist (using the uuid)
@ -2243,7 +2268,11 @@ class Server extends AppModel
return false;
}
$event = $this->__updatePulledEventBeforeInsert($event, $server, $user);
$this->__checkIfPulledEventExistsAndAddOrUpdate($event, $eventId, $successes, $fails, $eventModel, $server, $user, $jobId);
if (!$this->__checkIfEventSaveAble($event)) {
$fails[$eventId] = __('Empty event detected.');
} else {
$this->__checkIfPulledEventExistsAndAddOrUpdate($event, $eventId, $successes, $fails, $eventModel, $server, $user, $jobId);
}
} else {
// error
$fails[$eventId] = __('failed downloading the event');