fix: [API] tag capture fixed on newly created objects via the API, fixes MISP/PyMISP#236

pull/3368/head
iglocska 2018-06-22 06:19:09 +02:00
parent d860566017
commit 35cd81251d
1 changed files with 12 additions and 1 deletions

View File

@ -3153,12 +3153,23 @@ class Attribute extends AppModel {
'change' => 'Validation errors: ' . json_encode($this->validationErrors) . ' Full Attribute: ' . json_encode($attribute),
));
} else {
$tags = array();
if (isset($attribute['Tag'])) {
$tags = $attribute['Tag'];
}
if (isset($attribute['AttributeTag'])) {
foreach ($attribute['AttributeTag'] as $at) {
unset($at['id']);
$tags[] = $at['Tag'];
}
}
foreach ($tags as $tag) {
$tag_id = $this->AttributeTag->Tag->captureTag($tag, $user);
if ($tag_id) {
$this->AttributeTag->create();
$at = array();
$at['attribute_id'] = $this->id;
$at['event_id'] = $eventId;
$at['tag_id'] = $tag_id;
$this->AttributeTag->save($at);
}
}