chg: [internal] Code style for event pulling

pull/7639/head
Jakub Onderka 2021-08-11 09:46:55 +02:00
parent a8f9c0642a
commit 466ee6b87b
1 changed files with 11 additions and 17 deletions

View File

@ -246,6 +246,7 @@ class Server extends AppModel
* @param bool $force
* @return array
* @throws InvalidArgumentException
* @throws JsonException
*/
private function __getEventIdListBasedOnPullTechnique($technique, array $server, $force = false)
{
@ -272,7 +273,9 @@ class Server extends AppModel
private function __checkIfEventIsBlockedBeforePull($event)
{
if (Configure::read('MISP.enableEventBlocklisting') !== false) {
$this->EventBlocklist = ClassRegistry::init('EventBlocklist');
if (!isset($this->EventBlocklist)) {
$this->EventBlocklist = ClassRegistry::init('EventBlocklist');
}
if ($this->EventBlocklist->isBlocked($event['Event']['uuid'])) {
return true;
}
@ -379,7 +382,8 @@ class Server extends AppModel
return $event;
}
private function __checkIfEventSaveAble($event) {
private function __checkIfEventSaveAble($event)
{
if (!empty($event['Event']['Attribute'])) {
foreach ($event['Event']['Attribute'] as $attribute) {
if (empty($attribute['deleted'])) {
@ -411,7 +415,7 @@ class Server extends AppModel
return false;
}
private function __checkIfPulledEventExistsAndAddOrUpdate($event, $eventId, &$successes, &$fails, $eventModel, $server, $user, $jobId, $force = false)
private function __checkIfPulledEventExistsAndAddOrUpdate($event, $eventId, &$successes, &$fails, Event $eventModel, $server, $user, $jobId, $force = false)
{
// check if the event already exist (using the uuid)
$existingEvent = $eventModel->find('first', [
@ -430,7 +434,7 @@ class Server extends AppModel
$pubSubTool->event_save(array('Event' => $eventId, 'Server' => $server['Server']['id']), 'add_from_connected_server');
}
} else {
$fails[$eventId] = __('Failed (partially?) because of validation errors: ') . json_encode($eventModel->validationErrors, true);
$fails[$eventId] = __('Failed (partially?) because of validation errors: ') . json_encode($eventModel->validationErrors);
}
} else {
if (!$existingEvent['Event']['locked'] && !$server['Server']['internal']) {
@ -452,7 +456,7 @@ class Server extends AppModel
}
}
private function __pullEvent($eventId, &$successes, &$fails, $eventModel, $server, $user, $jobId, $force = false)
private function __pullEvent($eventId, &$successes, &$fails, Event $eventModel, $server, $user, $jobId, $force = false)
{
try {
$event = $eventModel->downloadEventFromServer($eventId, $server);
@ -539,6 +543,7 @@ class Server extends AppModel
return $message;
}
/** @var Event $eventModel */
$eventModel = ClassRegistry::init('Event');
$successes = array();
$fails = array();
@ -558,19 +563,8 @@ class Server extends AppModel
}
}
if (!empty($fails)) {
$this->Log = ClassRegistry::init('Log');
foreach ($fails as $eventid => $message) {
$this->Log->create();
$this->Log->save(array(
'org' => $user['Organisation']['name'],
'model' => 'Server',
'model_id' => $id,
'email' => $user['email'],
'action' => 'pull',
'user_id' => $user['id'],
'title' => 'Failed to pull event #' . $eventid . '.',
'change' => 'Reason: ' . $message
));
$this->loadLog()->createLogEntry($user, 'pull', 'Server', $id, "Failed to pull event #$eventid.", 'Reason: ' . $message);
}
}
if ($jobId) {