From 3ec0cbf9819fb8813391881edd420c84eb04a8ae Mon Sep 17 00:00:00 2001
From: Guillaume Heurtier <guillaume.heurtier@maarch.org>
Date: Fri, 7 Feb 2020 14:48:00 +0100
Subject: [PATCH] FEAT #12072 TIME 0:10 fix get shippings if no attachments

---
 .../shipping/controllers/ShippingController.php    | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/app/shipping/controllers/ShippingController.php b/src/app/shipping/controllers/ShippingController.php
index d96e4233ee2..1a9b3040209 100644
--- a/src/app/shipping/controllers/ShippingController.php
+++ b/src/app/shipping/controllers/ShippingController.php
@@ -36,13 +36,21 @@ class ShippingController
             'where'  => ['res_id_master = ?'],
             'data'   => [$args['resId']]
         ]);
-
         $attachments = array_column($attachments, 'res_id');
 
+        $where = '(document_id = ? and document_type = ?)';
+        $data  = [$args['resId'], 'resource'];
+
+        if (!empty($attachments)) {
+            $where .= ' or (document_id in (?) and document_type = ?)';
+            $data[] = $attachments;
+            $data[] = 'attachment';
+        }
+
         $shippingsModel = ShippingModel::get([
             'select' => ['*'],
-            'where'  => ['(document_id = ? and document_type = ?) or (document_id in (?) and document_type = ?)'],
-            'data'   => [$args['resId'], 'resource', $attachments, 'attachment']
+            'where'  => [$where],
+            'data'   => $data
         ]);
 
         $shippings = [];
-- 
GitLab