From f4aca7f0e80fc1c65245db4ca191e49007bfded3 Mon Sep 17 00:00:00 2001
From: "florian.azizian" <florian.azizian@maarch.org>
Date: Fri, 8 Nov 2019 18:04:38 +0100
Subject: [PATCH] FEAT #11691 TIME 0:20 improve migrate fingerprint in
 res_vers_attachments

---
 migration/19.12/migrateVersionAttachments.php | 21 +++++++++++++++++++
 .../resource/controllers/StoreController.php  |  1 -
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/migration/19.12/migrateVersionAttachments.php b/migration/19.12/migrateVersionAttachments.php
index 61aa0a3ebcc..234c7239c4c 100644
--- a/migration/19.12/migrateVersionAttachments.php
+++ b/migration/19.12/migrateVersionAttachments.php
@@ -33,6 +33,27 @@ foreach ($customs as $custom) {
         $attachmentInfo['in_signature_book'] = empty($attachmentInfo['in_signature_book']) ?  'false' : 'true';
         $attachmentInfo['in_send_attach']    = empty($attachmentInfo['in_send_attach']) ?  'false' : 'true';
         $attachmentInfo['format']            = empty($attachmentInfo['format']) ?  pathinfo($attachmentInfo['filename'], PATHINFO_EXTENSION) : $attachmentInfo['format'];
+        if (empty($attachmentInfo['fingerprint'])) {
+            $docserver = \SrcCore\models\DatabaseModel::select([
+                'select' => ['path_template', 'docserver_type_id'],
+                'table'  => ['docservers'],
+                'where'  => ['docserver_id = ?'],
+                'data'   => [$attachmentInfo['docserver_id']]
+            ]);
+            $docserverType = \SrcCore\models\DatabaseModel::select([
+                'select' => ['fingerprint_mode'],
+                'table'  => ['docserver_types'],
+                'where'  => ['docserver_type_id = ?'],
+                'data'   => [$docserver[0]['docserver_type_id']]
+            ]);
+            $pathToDocument = $docserver[0]['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $attachmentInfo['path']) . $attachmentInfo['filename'];
+            if (file_exists($pathToDocument)) {
+                $fingerprint = \Resource\controllers\StoreController::getFingerPrint(['filePath' => $pathToDocument, 'mode' => $docserverType[0]['fingerprint_mode']]);
+                $attachmentInfo['fingerprint'] = $fingerprint;
+            } else {
+                $attachmentInfo['fingerprint'] = 1;
+            }
+        }
 
         $newResId = \Attachment\models\AttachmentModel::create($attachmentInfo);
 
diff --git a/src/app/resource/controllers/StoreController.php b/src/app/resource/controllers/StoreController.php
index a1e80cc7992..d17b51e6d78 100755
--- a/src/app/resource/controllers/StoreController.php
+++ b/src/app/resource/controllers/StoreController.php
@@ -24,7 +24,6 @@ use SrcCore\models\DatabaseModel;
 use SrcCore\models\ValidatorModel;
 use Resource\models\ResModel;
 use SrcCore\models\CoreConfigModel;
-use User\models\UserModel;
 
 class StoreController
 {
-- 
GitLab