mirror of https://github.com/MISP/MISP
chg: [internal] Cleanup code responsible for adding events
parent
b4661c4d3e
commit
673f48c10d
|
@ -3640,7 +3640,6 @@ class Attribute extends AppModel
|
|||
$attribute['data'] = $result['data'];
|
||||
$attribute['value'] = $attribute['value'] . '|' . $result['md5'];
|
||||
}
|
||||
$fieldList = $this->captureFields;
|
||||
$this->create();
|
||||
if (!isset($attribute['distribution'])) {
|
||||
$attribute['distribution'] = Configure::read('MISP.default_attribute_distribution');
|
||||
|
@ -3649,7 +3648,7 @@ class Attribute extends AppModel
|
|||
}
|
||||
}
|
||||
$params = array(
|
||||
'fieldList' => $fieldList
|
||||
'fieldList' => $this->captureFields
|
||||
);
|
||||
if (!empty($parentEvent)) {
|
||||
$params['parentEvent'] = $parentEvent;
|
||||
|
@ -3675,7 +3674,6 @@ class Attribute extends AppModel
|
|||
'change' => 'Validation errors: ' . json_encode($this->validationErrors) . ' Full Attribute: ' . json_encode($attribute),
|
||||
));
|
||||
} else {
|
||||
$tags = array();
|
||||
if (isset($attribute['AttributeTag'])) {
|
||||
foreach ($attribute['AttributeTag'] as $at) {
|
||||
unset($at['id']);
|
||||
|
|
|
@ -3747,7 +3747,11 @@ class Event extends AppModel
|
|||
}
|
||||
if (isset($data['Event']['uuid'])) {
|
||||
// check if the uuid already exists
|
||||
$existingEvent = $this->find('first', array('conditions' => array('Event.uuid' => $data['Event']['uuid'])));
|
||||
$existingEvent = $this->find('first', [
|
||||
'conditions' => ['Event.uuid' => $data['Event']['uuid']],
|
||||
'fields' => ['Event.id'],
|
||||
'recursive' => -1.
|
||||
]);
|
||||
if ($existingEvent) {
|
||||
// RESTful, set response location header so client can find right URL to edit
|
||||
if ($fromPull) {
|
||||
|
@ -3789,42 +3793,23 @@ class Event extends AppModel
|
|||
return json_encode($validationErrors);
|
||||
}
|
||||
$fieldList = array(
|
||||
'Event' => array(
|
||||
'org_id',
|
||||
'orgc_id',
|
||||
'date',
|
||||
'threat_level_id',
|
||||
'analysis',
|
||||
'info',
|
||||
'user_id',
|
||||
'published',
|
||||
'uuid',
|
||||
'timestamp',
|
||||
'distribution',
|
||||
'sharing_group_id',
|
||||
'locked',
|
||||
'disable_correlation',
|
||||
'extends_uuid'
|
||||
),
|
||||
'Attribute' => $this->Attribute->captureFields,
|
||||
'Object' => array(
|
||||
'name',
|
||||
'meta-category',
|
||||
'description',
|
||||
'template_uuid',
|
||||
'template_version',
|
||||
'event_id',
|
||||
'uuid',
|
||||
'timestamp',
|
||||
'distribution',
|
||||
'sharing_group_id',
|
||||
'comment',
|
||||
'deleted'
|
||||
),
|
||||
'ObjectRelation' => array(),
|
||||
'EventReport' => $this->EventReport->captureFields,
|
||||
'org_id',
|
||||
'orgc_id',
|
||||
'date',
|
||||
'threat_level_id',
|
||||
'analysis',
|
||||
'info',
|
||||
'user_id',
|
||||
'published',
|
||||
'uuid',
|
||||
'timestamp',
|
||||
'distribution',
|
||||
'sharing_group_id',
|
||||
'locked',
|
||||
'disable_correlation',
|
||||
'extends_uuid'
|
||||
);
|
||||
$saveResult = $this->save(array('Event' => $data['Event']), array('fieldList' => $fieldList['Event']));
|
||||
$saveResult = $this->save(array('Event' => $data['Event']), array('fieldList' => $fieldList));
|
||||
if ($saveResult) {
|
||||
if ($jobId) {
|
||||
/** @var EventLock $eventLock */
|
||||
|
@ -3886,8 +3871,7 @@ class Event extends AppModel
|
|||
}
|
||||
$referencesToCapture = array();
|
||||
if (!empty($data['Event']['Object'])) {
|
||||
$objectDuplicateCache = [];
|
||||
foreach ($data['Event']['Object'] as $k => $object) {
|
||||
foreach ($data['Event']['Object'] as $object) {
|
||||
$result = $this->Object->captureObject($object, $this->id, $user, $this->Log, false, $breakOnDuplicate);
|
||||
}
|
||||
foreach ($data['Event']['Object'] as $object) {
|
||||
|
@ -3903,8 +3887,7 @@ class Event extends AppModel
|
|||
$result = $this->Object->ObjectReference->captureReference(
|
||||
$referenceToCapture,
|
||||
$this->id,
|
||||
$user,
|
||||
$this->Log
|
||||
$user
|
||||
);
|
||||
}
|
||||
if (!empty($data['Event']['EventReport'])) {
|
||||
|
|
|
@ -176,11 +176,8 @@ class ObjectReference extends AppModel
|
|||
return true;
|
||||
}
|
||||
|
||||
public function captureReference($reference, $eventId, $user, $log = false)
|
||||
public function captureReference($reference, $eventId, $user)
|
||||
{
|
||||
if ($log == false) {
|
||||
$log = ClassRegistry::init('Log');
|
||||
}
|
||||
if (isset($reference['uuid'])) {
|
||||
$existingReference = $this->find('first', array(
|
||||
'conditions' => array('ObjectReference.uuid' => $reference['uuid']),
|
||||
|
@ -216,7 +213,8 @@ class ObjectReference extends AppModel
|
|||
}
|
||||
$sourceObject = $this->Object->find('first', array(
|
||||
'recursive' => -1,
|
||||
'conditions' => $conditions
|
||||
'conditions' => $conditions,
|
||||
'fields' => ['Object.id', 'Object.uuid', 'Object.event_id'],
|
||||
));
|
||||
if (isset($reference['referenced_uuid'])) {
|
||||
$conditions[0] = array('Attribute.uuid' => $reference['referenced_uuid']);
|
||||
|
|
Loading…
Reference in New Issue