chg: [event:updateEventReportBeforeSync] Make sure remote instance

supports event report
pull/6412/head
mokaddem 2020-10-02 16:10:35 +02:00
parent aefcd41b87
commit f4c846b5a1
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 22 additions and 0 deletions

View File

@ -1292,6 +1292,9 @@ class Event extends AppModel
}
$data['EventReport'] = array_values($data['EventReport']);
}
if (isset($data['EventReport']) && empty($data['EventReport'])) {
unset($data['EventReport']);
}
return $data;
}
@ -1412,6 +1415,25 @@ class Event extends AppModel
if (!$server['Server']['internal'] && $report['distribution'] < 2) {
return false;
}
// check if remote version support event reports
$eventReportSupportedByRemote = false;
$uri = $server['Server']['url'] . '/eventReports/add';
try {
$response = $HttpSocket->get($uri, false, $request);
if ($response->isOk()) {
$apiDescription = json_decode($response->body, true);
$eventReportSupportedByRemote = !empty($apiDescription['description']);
}
} catch (Exception $e) {
$this->Log = ClassRegistry::init('Log');
$message = __('Remote version does not support event report.');
$this->Log->createLogEntry('SYSTEM', $action, 'Server', $id, $message);
}
if (!$eventReportSupportedByRemote) {
return [];
}
// Downgrade the object from connected communities to community only
if (!$server['Server']['internal'] && $report['distribution'] == 2) {
$report['distribution'] = 1;