From 4bc4192f3fd7e3b5c5f53c828fc5cc800fbd3384 Mon Sep 17 00:00:00 2001
From: Quentin RIBAC <quentin.ribac@xelians.fr>
Date: Thu, 15 Sep 2022 10:42:59 +0200
Subject: [PATCH] FEAT #17671 TIME 0:15 change error message; remove double
 foreach

---
 .../controllers/DocumentController.php        | 24 ++++++++-----------
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/src/app/document/controllers/DocumentController.php b/src/app/document/controllers/DocumentController.php
index dff5497ac7..61d48e6cc6 100755
--- a/src/app/document/controllers/DocumentController.php
+++ b/src/app/document/controllers/DocumentController.php
@@ -316,7 +316,7 @@ class DocumentController
                 'data'  => [$args['id']]
             ]);
             if (empty($filePaths)) {
-                return $response->withStatus(500)->withJson(['errors' => 'No documents found on Docserver']);
+                return $response->withStatus(500)->withJson(['errors' => 'Document does not exist']);
             }
 
             $attachments = AttachmentModel::get([
@@ -333,20 +333,16 @@ class DocumentController
                 $filePaths = array_merge($filePaths, $attachmentFilePaths);
             }
 
-            foreach ($docServers as $docserver) {
-                foreach ($filePaths as $filePath) {
+            $docServers = array_column($docServers, 'path', 'type');
+            foreach ($filePaths as $filePath) {
+                $docFilePath = $docServers[$filePath['type']] . $filePath['path'];
 
-                    if ($docserver['type'] == $filePath['type']) {
-                        $docFilePath = "{$docserver['path']}{$filePath['path']}";
-
-                        if (file_exists("$docFilePath")) {
-                            AdrModel::deleteDocumentAdr([
-                                'where' => ['id = ?'],
-                                'data'  => [$filePath['id']]
-                            ]);
-                            unlink($docFilePath);
-                        }
-                    }
+                if (file_exists("$docFilePath")) {
+                    AdrModel::deleteDocumentAdr([
+                        'where' => ['id = ?'],
+                        'data'  => [$filePath['id']]
+                    ]);
+                    unlink($docFilePath);
                 }
             }
 
-- 
GitLab