mirror of https://github.com/MISP/MISP
chg: [internal] Log when object reference could not be captured
parent
278492a5df
commit
75ea9c4a0a
|
@ -5651,13 +5651,13 @@ class EventsController extends AppController
|
|||
$objectRef['object_id'] = $ObjectResult;
|
||||
$objectRef['relationship_type'] = "preceded-by";
|
||||
$this->loadModel('MispObject');
|
||||
$result = $this->MispObject->ObjectReference->captureReference($objectRef, $eventId, $this->Auth->user(), false);
|
||||
$result = $this->MispObject->ObjectReference->captureReference($objectRef, $eventId);
|
||||
$objectRef['referenced_id'] = $temp['Object']['id'];
|
||||
$objectRef['referenced_uuid'] = $temp['Object']['uuid'];
|
||||
$objectRef['object_id'] = $PreviousObjRef['Object']['id'];
|
||||
$objectRef['relationship_type'] = "followed-by";
|
||||
$this->loadModel('MispObject');
|
||||
$result = $this->MispObject->ObjectReference->captureReference($objectRef, $eventId, $this->Auth->user(), false);
|
||||
$result = $this->MispObject->ObjectReference->captureReference($objectRef, $eventId);
|
||||
$PreviousObjRef = $temp;
|
||||
} else {
|
||||
$PreviousObjRef = $temp;
|
||||
|
|
|
@ -3852,9 +3852,12 @@ class Event extends AppModel
|
|||
foreach ($referencesToCapture as $referenceToCapture) {
|
||||
$result = $this->Object->ObjectReference->captureReference(
|
||||
$referenceToCapture,
|
||||
$this->id,
|
||||
$user
|
||||
$this->id
|
||||
);
|
||||
if ($result !== true) {
|
||||
$title = "Could not save object reference when capturing event with ID {$this->id}";
|
||||
$this->loadLog()->validationError($user, 'add', 'ObjectReference', $title, $result, $referenceToCapture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4071,7 +4074,11 @@ class Event extends AppModel
|
|||
foreach ($object['ObjectReference'] as $objectRef) {
|
||||
$nothingToChange = false;
|
||||
$objectRef['source_uuid'] = $object['uuid'];
|
||||
$result = $this->Object->ObjectReference->captureReference($objectRef, $this->id, $user);
|
||||
$result = $this->Object->ObjectReference->captureReference($objectRef, $this->id);
|
||||
if ($result !== true) {
|
||||
$title = "Could not save object reference when capturing event with ID {$this->id}";
|
||||
$this->loadLog()->validationError($user, 'edit', 'ObjectReference', $title, $result, $objectRef);
|
||||
}
|
||||
if ($result && !$nothingToChange) {
|
||||
$changed = true;
|
||||
}
|
||||
|
|
|
@ -250,6 +250,22 @@ class Log extends AppModel
|
|||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|string $user
|
||||
* @param string $action
|
||||
* @param string $model
|
||||
* @param string $title
|
||||
* @param array $validationErrors
|
||||
* @param array $fullObject
|
||||
* @throws Exception
|
||||
*/
|
||||
public function validationError($user, $action, $model, $title, array $validationErrors, array $fullObject)
|
||||
{
|
||||
$this->log($title, LOG_WARNING);
|
||||
$change = 'Validation errors: ' . json_encode($validationErrors) . ' Full ' . $model . ': ' . json_encode($fullObject);
|
||||
$this->createLogEntry($user, $action, $model, 0, $title, $change);
|
||||
}
|
||||
|
||||
// to combat a certain bug that causes the upgrade scripts to loop without being able to set the correct version
|
||||
// this function remedies a fixed upgrade bug instance by eliminating the massive number of erroneous upgrade log entries
|
||||
public function pruneUpdateLogs($jobId = false, $user)
|
||||
|
|
|
@ -191,7 +191,13 @@ class ObjectReference extends AppModel
|
|||
return true;
|
||||
}
|
||||
|
||||
public function captureReference($reference, $eventId, $user)
|
||||
/**
|
||||
* @param array $reference
|
||||
* @param int $eventId
|
||||
* @return array|bool
|
||||
* @throws Exception
|
||||
*/
|
||||
public function captureReference(array $reference, $eventId)
|
||||
{
|
||||
if (isset($reference['uuid'])) {
|
||||
$existingReference = $this->find('first', array(
|
||||
|
@ -278,6 +284,9 @@ class ObjectReference extends AppModel
|
|||
$reference['object_uuid'] = $sourceObject['Object']['uuid'];
|
||||
$reference['event_id'] = $eventId;
|
||||
$result = $this->save(array('ObjectReference' => $reference));
|
||||
if (!$result) {
|
||||
return $this->validationErrors;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue