Skip to content
Snippets Groups Projects
Verified Commit 6c558e9e authored by Florian Azizian's avatar Florian Azizian
Browse files

FEAT #8391 save historic in attachment

parent 9ea2ebc2
No related branches found
No related tags found
No related merge requests found
......@@ -276,6 +276,27 @@ if (!empty($retrievedMails['error'])) {
foreach ($retrievedMails['isVersion'] as $resId => $value) {
$GLOBALS['logger']->write('Update res_version_attachments : ' . $resId . '. ExternalId : ' . $value->external_id, 'INFO');
if (!empty($value->log)) {
$GLOBALS['logger']->write('Create log Attachment', 'INFO');
Bt_createAttachment([
'res_id_master' => $value->res_id_master,
'title' => '[xParaph Log] ' . $value->title,
'identifier' => $value->identifier,
'type_id' => $value->type_id,
'dest_contact_id' => $value->dest_contact_id,
'dest_address_id' => $value->dest_address_id,
'dest_user' => $value->dest_user,
'typist' => $value->typist,
'format' => 'xml',
'attachment_type' => $value->attachment_type,
'relation' => 1,
'status' => 'TRA',
'encodedFile' => $value->log,
'in_signature_book' => 'false',
'table' => 'res_attachments'
]);
}
if ($value->status == 'validated') {
if (!empty($value->encodedFile)) {
$GLOBALS['logger']->write('Create validated version Attachment', 'INFO');
......@@ -358,6 +379,27 @@ foreach ($retrievedMails['isVersion'] as $resId => $value) {
foreach ($retrievedMails['noVersion'] as $resId => $value) {
$GLOBALS['logger']->write('Update res_attachments : ' . $resId . '. ExternalId : ' . $value->external_id, 'INFO');
if (!empty($value->log)) {
$GLOBALS['logger']->write('Create log Attachment', 'INFO');
Bt_createAttachment([
'res_id_master' => $value->res_id_master,
'title' => '[xParaph Log] ' . $value->title,
'identifier' => $value->identifier,
'type_id' => $value->type_id,
'dest_contact_id' => $value->dest_contact_id,
'dest_address_id' => $value->dest_address_id,
'dest_user' => $value->dest_user,
'typist' => $value->typist,
'format' => 'xml',
'attachment_type' => $value->attachment_type,
'relation' => 1,
'status' => 'TRA',
'encodedFile' => $value->log,
'in_signature_book' => 'false',
'table' => 'res_attachments'
]);
}
if ($value->status == 'validated') {
if (!empty($value->encodedFile)) {
$GLOBALS['logger']->write('Create validated Attachment', 'INFO');
......
......@@ -189,6 +189,7 @@ class XParaphController
public static function retrieveSignedMails($aArgs)
{
$tmpPath = CoreConfigModel::getTmpPath();
foreach (['noVersion', 'isVersion'] as $version) {
$depotids = [];
foreach ($aArgs['idsToRetrieve'][$version] as $resId => $value) {
......@@ -210,6 +211,28 @@ class XParaphController
if ($state['id'] == 'refused') {
$aArgs['idsToRetrieve'][$version][$resId]->status = 'refused';
$aArgs['idsToRetrieve'][$version][$resId]->noteContent = $state['note'];
$processedFile = XParaphController::getFile(['config' => $aArgs['config'], 'depotId' => $value->external_id]);
if (!empty($processedFile['errors'])) {
unset($aArgs['idsToRetrieve'][$version][$resId]);
continue;
}
$file = base64_decode($processedFile['zip']);
$unzipName = 'tmp_file_' .rand(). '_xParaph_' .rand();
$tmpName = $unzipName . '.zip';
file_put_contents($tmpPath . $tmpName, $file);
$zip = new \ZipArchive();
$zip->open($tmpPath . $tmpName);
$zip->extractTo($tmpPath . $unzipName);
foreach (glob($tmpPath . $unzipName . '/*.xml') as $filename) {
$log = base64_encode(file_get_contents($filename));
}
unlink($tmpPath . $tmpName);
$aArgs['idsToRetrieve'][$version][$resId]->log = $log;
} elseif ($state['id'] == 'validateSignature' || $state['id'] == 'validateOnlyVisa') {
$processedFile = XParaphController::getFile(['config' => $aArgs['config'], 'depotId' => $value->external_id]);
if (!empty($processedFile['errors'])) {
......@@ -223,7 +246,6 @@ class XParaphController
$unzipName = 'tmp_file_' .rand(). '_xParaph_' .rand();
$tmpName = $unzipName . '.zip';
$tmpPath = CoreConfigModel::getTmpPath();
file_put_contents($tmpPath . $tmpName, $file);
$zip = new \ZipArchive();
......@@ -233,6 +255,9 @@ class XParaphController
foreach (glob($tmpPath . $unzipName . '/*.pdf') as $filename) {
$encodedFile = base64_encode(file_get_contents($filename));
}
foreach (glob($tmpPath . $unzipName . '/*.xml') as $filename) {
$log = base64_encode(file_get_contents($filename));
}
unlink($tmpPath . $tmpName);
$aArgs['idsToRetrieve'][$version][$resId]->encodedFile = $encodedFile;
......@@ -240,6 +265,7 @@ class XParaphController
if ($state['id'] == 'validateOnlyVisa') {
$aArgs['idsToRetrieve'][$version][$resId]->onlyVisa = true;
}
$aArgs['idsToRetrieve'][$version][$resId]->log = $log;
} else {
unset($aArgs['idsToRetrieve'][$version][$resId]);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment