From 324039f9b79cbd0d40fb835ba7055fb3f5a15b00 Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Mon, 8 Jan 2024 19:09:18 +0100 Subject: [PATCH] fix: [internal] Attachment scanning --- app/Model/Attribute.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/app/Model/Attribute.php b/app/Model/Attribute.php index 570d8f005..6ea5a12bd 100644 --- a/app/Model/Attribute.php +++ b/app/Model/Attribute.php @@ -545,6 +545,28 @@ class Attribute extends AppModel return $result; } + /** + * This method is called after all data are successfully saved into database + * @return void + * @throws Exception + */ + private function afterDatabaseSave(array $data) + { + $attribute = $data['Attribute']; + if (isset($attribute['type']) && $this->typeIsAttachment($attribute['type'])) { + $this->loadAttachmentScan()->backgroundScan(AttachmentScan::TYPE_ATTRIBUTE, $attribute); + } + } + + public function save($data = null, $validate = true, $fieldList = array()) + { + $result = parent::save($data, $validate, $fieldList); + if ($result) { + $this->afterDatabaseSave($result); + } + return $result; + } + public function beforeDelete($cascade = true) { // delete attachments from the disk @@ -881,7 +903,6 @@ class Attribute extends AppModel } $result = $this->loadAttachmentTool()->save($attribute['event_id'], $attribute['id'], $attribute['data']); if ($result) { - $this->loadAttachmentScan()->backgroundScan(AttachmentScan::TYPE_ATTRIBUTE, $attribute); // Clean thumbnail cache if ($this->isImage($attribute) && Configure::read('MISP.thumbnail_in_redis')) { $redis = RedisTool::init();