fix: [object] object deduplication fixed

pull/5615/head
iglocska 2020-02-10 14:39:58 +01:00
parent 8803f47a9e
commit 55385e6ca6
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
1 changed files with 15 additions and 10 deletions

View File

@ -208,7 +208,10 @@ class MispObject extends AppModel
$newObjectAttributes = array();
$existingObjectAttributes = array();
foreach ($object['Attribute'] as $attribute) {
$newObjectAttributes[] = hash('sha256', $attribute['object_relation'] . $attribute['category'] . $attribute['type'] . $attribute['value']);
$newObjectAttributes[] = hash(
'sha256',
$attribute['object_relation'] . $attribute['category'] . $attribute['type'] . $attribute['value']
);
}
$newObjectAttributeCount = count($newObjectAttributes);
$existingObjects = $this->find('all', array(
@ -224,17 +227,17 @@ class MispObject extends AppModel
));
$oldObjects = array();
foreach ($existingObjects as $k => $existingObject) {
$temp = array();
if (!empty($existingObject['Attribute']) && $newObjectAttributeCount == count($existingObject['Attribute'])) {
foreach ($existingObject['Attribute'] as $existingAttribute) {
$oldObjects[$k][] = hash('sha256',
$attribute['object_relation'] . $existingAttribute['category'] . $existingAttribute['type'] . $existingAttribute['value']
);
$temp[] = hash(
'sha256',
$attribute['object_relation'] . $existingAttribute['category'] . $existingAttribute['type'] . $existingAttribute['value']
);
}
if (empty(array_diff($temp, $newObjectAttributes))) {
return true;
}
}
}
foreach ($oldObjects as $k => $object) {
if (empty(array_diff($object, $newObjectAttributes))) {
return true;
}
}
return false;
@ -244,7 +247,9 @@ class MispObject extends AppModel
{
if ($breakOnDuplicate) {
$duplicate = $this->checkForDuplicateObjects($object, $eventId);
return array('value' => array('Duplicate object found. Since breakOnDuplicate is set the object will not be added.'));
if ($duplicate) {
return array('value' => array('Duplicate object found. Since breakOnDuplicate is set the object will not be added.'));
}
}
$this->create();
$templateFields = array(