From 4fc3d8b08ebdd4ab752c06001b59bca9cd39c8cd Mon Sep 17 00:00:00 2001 From: "florian.azizian" <florian.azizian@maarch.org> Date: Fri, 22 Jan 2021 12:21:09 +0100 Subject: [PATCH] FEAT #15155 TIME 2:20 Send To RecordManagement with multiple documents --- .../controllers/ExportSEDATrait.php | 48 ++++++++----------- .../controllers/PreProcessActionSEDATrait.php | 5 +- .../exportSeda/controllers/SedaController.php | 11 +++-- .../controllers/SendMessageController.php | 26 ++++------ src/app/folder/models/FolderModelAbstract.php | 4 +- .../controllers/ResourceListController.php | 5 +- 6 files changed, 46 insertions(+), 53 deletions(-) diff --git a/src/app/external/exportSeda/controllers/ExportSEDATrait.php b/src/app/external/exportSeda/controllers/ExportSEDATrait.php index 730aa077a39..7dc4e448f22 100644 --- a/src/app/external/exportSeda/controllers/ExportSEDATrait.php +++ b/src/app/external/exportSeda/controllers/ExportSEDATrait.php @@ -90,18 +90,12 @@ trait ExportSEDATrait return ['errors' => ['No senderOrgRegNumber found in config.json']]; } - foreach (['packageName', 'archivalAgreement', 'slipId', 'entityArchiveRecipient', 'archiveDescriptionLevel'] as $value) { + foreach (['archivalAgreement', 'entityArchiveRecipient'] as $value) { if (empty($args['data'][$value])) { return ['errors' => [$value . ' is empty']]; } } - foreach ($args['data']['archives'] as $archiveUnit) { - if (empty($archiveUnit['id']) or empty($archiveUnit['descriptionLevel'])) { - return ['errors' => ['Missing id or descriptionLevel for an archiveUnit']]; - } - } - $initData = SedaController::initArchivalData([ 'resource' => $resource, 'senderOrgRegNumber' => $config['exportSeda']['senderOrgRegNumber'], @@ -116,24 +110,6 @@ trait ExportSEDATrait $initData = $initData['archivalData']; } - $archivesAttachment = []; - $initialArchiveUnits = $initData['archiveUnits']; - foreach ($initialArchiveUnits as $archiveUnit) { - $archiveFound = false; - foreach ($args['data']['archives'] as $userArchiveUnit) { - if ($userArchiveUnit['id'] == $archiveUnit['id']) { - $archiveUnit['descriptionLevel'] = $userArchiveUnit['descriptionLevel']; - $archivesAttachment[] = $archiveUnit; - $archiveFound = true; - break; - } - } - if (!$archiveFound) { - $archiveUnit['descriptionLevel'] = 'Item'; - $archivesAttachment = $archiveUnit; - } - } - $history = ExportSEDATrait::getHistory(['resId' => $resource['res_id']]); $folder = ExportSEDATrait::getFolderPath(['selectedFolder' => $args['data']['folder'], 'folders' => $initData['additionalData']['folders']]); @@ -144,7 +120,6 @@ trait ExportSEDATrait 'id' => $entity['producer_service'], 'label' => $entity['entity_label'] ], - 'descriptionLevel' => $args['data']['archiveDescriptionLevel'], 'receivedDate' => $resource['admission_date'], 'documentDate' => $resource['doc_date'], 'creationDate' => $resource['creation_date'], @@ -157,7 +132,7 @@ trait ExportSEDATrait 'senders' => ContactController::getParsedContacts(['resId' => $resource['res_id'], 'mode' => 'sender']), 'recipients' => ContactController::getParsedContacts(['resId' => $resource['res_id'], 'mode' => 'recipient']) ], - 'attachments' => $archivesAttachment, + 'attachments' => $initData['archivalData']['archiveUnits'], 'folders' => $folder['folderPath'], 'links' => $initData['additionalData']['linkedResources'] ]; @@ -165,7 +140,6 @@ trait ExportSEDATrait $data = [ 'type' => 'ArchiveTransfer', 'messageObject' => [ - 'messageName ' => $args['data']['packageName'], 'messageIdentifier' => $initData['data']['slipInfo']['slipId'], 'archivalAgreement' => $args['data']['archivalAgreement'], 'dataObjectPackage' => $dataObjectPackage, @@ -192,7 +166,7 @@ trait ExportSEDATrait $encodedContent = base64_encode(file_get_contents($sedaPackage['encodedFilePath'])); unlink($sedaPackage['encodedFilePath']); return ['data' => ['encodedFile' => $encodedContent]]; - } else { + } elseif ($args['massAction']) { $resId = '--resId ' . $resource['res_id']; $userId = '--userId ' . $GLOBALS['id']; $messageId = '--messageId ' . $messageSaved['messageId']; @@ -207,6 +181,19 @@ trait ExportSEDATrait exec("php src/app/external/exportSeda/scripts/ExportSedaScript.php {$customId} {$resId} {$userId} {$messageId} {$encodedFilePath} {$messageFileName} {$reference} {$actionId} > /dev/null &"); return true; + } else { + $elementSend = ExportSEDATrait::sendSedaPackage([ + 'messageId' => $messageSaved['messageId'], + 'config' => $config, + 'encodedFilePath' => $sedaPackage['encodedFilePath'], + 'messageFilename' => $sedaPackage['messageFilename'], + 'resId' => $resource['res_id'], + 'reference' => $data['messageObject']['messageIdentifier'] + ]); + unlink($sedaPackage['encodedFilePath']); + if (!empty($elementSend['errors'])) { + return ['errors' => [$elementSend['errors']]]; + } } } @@ -311,6 +298,9 @@ trait ExportSEDATrait break; } } + } elseif (!empty($args['folders'])) { + $folderId = explode("_", $args['folders'][0]['id'])[1]; + $folderPath = FolderModel::getFolderPath(['id' => $folderId]); } return ['folderPath' => $folderPath]; diff --git a/src/app/external/exportSeda/controllers/PreProcessActionSEDATrait.php b/src/app/external/exportSeda/controllers/PreProcessActionSEDATrait.php index 5a8defd8a01..8bd0535cf55 100644 --- a/src/app/external/exportSeda/controllers/PreProcessActionSEDATrait.php +++ b/src/app/external/exportSeda/controllers/PreProcessActionSEDATrait.php @@ -130,6 +130,8 @@ trait PreProcessActionSEDATrait $resourcesInformations['archivalAgreements'] = $archivalAgreements['archivalAgreements']; $resourcesInformations['recipientArchiveEntities'] = $recipientArchiveEntities['archiveEntities']; $resourcesInformations['senderArchiveEntity'] = $config['exportSeda']['senderOrgRegNumber']; + + $massAction = count($body['resources']) > 1; // End of Common Data foreach ($body['resources'] as $resId) { @@ -179,7 +181,8 @@ trait PreProcessActionSEDATrait 'resource' => $resources[$resId], 'senderOrgRegNumber' => $config['exportSeda']['senderOrgRegNumber'], 'entity' => $destinationsData[$destinationId], - 'doctype' => $doctypesData[$typeId] + 'doctype' => $doctypesData[$typeId], + 'massAction' => $massAction ]); if (!empty($archivalData['errors'])) { diff --git a/src/app/external/exportSeda/controllers/SedaController.php b/src/app/external/exportSeda/controllers/SedaController.php index 899acb3ac6e..2c50d5803a8 100755 --- a/src/app/external/exportSeda/controllers/SedaController.php +++ b/src/app/external/exportSeda/controllers/SedaController.php @@ -101,7 +101,7 @@ class SedaController 'id' => 'letterbox_' . $args['resource']['res_id'], 'label' => $args['resource']['subject'], 'type' => 'mainDocument', - 'descriptionLevel' => 'Item' + 'descriptionLevel' => 'File' ]; if ($args['getFile']) { @@ -198,10 +198,13 @@ class SedaController $entities = [0]; } + $folderLimit = $args['massAction'] ? 1 : 0; $folders = FolderModel::getWithEntitiesAndResources([ - 'select' => ['DISTINCT(folders.id)', 'folders.label'], - 'where' => ['res_id = ?', '(entity_id in (?) OR keyword = ?)', 'folders.public = TRUE'], - 'data' => [$args['resource']['res_id'], $entities, 'ALL_ENTITIES'] + 'select' => ['DISTINCT(folders.id)', 'folders.label'], + 'where' => ['res_id = ?', '(entity_id in (?) OR keyword = ?)', 'folders.public = TRUE'], + 'data' => [$args['resource']['res_id'], $entities, 'ALL_ENTITIES'], + 'orderBy' => ['folders.label'], + 'limit' => $folderLimit ]); foreach ($folders as $folder) { $return['additionalData']['folders'][] = [ diff --git a/src/app/external/exportSeda/controllers/SendMessageController.php b/src/app/external/exportSeda/controllers/SendMessageController.php index 85bccdf6da7..7c74997a9f1 100755 --- a/src/app/external/exportSeda/controllers/SendMessageController.php +++ b/src/app/external/exportSeda/controllers/SendMessageController.php @@ -90,7 +90,7 @@ class SendMessageController null ); - foreach($messageObject->dataObjectPackage->attachments as $attachment) { + foreach ($messageObject->dataObjectPackage->attachments as $attachment) { $seda2Message->DataObjectPackage->BinaryDataObject[] = self::getBinaryDataObject( $attachment->filePath, $attachment->id @@ -248,7 +248,6 @@ class SendMessageController } else { $archiveUnit->DataObjectReference->DataObjectReferenceId = $dataObjectReferenceId; } - } $archiveUnit->ArchiveUnit = []; @@ -279,7 +278,6 @@ class SendMessageController private function getContent($type, $object = null, $relatedObjectReference = null) { - $content = new \stdClass(); switch ($type) { @@ -312,23 +310,22 @@ class SendMessageController $content->Keyword = []; if ($object->contacts) { - foreach($object->contacts as $contactType => $contacts) { - foreach($contacts as $contact) { + foreach ($object->contacts as $contactType => $contacts) { + foreach ($contacts as $contact) { if ($contactType == "senders") { - $content->Sender[] = self::getAddresse($contact, $contactType); - } else if ($contactType == "recipients") { - $content->Addressee[] = self::getAddresse($contact, $contactType); + $content->Sender[] = self::getAddresse($contact); + } elseif ($contactType == "recipients") { + $content->Addressee[] = self::getAddresse($contact); } - } } } - if ($object->folders ) { + if ($object->folders) { $content->FilePlanPosition = []; $content->FilePlanPosition[] = new \stdClass; $content->FilePlanPosition[0]->value=""; - foreach($object->folders as $folder) { + foreach ($object->folders as $folder) { $content->FilePlanPosition[0]->value .= "/".$folder; } } @@ -399,7 +396,6 @@ class SendMessageController } } } - } if (isset($object->originatorAgency)) { @@ -415,7 +411,7 @@ class SendMessageController if (isset($object->history)) { $content->CustodialHistory = new \stdClass(); $content->CustodialHistory->CustodialHistoryItem = []; - foreach($object->history as $history) { + foreach ($object->history as $history) { $content->CustodialHistory->CustodialHistoryItem[] = self::getCustodialHistoryItem($history); } @@ -464,7 +460,7 @@ class SendMessageController return $custodialHistoryItem; } - private function getAddresse($informations, $type = null) + private function getAddresse($informations) { $addressee = new \stdClass(); @@ -479,6 +475,4 @@ class SendMessageController } return $addressee; } - - } diff --git a/src/app/folder/models/FolderModelAbstract.php b/src/app/folder/models/FolderModelAbstract.php index dc4137294a9..16ef5ab6c4a 100755 --- a/src/app/folder/models/FolderModelAbstract.php +++ b/src/app/folder/models/FolderModelAbstract.php @@ -161,7 +161,9 @@ class FolderModelAbstract 'left_join' => ['folders.id = entities_folders.folder_id', 'folders.id = resources_folders.folder_id'], 'where' => empty($args['where']) ? [] : $args['where'], 'data' => empty($args['data']) ? [] : $args['data'], - 'groupBy' => empty($args['groupBy']) ? [] : $args['groupBy'] + 'groupBy' => empty($args['groupBy']) ? [] : $args['groupBy'], + 'order_by' => empty($args['orderBy']) ? [] : $args['orderBy'], + 'limit' => empty($args['limit']) ? 0 : $args['limit'], ]); return $folders; diff --git a/src/app/resource/controllers/ResourceListController.php b/src/app/resource/controllers/ResourceListController.php index 6d8025b35ca..41939437d00 100644 --- a/src/app/resource/controllers/ResourceListController.php +++ b/src/app/resource/controllers/ResourceListController.php @@ -483,8 +483,9 @@ class ResourceListController $body['data'] = empty($body['data']) ? [] : $body['data']; $body['note'] = empty($body['note']) ? [] : $body['note']; - $method = ActionMethodController::COMPONENTS_ACTIONS[$action['component']]; + $method = ActionMethodController::COMPONENTS_ACTIONS[$action['component']]; $methodResponses = []; + $massAction = count($resourcesForAction) > 1; foreach ($resourcesForAction as $key => $resId) { if (!empty($actionRequiredFields)) { $requiredFieldsValid = ActionController::checkRequiredFields(['resId' => $resId, 'actionRequiredFields' => $actionRequiredFields]); @@ -506,7 +507,7 @@ class ResourceListController } if (!empty($method)) { - $methodResponse = ActionMethodController::$method(['resId' => $resId, 'data' => $body['data'], 'note' => $body['note'], 'parameters' => $parameters]); + $methodResponse = ActionMethodController::$method(['resId' => $resId, 'data' => $body['data'], 'note' => $body['note'], 'parameters' => $parameters, 'massAction' => $massAction]); if (!empty($methodResponse['errors'])) { if (empty($methodResponses['errors'])) { -- GitLab