From 7b9a511b4f162f8ba5633bcee89a567c41ea1eef Mon Sep 17 00:00:00 2001 From: "florian.azizian" <florian.azizian@maarch.org> Date: Mon, 19 Oct 2020 19:04:02 +0200 Subject: [PATCH] FEAT #15050 TIME 0:25 batch get replies from archiving system --- bin/exportSeda/batch_tools.php | 33 ------------------------------ bin/exportSeda/checkAllReplies.php | 22 +++++++++++++++----- 2 files changed, 17 insertions(+), 38 deletions(-) diff --git a/bin/exportSeda/batch_tools.php b/bin/exportSeda/batch_tools.php index a08645906e8..1ac1d611355 100644 --- a/bin/exportSeda/batch_tools.php +++ b/bin/exportSeda/batch_tools.php @@ -140,39 +140,6 @@ function Bt_writeLog($args = []) ]); } -function Bt_createAttachment($args = []) -{ - $opts = [ - CURLOPT_URL => rtrim($GLOBALS['applicationUrl'], "/") . '/rest/attachments', - CURLOPT_HTTPHEADER => [ - 'accept:application/json', - 'content-type:application/json', - 'Authorization: Basic ' . base64_encode($GLOBALS['userWS']. ':' .$GLOBALS['passwordWS']), - ], - CURLOPT_RETURNTRANSFER => true, - CURLOPT_SSL_VERIFYPEER => false, - CURLOPT_POSTFIELDS => json_encode($args), - CURLOPT_POST => true - ]; - - $curl = curl_init(); - curl_setopt_array($curl, $opts); - $rawResponse = curl_exec($curl); - $error = curl_error($curl); - if (!empty($error)) { - Bt_writeLog(['level' => 'ERROR', 'message' => $error]); - exit; - } - - $return = json_decode($rawResponse, true); - if (!empty($return['errors'])) { - Bt_writeLog(['level' => 'ERROR', 'message' => $return['errors']]); - exit; - } - - return $return; -} - function Bt_getReply($args = []) { $refEncode = str_replace('.', '%2E', urlencode($args['reference'])); diff --git a/bin/exportSeda/checkAllReplies.php b/bin/exportSeda/checkAllReplies.php index d445f23d99b..e2411eb7e8c 100755 --- a/bin/exportSeda/checkAllReplies.php +++ b/bin/exportSeda/checkAllReplies.php @@ -26,7 +26,7 @@ class IncludeFileError extends Exception } // Globals variables definition -$GLOBALS['batchName'] = 'checkAllRepliesFromArchivingSystem'; +$GLOBALS['batchName'] = 'checkRepliesFromArchivingSystem'; $GLOBALS['wb'] = ''; $totalProcessedResources = 0; @@ -128,6 +128,7 @@ $replies = array_column($replies, 'res_id_master'); $pendingResources = array_diff($acknowledgements, $replies); $unitIdentifiers = []; +$nbMailsRetrieved = 0; foreach ($pendingResources as $resId) { $unitIdentifier = \MessageExchange\models\MessageExchangeModel::getUnitIdentifierByResId(['select' => ['message_id', 'res_id'], 'resId' => (string)$resId]); if (empty($unitIdentifier[0]['message_id'])) { @@ -151,19 +152,30 @@ foreach ($pendingResources as $resId) { continue; } - //créer message reply & sauvegarder xml $resIds = explode(',', $value); $data = json_decode($messages->replyMessage->data); - // TODO save reply - // $archiveTransferReply = new ArchiveTransferReply(); - // $archiveTransferReply->receive($data, $resIds); + // TODO GET XML + $pathToDocument = 'xmlFile'; + foreach ($resIds as $resId) { + $id = Resource\controllers\StoreController::storeAttachment([ + 'encodedFile' => base64_encode(file_get_contents($pathToDocument)), + 'type' => 'reply_record_management', + 'resIdMaster' => $resId, + 'title' => 'Réponse au transfert', + 'format' => 'xml', + 'status' => 'TRA' + ]); + if (empty($id) || !empty($id['errors'])) { + return ['errors' => ['[storeAttachment] ' . $id['errors']]]; + } \Resource\models\ResModel::update([ 'set' => ['status' => $GLOBALS['statusReplyReceived']], 'where' => ['res_id = ?'], 'data' => [$resId] ]); + $nbMailsRetrieved++; } } } -- GitLab