diff --git a/include/class.attachment.php b/include/class.attachment.php index bb5e8e292f11aa0342f82299f7d2b5c1bec04dd8..f8d2c38fee12268db1728fdf4fbd38ad75ed28ad 100644 --- a/include/class.attachment.php +++ b/include/class.attachment.php @@ -148,7 +148,15 @@ extends InstrumentedList { $_inline = isset($file['inline']) ? $file['inline'] : $inline; - $att = $this->add(new Attachment(array( + // Check if Attachment exists + if ($F && $this->key) + $existing = Attachment::objects()->filter(array( + 'file__key' => $F->key, + 'object_id' => $this->key['object_id'], + 'type' => $this->key['type'] + ))->first(); + + $att = $this->add(isset($existing) ? $existing : new Attachment(array( 'file_id' => $fileId, 'inline' => $_inline ? 1 : 0, )));