From b3cc299878ac6dd83b54f49dbec1c6eb3d97fcb6 Mon Sep 17 00:00:00 2001
From: Damien <damien.burel@maarch.org>
Date: Mon, 2 Jul 2018 14:50:11 +0200
Subject: [PATCH] FEAT #7983 Fix del and obs attachment

---
 src/app/attachment/models/AttachmentModelAbstract.php | 8 ++++----
 src/app/resource/controllers/ResController.php        | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/app/attachment/models/AttachmentModelAbstract.php b/src/app/attachment/models/AttachmentModelAbstract.php
index 8cb120a9cca..ad0a351708a 100644
--- a/src/app/attachment/models/AttachmentModelAbstract.php
+++ b/src/app/attachment/models/AttachmentModelAbstract.php
@@ -89,8 +89,8 @@ abstract class AttachmentModelAbstract
         ValidatorModel::arrayType($aArgs, ['select']);
 
         $originalAttachment = AttachmentModel::getById([
-            'select' => ['path', 'filename'],
-            'id' => $aArgs['id'],
+            'select'    => ['path', 'filename'],
+            'id'        => $aArgs['id'],
             'isVersion' => (empty($aArgs['isVersion']) ? 'false' : 'true')
         ]);
 
@@ -99,8 +99,8 @@ abstract class AttachmentModelAbstract
         $attachment = DatabaseModel::select([
             'select'    => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
             'table'     => ['res_attachments'],
-            'where'     => ['path = ?', 'filename = ?', 'attachment_type = ?'],
-            'data'      => [$originalAttachment['path'], $PdfFilename, 'converted_pdf'],
+            'where'     => ['path = ?', 'filename = ?', 'attachment_type = ?', 'status != ?'],
+            'data'      => [$originalAttachment['path'], $PdfFilename, 'converted_pdf', 'DEL'],
         ]);
 
         if (empty($attachment[0])) {
diff --git a/src/app/resource/controllers/ResController.php b/src/app/resource/controllers/ResController.php
index 98cc9a01f13..be33b7c0f9a 100755
--- a/src/app/resource/controllers/ResController.php
+++ b/src/app/resource/controllers/ResController.php
@@ -176,8 +176,8 @@ class ResController
         if ($extDocument['category_id'] == 'outgoing') {
             $attachment = AttachmentModel::getOnView([
                 'select'    => ['res_id', 'res_id_version', 'docserver_id', 'path', 'filename'],
-                'where'     => ['res_id_master = ?', 'attachment_type = ?'],
-                'data'      => [$aArgs['resId'], 'outgoing_mail'],
+                'where'     => ['res_id_master = ?', 'attachment_type = ?', 'status not in (?)'],
+                'data'      => [$aArgs['resId'], 'outgoing_mail', ['DEL', 'OBS']],
                 'limit'     => 1
             ]);
             if (!empty($attachment[0])) {
-- 
GitLab