Verified Commit 1aa16a70 authored by Damien's avatar Damien

FEAT #11691 TIME 4:00 Merge data

parent 2fd8af19
......@@ -102,17 +102,18 @@ abstract class AttachmentModelAbstract
return $aAttachments;
}
public static function create(array $aArgs)
public static function create(array $args)
{
ValidatorModel::notEmpty($aArgs, ['format', 'typist', 'creation_date', 'docserver_id', 'path', 'filename', 'fingerprint', 'filesize', 'status', 'relation']);
ValidatorModel::stringType($aArgs, ['format', 'typist', 'creation_date', 'docserver_id', 'path', 'filename', 'fingerprint', 'status']);
ValidatorModel::intVal($aArgs, ['filesize', 'relation']);
ValidatorModel::notEmpty($args, ['format', 'typist', 'creation_date', 'docserver_id', 'path', 'filename', 'fingerprint', 'filesize', 'status', 'relation']);
ValidatorModel::stringType($args, ['format', 'typist', 'creation_date', 'docserver_id', 'path', 'filename', 'fingerprint', 'status']);
ValidatorModel::intVal($args, ['filesize', 'relation']);
$nextSequenceId = DatabaseModel::getNextSequenceValue(['sequenceId' => 'res_attachment_res_id_seq']);
$aArgs['res_id'] = $nextSequenceId;
$args['res_id'] = $nextSequenceId;
DatabaseModel::insert([
'table' => 'res_attachments',
'columnsValues' => $aArgs
'columnsValues' => $args
]);
return $nextSequenceId;
......
......@@ -129,13 +129,13 @@ class JnlpController
$tagArg1 = $jnlpDocument->createElement('argument', $coreUrl . 'rest/jnlp/' . $jnlpUniqueId); //ProcessJnlp
$tagArg2 = $jnlpDocument->createElement('argument', $body['objectType']); //Type
$tagArg3 = $jnlpDocument->createElement('argument', 'table'); //Useless
$tagArg3 = $jnlpDocument->createElement('argument', urlencode(json_encode($body['data'])));
$tagArg4 = $jnlpDocument->createElement('argument', $body['objectId']); //ObjectId
$tagArg5 = $jnlpDocument->createElement('argument', 0); //Useless
$tagArg6 = $jnlpDocument->createElement('argument', "maarchCourrierAuth={$_COOKIE['maarchCourrierAuth']}"); //MaarchCookie
$tagArg7 = $jnlpDocument->createElement('argument', htmlentities($allCookies)); //AllCookies
$tagArg8 = $jnlpDocument->createElement('argument', $jnlpFileName); //JnlpFileName
$tagArg9 = $jnlpDocument->createElement('argument', $GLOBALS['id']); //CurrentUser
$tagArg9 = $jnlpDocument->createElement('argument', $GLOBALS['id']); //CurrentUser //Useless
$tagArg10 = $jnlpDocument->createElement('argument', 'false'); //ConvertPdf //Useless
$tagArg11 = $jnlpDocument->createElement('argument', 'false'); //OnlyConvert //Useless
$tagArg12 = $jnlpDocument->createElement('argument', 0); //HashFile //Useless
......@@ -202,21 +202,21 @@ class JnlpController
public function processJnlp(Request $request, Response $response, array $args)
{
$body = $request->getParams();
$queryParams = $request->getQueryParams();
$body = $request->getParsedBody();
$tmpPath = CoreConfigModel::getTmpPath();
if ($body['action'] == 'editObject') {
if ($body['objectType'] == 'templateCreation') {
//TODO passer l'id et pas le chemin dans objectId
$explodeFile = explode('.', $body['objectId']);
if ($queryParams['action'] == 'editObject') {
if ($queryParams['objectType'] == 'templateCreation') {
$explodeFile = explode('.', $queryParams['objectId']);
$ext = $explodeFile[count($explodeFile) - 1];
$newFileOnTmp = "tmp_file_{$GLOBALS['id']}_{$args['jnlpUniqueId']}.{$ext}";
$pathToCopy = $body['objectId'];
} elseif ($body['objectType'] == 'templateModification') {
$pathToCopy = $queryParams['objectId'];
} elseif ($queryParams['objectType'] == 'templateModification') {
$docserver = DocserverModel::getCurrentDocserver(['typeId' => 'TEMPLATES', 'collId' => 'templates', 'select' => ['path_template']]);
$template = TemplateModel::getById(['id' => $body['objectId'], 'select' => ['template_path', 'template_file_name']]);
$template = TemplateModel::getById(['id' => $queryParams['objectId'], 'select' => ['template_path', 'template_file_name']]);
if (empty($template)) {
$xmlResponse = JnlpController::generateResponse(['type' => 'ERROR', 'data' => ['ERROR' => "Template does not exist"]]);
$response->write($xmlResponse);
......@@ -228,26 +228,32 @@ class JnlpController
$newFileOnTmp = "tmp_file_{$GLOBALS['id']}_{$args['jnlpUniqueId']}.{$ext}";
$pathToCopy = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $template['template_path']) . $template['template_file_name'];
} elseif ($body['objectType'] == 'resourceCreation') {
} elseif ($queryParams['objectType'] == 'resourceCreation' || $queryParams['objectType'] == 'attachmentCreation') {
$docserver = DocserverModel::getCurrentDocserver(['typeId' => 'TEMPLATES', 'collId' => 'templates', 'select' => ['path_template']]);
$template = TemplateModel::getById(['id' => $body['objectId'], 'select' => ['template_path', 'template_file_name']]);
$template = TemplateModel::getById(['id' => $queryParams['objectId'], 'select' => ['template_path', 'template_file_name']]);
if (empty($template)) {
$xmlResponse = JnlpController::generateResponse(['type' => 'ERROR', 'data' => ['ERROR' => "Template does not exist"]]);
$response->write($xmlResponse);
return $response->withHeader('Content-Type', 'application/xml');
}
//TODO revoir le merge avec les data
// $mergedDocument = MergeController::mergeDocument([
// 'path' => $pathToDocument,
// 'data' => ['resId' => $aArgs['resId'], 'contactAddressId' => $contactToProcess, 'userId' => $currentUser['id']]
// ]);
$explodeFile = explode('.', $template['template_file_name']);
$ext = $explodeFile[count($explodeFile) - 1];
$newFileOnTmp = "tmp_file_{$GLOBALS['id']}_{$args['jnlpUniqueId']}.{$ext}";
$pathToCopy = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $template['template_path']) . $template['template_file_name'];
$dataToMerge = ['userId' => $GLOBALS['id']];
if (!empty($queryParams['objectTable'])) {
$decodedData = urldecode(json_decode($queryParams['objectTable'], true));
$dataToMerge = array_merge($dataToMerge, $decodedData);
}
$mergedDocument = MergeController::mergeDocument([
'content' => file_get_contents($pathToCopy),
'data' => $dataToMerge
]);
file_put_contents($tmpPath . $newFileOnTmp, base64_decode($mergedDocument['encodedDocument']));
} else {
$xmlResponse = JnlpController::generateResponse(['type' => 'ERROR', 'data' => ['ERROR' => 'Wrong objectType']]);
$response->write($xmlResponse);
......@@ -264,10 +270,10 @@ class JnlpController
$result = [
'STATUS' => 'ok',
'OBJECT_TYPE' => $body['objectType'],
'OBJECT_TABLE' => $body['objectTable'],
'OBJECT_ID' => $body['objectId'],
'UNIQUE_ID' => $body['uniqueId'],
'OBJECT_TYPE' => $queryParams['objectType'],
'OBJECT_TABLE' => $queryParams['objectTable'],
'OBJECT_ID' => $queryParams['objectId'],
'UNIQUE_ID' => $queryParams['uniqueId'],
'APP_PATH' => 'start',
'FILE_CONTENT' => base64_encode($fileContent),
'FILE_EXTENSION' => $ext,
......@@ -276,7 +282,7 @@ class JnlpController
];
$xmlResponse = JnlpController::generateResponse(['type' => 'SUCCESS', 'data' => $result]);
} elseif ($body['action'] == 'saveObject') {
} elseif ($queryParams['action'] == 'saveObject') {
if (empty($body['fileContent']) || empty($body['fileExtension'])) {
$xmlResponse = JnlpController::generateResponse(['type' => 'ERROR', 'data' => ['ERROR' => 'File content or file extension empty']]);
$response->write($xmlResponse);
......@@ -292,14 +298,14 @@ class JnlpController
fwrite($file, $fileContent);
fclose($file);
if (!empty($body['step']) && $body['step'] == 'end') {
if (!empty($queryParams['step']) && $queryParams['step'] == 'end') {
if (file_exists("{$tmpPath}{$GLOBALS['id']}_maarchCM_{$args['jnlpUniqueId']}.lck")) {
unlink("{$tmpPath}{$GLOBALS['id']}_maarchCM_{$args['jnlpUniqueId']}.lck");
}
}
$xmlResponse = JnlpController::generateResponse(['type' => 'SUCCESS', 'data' => ['END_MESSAGE' => 'Update ok']]);
} elseif ($body['action'] == 'terminate') {
} elseif ($queryParams['action'] == 'terminate') {
if (file_exists("{$tmpPath}{$GLOBALS['id']}_maarchCM_{$args['jnlpUniqueId']}.lck")) {
unlink("{$tmpPath}{$GLOBALS['id']}_maarchCM_{$args['jnlpUniqueId']}.lck");
}
......@@ -308,10 +314,10 @@ class JnlpController
} else {
$result = [
'STATUS' => 'ko',
'OBJECT_TYPE' => $body['objectType'],
'OBJECT_TABLE' => $body['objectTable'],
'OBJECT_ID' => $body['objectId'],
'UNIQUE_ID' => $body['uniqueId'],
'OBJECT_TYPE' => $queryParams['objectType'],
'OBJECT_TABLE' => $queryParams['objectTable'],
'OBJECT_ID' => $queryParams['objectId'],
'UNIQUE_ID' => $queryParams['uniqueId'],
'APP_PATH' => 'start',
'FILE_CONTENT' => '',
'FILE_EXTENSION' => '',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment