mirror of https://github.com/MISP/MISP
fix: [analyst-data:recursive-fetch] Second tentative to prevent recursion in relationship
parent
9e97ae868c
commit
31ed2113fb
|
@ -51,6 +51,8 @@ class AnalystData extends AppModel
|
|||
public $Orgc;
|
||||
/** @var object|null */
|
||||
public $SharingGroup;
|
||||
/** @var array */
|
||||
protected $fetchedUUIDFromRecursion = [];
|
||||
|
||||
public $current_user = null;
|
||||
|
||||
|
@ -257,9 +259,10 @@ class AnalystData extends AppModel
|
|||
|
||||
public function fetchChildNotesAndOpinions(array $user, array $analystData, $depth = 2): array
|
||||
{
|
||||
if ($depth == 0) {
|
||||
if ($depth == 0 || !empty($this->fetchedUUIDFromRecursion[$analystData['uuid']])) {
|
||||
return $analystData;
|
||||
}
|
||||
$this->fetchedUUIDFromRecursion[$analystData['uuid']] = true;
|
||||
|
||||
$this->Note = ClassRegistry::init('Note');
|
||||
$this->Opinion = ClassRegistry::init('Opinion');
|
||||
|
@ -298,9 +301,15 @@ class AnalystData extends AppModel
|
|||
}, $this->Opinion->find('all', $paramsOpinion));
|
||||
|
||||
if (!empty($childNotes)) {
|
||||
foreach ($childNotes as $childNote) {
|
||||
$this->fetchedUUIDFromRecursion[$childNote['uuid']] = true;
|
||||
}
|
||||
$analystData['Note'] = $childNotes;
|
||||
}
|
||||
if (!empty($childOpinions)) {
|
||||
foreach ($childNotes as $childNote) {
|
||||
$this->fetchedUUIDFromRecursion[$childNote['uuid']] = true;
|
||||
}
|
||||
$analystData['Opinion'] = $childOpinions;
|
||||
}
|
||||
return $analystData;
|
||||
|
|
|
@ -27,9 +27,7 @@ class AnalystDataParentBehavior extends ModelBehavior
|
|||
$data = [];
|
||||
foreach ($types as $type) {
|
||||
$this->{$type} = ClassRegistry::init($type);
|
||||
if ($model->includeAnalystDataRecursive) {
|
||||
$this->{$type}->fetchRecursive = true;
|
||||
}
|
||||
$this->{$type}->fetchRecursive = !empty($model->includeAnalystDataRecursive);
|
||||
$temp = $this->{$type}->fetchForUuid($object['uuid'], $this->__currentUser);
|
||||
if (!empty($temp)) {
|
||||
foreach ($temp as $k => $temp_element) {
|
||||
|
|
|
@ -2235,10 +2235,6 @@ class Event extends AppModel
|
|||
unset($attribute['EventTag']);
|
||||
}
|
||||
}
|
||||
$allAnalystData = $this->Attribute->attachAnalystData($attribute); // afterFind from AnalystDataParentBehavior is not called. Probably because we're in an association
|
||||
foreach ($allAnalystData as $type => $analystData) {
|
||||
$attribute[$type] = $analystData;
|
||||
}
|
||||
// If a shadowattribute can be linked to an attribute, link it to it
|
||||
// This is to differentiate between proposals that were made to an attribute for modification and between proposals for new attributes
|
||||
$attribute['ShadowAttribute'] = $shadowAttributeByOldId[$attribute['id']] ?? [];
|
||||
|
|
|
@ -59,7 +59,10 @@ class Relationship extends AnalystData
|
|||
$this->Event = ClassRegistry::init('Event');
|
||||
$params = [
|
||||
];
|
||||
$backup = $this->Event->includeAnalystData;
|
||||
$this->Event->includeAnalystData = false;
|
||||
$data = $this->Event->fetchSimpleEvent($user, $uuid, $params);
|
||||
$this->Event->includeAnalystData = $backup;
|
||||
} else if ($type == 'Attribute') {
|
||||
$this->Attribute = ClassRegistry::init('Attribute');
|
||||
$params = [
|
||||
|
@ -68,7 +71,10 @@ class Relationship extends AnalystData
|
|||
],
|
||||
'contain' => ['Event' => 'Orgc', 'Object',]
|
||||
];
|
||||
$backup = $this->Attribute->includeAnalystData;
|
||||
$this->Attribute->includeAnalystData = false;
|
||||
$data = $this->Attribute->fetchAttributeSimple($user, $params);
|
||||
$this->Attribute->includeAnalystData = $backup;
|
||||
$data = $this->rearrangeData($data, 'Attribute');
|
||||
} else if ($type == 'Object') {
|
||||
$this->Object = ClassRegistry::init('MispObject');
|
||||
|
@ -78,7 +84,10 @@ class Relationship extends AnalystData
|
|||
],
|
||||
'contain' => ['Event' => 'Orgc',]
|
||||
];
|
||||
$backup = $this->Object->includeAnalystData;
|
||||
$this->Object->includeAnalystData = false;
|
||||
$data = $this->Object->fetchObjectSimple($user, $params);
|
||||
$this->Object->includeAnalystData = $backup;
|
||||
if (!empty($data)) {
|
||||
$data = $data[0];
|
||||
}
|
||||
|
@ -88,19 +97,28 @@ class Relationship extends AnalystData
|
|||
$params = [
|
||||
|
||||
];
|
||||
$backup = $this->Note->includeAnalystData;
|
||||
$this->Note->includeAnalystData = false;
|
||||
$data = $this->Note->fetchNote();
|
||||
$this->Note->includeAnalystData = $backup;
|
||||
} else if ($type == 'Opinion') {
|
||||
$this->Opinion = ClassRegistry::init('Opinion');
|
||||
$params = [
|
||||
|
||||
];
|
||||
$backup = $this->Opinion->includeAnalystData;
|
||||
$this->Opinion->includeAnalystData = false;
|
||||
$data = $this->Opinion->fetchOpinion();
|
||||
$this->Opinion->includeAnalystData = $backup;
|
||||
} else if ($type == 'Relationship') {
|
||||
$this->Relationship = ClassRegistry::init('Relationship');
|
||||
$params = [
|
||||
|
||||
];
|
||||
$backup = $this->Relationship->includeAnalystData;
|
||||
$this->Relationship->includeAnalystData = false;
|
||||
$data = $this->Relationship->fetchRelationship();
|
||||
$this->Relationship->includeAnalystData = $backup;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue