Skip to content
Snippets Groups Projects
Verified Commit 04c28714 authored by Damien's avatar Damien
Browse files

FEAT #12332 TIME 1:00 Fusion chrono when storing

parent 5f66fde2
No related branches found
No related tags found
No related merge requests found
......@@ -31,6 +31,8 @@ include_once('vendor/tinybutstrong/opentbs/tbs_plugin_opentbs.php');
class MergeController
{
const OFFICE_EXTENSIONS = ['odt', 'ods', 'odp', 'xlsx', 'pptx', 'docx', 'odf'];
public static function mergeDocument(array $args)
{
ValidatorModel::notEmpty($args, ['data']);
......@@ -70,7 +72,7 @@ class MergeController
$tbs->MergeField($key, $value);
}
if (in_array($extension, ['odt', 'ods', 'odp', 'xlsx', 'pptx', 'docx', 'odf'])) {
if (in_array($extension, MergeController::OFFICE_EXTENSIONS)) {
$tbs->Show(OPENTBS_STRING);
} else {
$tbs->Show(TBS_NOTHING);
......@@ -102,6 +104,7 @@ class MergeController
}
$resource = [
'model_id' => $args['modelId'] ?? null,
'alt_identifier' => '[res_letterbox.alt_identifier]',
'category_id' => $indexingModel['category'] ?? null,
'type_id' => $args['doctype'] ?? null,
'subject' => $args['subject'] ?? null,
......@@ -269,4 +272,44 @@ class MergeController
return $dataToBeMerge;
}
public static function mergeChronoDocument(array $args)
{
ValidatorModel::stringType($args, ['path', 'content', 'chrono']);
$tbs = new \clsTinyButStrong();
$tbs->NoErr = true;
$tbs->PlugIn(TBS_INSTALL, OPENTBS_PLUGIN);
if (!empty($args['path'])) {
$pathInfo = pathinfo($args['path']);
$extension = $pathInfo['extension'];
} else {
$tbs->Source = $args['content'];
$extension = 'unknow';
$args['path'] = null;
}
if (!empty($args['path'])) {
if ($extension == 'odt') {
$tbs->LoadTemplate($args['path'], OPENTBS_ALREADY_UTF8);
// $tbs->LoadTemplate("{$args['path']}#content.xml;styles.xml", OPENTBS_ALREADY_UTF8);
} elseif ($extension == 'docx') {
$tbs->LoadTemplate($args['path'], OPENTBS_ALREADY_UTF8);
// $tbs->LoadTemplate("{$args['path']}#word/header1.xml;word/footer1.xml", OPENTBS_ALREADY_UTF8);
} else {
$tbs->LoadTemplate($args['path'], OPENTBS_ALREADY_UTF8);
}
}
$tbs->MergeField('res_letterbox', ['alt_identifier' => $args['chrono']]);
if (in_array($extension, MergeController::OFFICE_EXTENSIONS)) {
$tbs->Show(OPENTBS_STRING);
} else {
$tbs->Show(TBS_NOTHING);
}
return ['encodedDocument' => base64_encode($tbs->Source)];
}
}
......@@ -16,6 +16,7 @@
namespace Resource\controllers;
use Attachment\models\AttachmentModel;
use ContentManagement\controllers\MergeController;
use Docserver\controllers\DocserverController;
use Entity\models\EntityModel;
use IndexingModel\models\IndexingModelModel;
......@@ -36,10 +37,22 @@ class StoreController
$resId = DatabaseModel::getNextSequenceValue(['sequenceId' => 'res_id_mlb_seq']);
$data = ['resId' => $resId];
$data = array_merge($args, $data);
$data = StoreController::prepareStorage($data);
if (!empty($args['encodedFile'])) {
$fileContent = base64_decode(str_replace(['-', '_'], ['+', '/'], $args['encodedFile']));
if (in_array($args['format'], MergeController::OFFICE_EXTENSIONS)) {
$tmpPath = CoreConfigModel::getTmpPath();
$uniqueId = CoreConfigModel::uniqueId();
$tmpFilename = "storeTmp_{$GLOBALS['id']}_{$uniqueId}.{$args['format']}";
file_put_contents($tmpPath . $tmpFilename, $fileContent);
$fileContent = MergeController::mergeChronoDocument(['chrono' => $data['alt_identifier'], 'path' => $tmpPath . $tmpFilename]);
$fileContent = base64_decode($fileContent['encodedDocument']);
unlink($tmpPath . $tmpFilename);
}
$storeResult = DocserverController::storeResourceOnDocServer([
'collId' => 'letterbox_coll',
'docserverTypeId' => 'DOC',
......@@ -57,9 +70,6 @@ class StoreController
$data['fingerprint'] = $storeResult['fingerPrint'];
}
$data = array_merge($args, $data);
$data = StoreController::prepareStorage($data);
ResModel::create($data);
return $resId;
......@@ -113,8 +123,7 @@ class StoreController
public static function prepareStorage(array $args)
{
ValidatorModel::notEmpty($args, ['resId', 'modelId']);
ValidatorModel::stringType($args, ['docserver_id', 'filename', 'format', 'path', 'fingerprint']);
ValidatorModel::intVal($args, ['resId', 'modelId', 'filesize']);
ValidatorModel::intVal($args, ['resId', 'modelId']);
$indexingModel = IndexingModelModel::getById(['id' => $args['modelId'], 'select' => ['category']]);
......@@ -164,12 +173,6 @@ class StoreController
'barcode' => $args['barcode'] ?? null,
'origin' => $args['origin'] ?? null,
'external_id' => $externalId,
'format' => empty($args['encodedFile']) ? null : $args['format'],
'docserver_id' => empty($args['encodedFile']) ? null : $args['docserver_id'],
'filename' => empty($args['encodedFile']) ? null : $args['filename'],
'filesize' => empty($args['encodedFile']) ? null : $args['filesize'],
'path' => empty($args['encodedFile']) ? null : $args['path'],
'fingerprint' => empty($args['encodedFile']) ? null : $args['fingerprint'],
'creation_date' => 'CURRENT_TIMESTAMP'
];
......
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