From e20929ef21899e49dcd54d8ebc014be759c48242 Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Wed, 19 Sep 2018 12:47:20 +0200
Subject: [PATCH] FEAT #8346 refactoring class convert pdf

---
 modules/attachments/xml/config.xml            |  4 +-
 .../class/class_modules_tools_Abstract.php    | 11 +--
 modules/visa/printFolder_ajax.php             |  6 +-
 modules/visa/sign_file.php                    |  5 +-
 .../controllers/AttachmentController.php      | 32 +++------
 .../models/AttachmentModelAbstract.php        | 27 --------
 .../controllers/ConvertPdfController.php      | 27 +++++++-
 .../ConvertThumbnailController.php            | 24 ++++++-
 src/app/convert/models/AdrModel.php           | 29 ++++++++
 .../resource/controllers/ResController.php    | 52 ++++----------
 .../resource/controllers/StoreController.php  | 10 ---
 src/app/resource/models/ResModelAbstract.php  | 20 ------
 .../controllers/SignatureBookController.php   |  7 +-
 vendor/composer/ClassLoader.php               | 12 ++--
 vendor/composer/LICENSE                       | 69 ++++++++++++++-----
 15 files changed, 176 insertions(+), 159 deletions(-)

diff --git a/modules/attachments/xml/config.xml b/modules/attachments/xml/config.xml
index 68a6e711d1d..f112103ab92 100755
--- a/modules/attachments/xml/config.xml
+++ b/modules/attachments/xml/config.xml
@@ -4,13 +4,13 @@
 		<name>attachments</name>
 		<comment>_ATTACHMENTS_COMMENT</comment>
 		<file_prefix>attach</file_prefix>
-		<convertPdf>true</convertPdf> <!-- true = applet DIS, false = applet Maarch -->
+		<convertPdf>false</convertPdf> <!-- true = convert with applet, false = convert server-side -->
 		<vbs_convert_path></vbs_convert_path> <!-- Path to VBS file if necessary. ex: C:\Program Files (x86)\Outils SPM\DOC2PDF_VBS.vbs . Default : %HOME_DIR%\maarchTmp\DOC2PDF_VBS.vbs -->
 		<useExeConvert>false</useExeConvert>
 		<loaded>true</loaded>
 		<watermark>
 			<enabled>false</enabled> <!-- If true, a watermark is applied on the document /!\ WARNING /!\ BUG WITH SIGNATUREBOOK IF TRUE -->
-			<text>Copie conforme de [identifier] au statut [status] le [date_now] [hour_now]</text> <!-- text with fusion fields [column_name] or [date_now], ex : [alt_identifier] with status [status] the [date_now] [hour_now]-->
+			<text>Copie conforme de [identifier] au statut [status] le [date_now] [hour_now]</text> <!-- text with fusion fields [column_name] or [date_now], ex : [identifier] with status [status] the [date_now] [hour_now]-->
 			<position>30,35,0,0.5</position> <!-- Setup position with X, Y, angle, opacity ; ex : 50,450,30,0.5 -->
 			<font>helvetica,10</font> <!-- Setup the font name and her size, ex: helvetica,10 -->
 			<text_color>20,192,30</text_color> <!-- Setup the color of the text, ex: 192,192,192 -->
diff --git a/modules/visa/class/class_modules_tools_Abstract.php b/modules/visa/class/class_modules_tools_Abstract.php
index bffab679785..c27a8ab461b 100755
--- a/modules/visa/class/class_modules_tools_Abstract.php
+++ b/modules/visa/class/class_modules_tools_Abstract.php
@@ -1062,11 +1062,12 @@ abstract class visa_Abstract extends Database
                     $idFile = $res->res_id_version;
                     $isVersion = true;
                 }
-                $convertedDocument =  \Attachment\models\AttachmentModel::getConvertedPdfById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => $idFile, 'isVersion' => $isVersion]);
+                $convertedDocument =  \Convert\controllers\ConvertPdfController::getConvertedPdfById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => $idFile, 'collId' => 'attachments_coll', 'isVersion' => $isVersion]);
                 $viewLink = $_SESSION['config']['businessappurl']
                         .'index.php?display=true&module=attachments&page=view_attachment&res_id_master='
                         .$id.'&id='.$res->res_id;
-                if (!empty($convertedDocument)) {
+                
+                if (empty($convertedDocument['errors'])) {
                     $docserver = \Docserver\models\DocserverModel::getByDocserverId(['docserverId' => $convertedDocument['docserver_id'], 'select' => ['path_template']]);
                     $pathToDocument = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $convertedDocument['path']) . $convertedDocument['filename'];
                     
@@ -1079,11 +1080,11 @@ abstract class visa_Abstract extends Database
                 }
             } else {
                 $idFile = $res->res_id;
-                $convertedDocument =  \Resource\models\ResModel::getConvertedPdfById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => $idFile]);
+                $convertedDocument =  \Convert\controllers\ConvertPdfController::getConvertedPdfById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => $idFile, 'collId' => 'letterbox_coll', 'isVersion' => $isVersion]);
                 $viewLink = $_SESSION['config']['businessappurl']
                         .'index.php?display=true&dir=indexing_searching&page=view_resource_controler&id='
                         .$id;
-                if (!empty($convertedDocument)) {
+                if (empty($convertedDocument['errors'])) {
                     $docserver = \Docserver\models\DocserverModel::getByDocserverId(['docserverId' => $convertedDocument['docserver_id'], 'select' => ['path_template']]);
                     $pathToDocument = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $convertedDocument['path']) . $convertedDocument['filename'];
                     
@@ -1116,7 +1117,7 @@ abstract class visa_Abstract extends Database
                 $typist = '';
             }
 
-            if (($from_res_attachment && $pdf_exist) || !empty($convertedDocument)
+            if (($from_res_attachment && $pdf_exist) || empty($convertedDocument['errors'])
             ) {
                 //nothing
             } else {
diff --git a/modules/visa/printFolder_ajax.php b/modules/visa/printFolder_ajax.php
index 4048be9a584..a94d6a340fe 100755
--- a/modules/visa/printFolder_ajax.php
+++ b/modules/visa/printFolder_ajax.php
@@ -273,7 +273,7 @@ if (isset($_REQUEST['notes']) && count($_REQUEST['notes']) > 0) {
 //$date = $request->current_datetime();
 $list_path_folder =  array();
 if ($res_master_attached == 'Y') {
-    $convertedDocument =  \Resource\models\ResModel::getConvertedPdfById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => (int)$_REQUEST['join_file'][0]]);
+    $convertedDocument =  \Convert\controllers\ConvertPdfController::getConvertedPdfById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => (int)$_REQUEST['join_file'][0], 'collId' => 'attachments_coll', 'isVersion' => false]);
     $docserver = \Docserver\models\DocserverModel::getByDocserverId(['docserverId' => $convertedDocument['docserver_id'], 'select' => ['path_template']]);
     $pathToDocument = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $convertedDocument['path']) . $convertedDocument['filename'];
     
@@ -281,7 +281,7 @@ if ($res_master_attached == 'Y') {
 }
 if (isset($_REQUEST['join_attachment']) && count($_REQUEST['join_attachment']) > 0) {
     foreach ($_REQUEST['join_attachment'] as $id_attach) {
-        $convertedDocument =  \Attachment\models\AttachmentModel::getConvertedPdfById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => $id_attach, 'isVersion' => false]);
+        $convertedDocument =  \Convert\controllers\ConvertPdfController::getConvertedPdfById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => $id_attach, 'collId' => 'attachments_coll', 'isVersion' => false]);
         $docserver = \Docserver\models\DocserverModel::getByDocserverId(['docserverId' => $convertedDocument['docserver_id'], 'select' => ['path_template']]);
         $pathToDocument = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $convertedDocument['path']) . $convertedDocument['filename'];
                 
@@ -290,7 +290,7 @@ if (isset($_REQUEST['join_attachment']) && count($_REQUEST['join_attachment']) >
 }
 if (isset($_REQUEST['join_version']) && count($_REQUEST['join_version']) > 0) {
     foreach ($_REQUEST['join_version'] as $id_attach) {
-        $convertedDocument =  \Attachment\models\AttachmentModel::getConvertedPdfById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => $id_attach, 'isVersion' => true]);
+        $convertedDocument =  \Convert\controllers\ConvertPdfController::getConvertedPdfById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => $id_attach, 'collId' => 'attachments_coll', 'isVersion' => true]);
         $docserver = \Docserver\models\DocserverModel::getByDocserverId(['docserverId' => $convertedDocument['docserver_id'], 'select' => ['path_template']]);
         $pathToDocument = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $convertedDocument['path']) . $convertedDocument['filename'];
                 
diff --git a/modules/visa/sign_file.php b/modules/visa/sign_file.php
index 7644b7472a9..a237567294f 100755
--- a/modules/visa/sign_file.php
+++ b/modules/visa/sign_file.php
@@ -104,9 +104,8 @@ if (!empty($_REQUEST['id']) && !empty($_REQUEST['collId'])) {
             $isVersion = false;
             $attachResId = $line->res_id;
         }
-        $convertedAttachment = \Attachment\models\AttachmentModel::getConvertedPdfById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => $attachResId, 'isVersion' => $isVersion]);
-
-        if (empty($convertedAttachment)) {
+        $convertedAttachment =  \Convert\controllers\ConvertPdfController::getConvertedPdfById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => $attachResId, 'collId' => 'attachments_coll', 'isVersion' => $isVersion]);
+        if (!empty($convertedAttachment['errors'])) {
             echo "{\"status\":1, \"error\" : \""._ATTACH_PDF_NOT_FOUND . ": {$attachResId}, version : {$isVersion}\"}";
             exit;
         }
diff --git a/src/app/attachment/controllers/AttachmentController.php b/src/app/attachment/controllers/AttachmentController.php
index e0603da2f6f..587199606a9 100644
--- a/src/app/attachment/controllers/AttachmentController.php
+++ b/src/app/attachment/controllers/AttachmentController.php
@@ -15,17 +15,17 @@
 namespace Attachment\controllers;
 
 use Attachment\models\AttachmentModel;
+use Convert\controllers\ConvertPdfController;
+use Convert\controllers\ConvertThumbnailController;
+use Convert\models\AdrModel;
+use Docserver\models\DocserverModel;
+use History\controllers\HistoryController;
+use Resource\controllers\ResController;
+use Respect\Validation\Validator;
+use setasign\Fpdi\TcpdfFpdi;
 use Slim\Http\Request;
 use Slim\Http\Response;
-use Respect\Validation\Validator;
-use Resource\controllers\ResController;
-use Docserver\models\DocserverModel;
 use SrcCore\models\CoreConfigModel;
-use setasign\Fpdi\TcpdfFpdi;
-use History\controllers\HistoryController;
-use Convert\controllers\ConvertPdfController;
-use Convert\models\AdrModel;
-use Convert\controllers\ConvertThumbnailController;
 
 class AttachmentController
 {
@@ -154,20 +154,8 @@ class AttachmentController
             $collId = "attachments_coll";
         }
 
-        $convertedAttachment = AttachmentModel::getConvertedPdfById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => $id, 'isVersion' => $isVersion]);
-        if (empty($convertedAttachment)) {
-            ConvertPdfController::convert([
-                'resId'     => $id,
-                'collId'    => $collId,
-                'isVersion' => $isVersion,
-            ]);
-
-            $convertedAttachment = AttachmentModel::getConvertedPdfById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => $id, 'isVersion' => $isVersion]);
-            
-            if (!empty($convertedAttachment)) {
-                $attachmentTodisplay = $convertedAttachment;
-            }
-        } else {
+        $convertedAttachment = ConvertPdfController::getConvertedPdfById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => $id, 'collId' => 'attachments_coll', 'isVersion' => $isVersion]);
+        if (empty($convertedAttachment['errors'])) {
             $attachmentTodisplay = $convertedAttachment;
         }
         $document['docserver_id'] = $attachmentTodisplay['docserver_id'];
diff --git a/src/app/attachment/models/AttachmentModelAbstract.php b/src/app/attachment/models/AttachmentModelAbstract.php
index d273f273dfc..2a914c3f92b 100644
--- a/src/app/attachment/models/AttachmentModelAbstract.php
+++ b/src/app/attachment/models/AttachmentModelAbstract.php
@@ -120,33 +120,6 @@ abstract class AttachmentModelAbstract
         return true;
     }
 
-    public static function getConvertedPdfById(array $aArgs)
-    {
-        ValidatorModel::notEmpty($aArgs, ['resId']);
-        ValidatorModel::intVal($aArgs, ['resId']);
-        ValidatorModel::boolType($aArgs, ['isVersion']);
-        ValidatorModel::arrayType($aArgs, ['select']);
-
-        if ($aArgs['isVersion']) {
-            $table = "adr_attachments_version";
-        } else {
-            $table = "adr_attachments";
-        }
-
-        $attachment = DatabaseModel::select([
-            'select'    => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
-            'table'     => [$table],
-            'where'     => ['res_id = ?', 'type = ?'],
-            'data'      => [$aArgs['resId'], 'PDF'],
-        ]);
-
-        if (empty($attachment[0])) {
-            return [];
-        }
-
-        return $attachment[0];
-    }
-
     public static function getAttachmentsTypesByXML()
     {
         $attachmentTypes = [];
diff --git a/src/app/convert/controllers/ConvertPdfController.php b/src/app/convert/controllers/ConvertPdfController.php
index 5e6bc402ece..57e9e12c834 100644
--- a/src/app/convert/controllers/ConvertPdfController.php
+++ b/src/app/convert/controllers/ConvertPdfController.php
@@ -129,6 +129,31 @@ class ConvertPdfController
                 'filename'      => $storeResult['file_destination_name'],
             ]);
         }
-        return true;
+        return ['docserver_id' => $storeResult['docserver_id'], 'path' => $storeResult['destination_dir'], 'filename' => $storeResult['file_destination_name']];
+    }
+
+    public static function getConvertedPdfById(array $aArgs)
+    {
+        ValidatorModel::notEmpty($aArgs, ['resId', 'collId']);
+        ValidatorModel::intVal($aArgs, ['resId']);
+        ValidatorModel::boolType($aArgs, ['isVersion']);
+        ValidatorModel::arrayType($aArgs, ['select']);
+
+        $convertedDocument = AdrModel::getConvertedDocumentById([
+            'select' => ['docserver_id','path', 'filename'],
+            'resId' => $aArgs['resId'],
+            'collId' => $aArgs['collId'],
+            'type' => 'PDF',
+            'isVersion' => $aArgs['isVersion']
+        ]);
+        
+        if (empty($convertedDocument)) {
+            $convertedDocument = ConvertPdfController::convert([
+                'resId'     => $aArgs['resId'],
+                'collId'    => $aArgs['collId'],
+                'isVersion' => $aArgs['isVersion'],
+            ]);
+        }
+        return $convertedDocument;
     }
 }
diff --git a/src/app/convert/controllers/ConvertThumbnailController.php b/src/app/convert/controllers/ConvertThumbnailController.php
index 93d09098d84..8b9041065c1 100644
--- a/src/app/convert/controllers/ConvertThumbnailController.php
+++ b/src/app/convert/controllers/ConvertThumbnailController.php
@@ -36,14 +36,32 @@ class ConvertThumbnailController
         if ($aArgs['collId'] == 'letterbox_coll') {
             if (empty($aArgs['outgoingId'])) {
                 $resource = ResModel::getById(['resId' => $aArgs['resId'], 'select' => ['docserver_id', 'path', 'filename']]);
-                $convertedDocument = ResModel::getConvertedPdfById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => $aArgs['resId']]);
+                $convertedDocument = AdrModel::getConvertedDocumentById([
+                    'select' => ['docserver_id','path', 'filename'],
+                    'resId' => $aArgs['resId'],
+                    'collId' => $aArgs['collId'],
+                    'type' => 'PDF',
+                    'isVersion' => false
+                ]);
             } else {
                 $resource = AttachmentModel::getById(['id' => $aArgs['outgoingId'], 'isVersion' => $aArgs['isOutgoingVersion'], 'select' => ['docserver_id', 'path', 'filename']]);
-                $convertedDocument =  AttachmentModel::getConvertedPdfById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => $aArgs['outgoingId'], 'isVersion' => $aArgs['isOutgoingVersion']]);
+                $convertedDocument = AdrModel::getConvertedDocumentById([
+                    'select' => ['docserver_id','path', 'filename'],
+                    'resId' => $aArgs['resId'],
+                    'collId' => $aArgs['collId'],
+                    'type' => 'PDF',
+                    'isVersion' => $aArgs['isOutgoingVersion']
+                ]);
             }
         } else {
             $resource = AttachmentModel::getById(['id' => $aArgs['resId'], 'isVersion' => $aArgs['isVersion'], 'select' => ['docserver_id', 'path', 'filename']]);
-            $convertedDocument =  AttachmentModel::getConvertedPdfById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => $aArgs['resId'], 'isVersion' => $aArgs['isVersion']]);
+            $convertedDocument = AdrModel::getConvertedDocumentById([
+                'select' => ['docserver_id','path', 'filename'],
+                'resId' => $aArgs['resId'],
+                'collId' => $aArgs['collId'],
+                'type' => 'PDF',
+                'isVersion' => $aArgs['isVersion']
+            ]);
         }
 
         if (empty($resource)) {
diff --git a/src/app/convert/models/AdrModel.php b/src/app/convert/models/AdrModel.php
index 274647ee723..f46e02732e4 100644
--- a/src/app/convert/models/AdrModel.php
+++ b/src/app/convert/models/AdrModel.php
@@ -19,6 +19,35 @@ use SrcCore\models\ValidatorModel;
 
 class AdrModel
 {
+    public static function getConvertedDocumentById(array $aArgs)
+    {
+        ValidatorModel::notEmpty($aArgs, ['resId', 'type', 'collId']);
+        ValidatorModel::intVal($aArgs, ['resId']);
+        ValidatorModel::boolType($aArgs, ['isVersion']);
+        ValidatorModel::arrayType($aArgs, ['select']);
+
+        if ($aArgs['collId'] == 'letterbox_coll') {
+            $table = "adr_letterbox";
+        } else if ($aArgs['isVersion']) {
+            $table = "adr_attachments_version";
+        } else {
+            $table = "adr_attachments";
+        }
+
+        $attachment = DatabaseModel::select([
+            'select'    => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
+            'table'     => [$table],
+            'where'     => ['res_id = ?', 'type = ?'],
+            'data'      => [$aArgs['resId'], $aArgs['type']],
+        ]);
+
+        if (empty($attachment[0])) {
+            return [];
+        }
+
+        return $attachment[0];
+    }
+
     public static function getDocumentsAdr(array $aArgs = [])
     {
         ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy']);
diff --git a/src/app/resource/controllers/ResController.php b/src/app/resource/controllers/ResController.php
index 9852bc50188..414bb2f5c2b 100755
--- a/src/app/resource/controllers/ResController.php
+++ b/src/app/resource/controllers/ResController.php
@@ -17,29 +17,29 @@ namespace Resource\controllers;
 use Attachment\models\AttachmentModel;
 use Basket\models\BasketModel;
 use Basket\models\GroupBasketModel;
+use Convert\controllers\ConvertPdfController;
 use Convert\controllers\ConvertThumbnailController;
 use Convert\models\AdrModel;
 use Docserver\controllers\DocserverController;
 use Docserver\models\DocserverModel;
+use Docserver\models\ResDocserverModel;
 use Entity\models\ListInstanceModel;
 use Group\controllers\GroupController;
 use Group\models\GroupModel;
-use Note\models\NoteModel;
 use Group\models\ServiceModel;
-use setasign\Fpdi\TcpdfFpdi;
-use SrcCore\models\CoreConfigModel;
-use Status\models\StatusModel;
-use SrcCore\models\ValidatorModel;
 use History\controllers\HistoryController;
+use Note\models\NoteModel;
+use Resource\models\ChronoModel;
 use Resource\models\ResModel;
 use Respect\Validation\Validator;
+use setasign\Fpdi\TcpdfFpdi;
 use Slim\Http\Request;
 use Slim\Http\Response;
 use SrcCore\controllers\PreparedClauseController;
+use SrcCore\models\CoreConfigModel;
+use SrcCore\models\ValidatorModel;
+use Status\models\StatusModel;
 use User\models\UserModel;
-use Docserver\models\ResDocserverModel;
-use Resource\models\ChronoModel;
-use Convert\controllers\ConvertPdfController;
 
 class ResController
 {
@@ -283,44 +283,18 @@ class ResController
                 } else {
                     $collId = "attachments_coll";
                 }
-                $convertedAttachment = AttachmentModel::getConvertedPdfById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => $id, 'isVersion' => $isVersion]);
-                if (empty($convertedAttachment)) {
-                    ConvertPdfController::convert([
-                        'resId'     => $id,
-                        'collId'    => $collId,
-                        'isVersion' => $isVersion,
-                    ]);
-        
-                    $convertedAttachment = AttachmentModel::getConvertedPdfById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => $id, 'isVersion' => $isVersion]);
-                    
-                    if (!empty($convertedAttachment)) {
-                        $attachmentTodisplay = $convertedAttachment;
-                    }
-                } else {
-                    $attachmentTodisplay = $convertedAttachment;
+                $convertedDocument = ConvertPdfController::getConvertedPdfById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => $id, 'collId' => $collId, 'isVersion' => $isVersion]);
+                if (empty($convertedDocument['errors'])) {
+                    $attachmentTodisplay = $convertedDocument;
                 }
                 $document['docserver_id'] = $attachmentTodisplay['docserver_id'];
                 $document['path'] = $attachmentTodisplay['path'];
                 $document['filename'] = $attachmentTodisplay['filename'];
             }
         } else {
-            $convertedDocument = ResModel::getConvertedPdfById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => $aArgs['resId']]);
+            $convertedDocument = ConvertPdfController::getConvertedPdfById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => $aArgs['resId'], 'collId' => 'letterbox_coll', 'isVersion' => false]);
 
-            if (empty($convertedDocument)) {
-                ConvertPdfController::convert([
-                    'resId'     => $aArgs['resId'],
-                    'collId'    => 'letterbox_coll',
-                ]);
-    
-                $convertedDocument = ResModel::getConvertedPdfById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => $aArgs['resId']]);
-                
-                if (!empty($convertedDocument)) {
-                    $documentTodisplay = $convertedDocument;
-                    $document['docserver_id'] = $documentTodisplay['docserver_id'];
-                    $document['path'] = $documentTodisplay['path'];
-                    $document['filename'] = $documentTodisplay['filename'];
-                }
-            } else {
+            if (empty($convertedDocument['errors'])) {
                 $documentTodisplay = $convertedDocument;
                 $document['docserver_id'] = $documentTodisplay['docserver_id'];
                 $document['path'] = $documentTodisplay['path'];
diff --git a/src/app/resource/controllers/StoreController.php b/src/app/resource/controllers/StoreController.php
index 48fb13f6afe..26b2548cdc7 100644
--- a/src/app/resource/controllers/StoreController.php
+++ b/src/app/resource/controllers/StoreController.php
@@ -75,18 +75,8 @@ class StoreController
             $resId = false;
             if ($aArgs['table'] == 'res_letterbox') {
                 $resId = ResModel::create($data);
-                ConvertPdfController::convert([
-                    'resId'     => $resId,
-                    'collId'    => 'letterbox_coll',
-                    'isVersion' => false,
-                ]);
             } elseif ($aArgs['table'] == 'res_attachments') {
                 $resId = AttachmentModel::create($data);
-                ConvertPdfController::convert([
-                    'resId'     => $resId,
-                    'collId'    => 'attachments_coll',
-                    'isVersion' => false,
-                ]);
             }
 
             return $resId;
diff --git a/src/app/resource/models/ResModelAbstract.php b/src/app/resource/models/ResModelAbstract.php
index 48ac92d8187..61529c26970 100644
--- a/src/app/resource/models/ResModelAbstract.php
+++ b/src/app/resource/models/ResModelAbstract.php
@@ -433,24 +433,4 @@ abstract class ResModelAbstract
 
         return $natures;
     }
-
-    public static function getConvertedPdfById(array $aArgs)
-    {
-        ValidatorModel::notEmpty($aArgs, ['resId']);
-        ValidatorModel::intVal($aArgs, ['resId']);
-        ValidatorModel::arrayType($aArgs, ['select']);
-
-        $document = DatabaseModel::select([
-            'select'    => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
-            'table'     => ['adr_letterbox'],
-            'where'     => ['res_id = ?', 'type = ?'],
-            'data'      => [$aArgs['resId'], 'PDF'],
-        ]);
-
-        if (empty($document[0])) {
-            return [];
-        }
-
-        return $document[0];
-    }
 }
diff --git a/src/app/signatureBook/controllers/SignatureBookController.php b/src/app/signatureBook/controllers/SignatureBookController.php
index 74e8bac53fb..094860776ec 100644
--- a/src/app/signatureBook/controllers/SignatureBookController.php
+++ b/src/app/signatureBook/controllers/SignatureBookController.php
@@ -14,10 +14,11 @@
 
 namespace SignatureBook\controllers;
 
+use Action\models\ActionModel;
 use Attachment\models\AttachmentModel;
 use Basket\models\BasketModel;
-use Action\models\ActionModel;
 use Contact\models\ContactModel;
+use Convert\controllers\ConvertPdfController;
 use Docserver\models\DocserverModel;
 use Entity\models\ListInstanceModel;
 use Group\models\ServiceModel;
@@ -188,9 +189,9 @@ class SignatureBookController
                 $isVersion = false;
             }
 
-            $convertedAttachment = AttachmentModel::getConvertedPdfById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => $value['res_id'], 'isVersion' => $isVersion]);
+            $convertedAttachment = ConvertPdfController::getConvertedPdfById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => $value['res_id'], 'collId' => 'attachments_coll', 'isVersion' => $isVersion]);
 
-            if (!empty($convertedAttachment)) {
+            if (empty($convertedAttachment['errors'])) {
                 $isConverted = true;
             } else {
                 $isConverted = false;
diff --git a/vendor/composer/ClassLoader.php b/vendor/composer/ClassLoader.php
index 4626994fd4d..dc02dfb114f 100644
--- a/vendor/composer/ClassLoader.php
+++ b/vendor/composer/ClassLoader.php
@@ -374,10 +374,14 @@ class ClassLoader
 
         $first = $class[0];
         if (isset($this->prefixLengthsPsr4[$first])) {
-            foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) {
-                if (0 === strpos($class, $prefix)) {
-                    foreach ($this->prefixDirsPsr4[$prefix] as $dir) {
-                        if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
+            $subPath = $class;
+            while (false !== $lastPos = strrpos($subPath, '\\')) {
+                $subPath = substr($subPath, 0, $lastPos);
+                $search = $subPath.'\\';
+                if (isset($this->prefixDirsPsr4[$search])) {
+                    $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
+                    foreach ($this->prefixDirsPsr4[$search] as $dir) {
+                        if (file_exists($file = $dir . $pathEnd)) {
                             return $file;
                         }
                     }
diff --git a/vendor/composer/LICENSE b/vendor/composer/LICENSE
index 1a28124886d..f0157a6ed02 100644
--- a/vendor/composer/LICENSE
+++ b/vendor/composer/LICENSE
@@ -1,21 +1,56 @@
+Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
+Upstream-Name: Composer
+Upstream-Contact: Jordi Boggiano <j.boggiano@seld.be>
+Source: https://github.com/composer/composer
 
-Copyright (c) 2016 Nils Adermann, Jordi Boggiano
+Files: *
+Copyright: 2016, Nils Adermann <naderman@naderman.de>
+           2016, Jordi Boggiano <j.boggiano@seld.be>
+License: Expat
 
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is furnished
-to do so, subject to the following conditions:
+Files: src/Composer/Util/TlsHelper.php
+Copyright: 2016, Nils Adermann <naderman@naderman.de>
+           2016, Jordi Boggiano <j.boggiano@seld.be>
+           2013, Evan Coury <me@evancoury.com>
+License: Expat and BSD-2-Clause
 
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
+License: BSD-2-Clause
+ Redistribution and use in source and binary forms, with or without modification,
+ are permitted provided that the following conditions are met:
+ .
+     * Redistributions of source code must retain the above copyright notice,
+       this list of conditions and the following disclaimer.
+ .
+     * Redistributions in binary form must reproduce the above copyright notice,
+       this list of conditions and the following disclaimer in the documentation
+       and/or other materials provided with the distribution.
+ .
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+License: Expat
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is furnished
+ to do so, subject to the following conditions:
+ .
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+ .
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
-- 
GitLab