mirror of https://github.com/MISP/MISP
chg: [internal] Code style for event pulling
parent
a8f9c0642a
commit
466ee6b87b
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue