From b0301d484dd338dde0eae1902e648e2e74eab740 Mon Sep 17 00:00:00 2001
From: Guillaume Heurtier <guillaume.heurtier@maarch.org>
Date: Mon, 21 Dec 2020 17:30:43 +0100
Subject: [PATCH] FIX #9925 TIME 0:35 fix TU

---
 .../controllers/SignatureBookController.php   | 28 +++++++++----------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/src/app/signatureBook/controllers/SignatureBookController.php b/src/app/signatureBook/controllers/SignatureBookController.php
index 5cddee93fab..9d8f92dbd05 100755
--- a/src/app/signatureBook/controllers/SignatureBookController.php
+++ b/src/app/signatureBook/controllers/SignatureBookController.php
@@ -414,6 +414,20 @@ class SignatureBookController
             return $response->withStatus(404)->withJson(['errors' => 'Signature not found on docserver']);
         }
 
+        $convertedDocument = AdrModel::getDocuments([
+            'select'  => ['docserver_id', 'path', 'filename', 'type', 'fingerprint'],
+            'where'   => ['res_id = ?', 'type in (?)'],
+            'data'    => [$args['resId'], ['PDF', 'SIGN']],
+            'orderBy' => ["type='SIGN' DESC", 'version DESC'],
+            'limit'   => 1
+        ]);
+
+        if (empty($convertedDocument[0])) {
+            return $response->withStatus(400)->withJson(['errors' => 'Converted document does not exist']);
+        } elseif ($convertedDocument[0]['type'] == 'SIGN') {
+            return $response->withStatus(400)->withJson(['errors' => 'Document has already been signed']);
+        }
+
         $document = ResModel::getById(['select' => ['format'], 'resId' => $args['resId']]);
         if (in_array($document['format'], MergeController::OFFICE_EXTENSIONS)) {
             $result = MergeController::mergeAction(['resId' => $args['resId'], 'type' => 'resource']);
@@ -426,20 +440,6 @@ class SignatureBookController
                 'data'   => [$args['resId'], 'TMP'],
                 'limit'  => 1
             ]);
-        } else {
-            $convertedDocument = AdrModel::getDocuments([
-                'select'  => ['docserver_id', 'path', 'filename', 'type', 'fingerprint'],
-                'where'   => ['res_id = ?', 'type in (?)'],
-                'data'    => [$args['resId'], ['PDF', 'SIGN']],
-                'orderBy' => ["type='SIGN' DESC", 'version DESC'],
-                'limit'   => 1
-            ]);
-        }
-
-        if (empty($convertedDocument[0])) {
-            return $response->withStatus(400)->withJson(['errors' => 'Converted document does not exist']);
-        } elseif ($convertedDocument[0]['type'] == 'SIGN') {
-            return $response->withStatus(400)->withJson(['errors' => 'Document has already been signed']);
         }
 
         $convertedDocument = $convertedDocument[0];
-- 
GitLab