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

FEAT #8753 Get Attachment

parent dfdd4406
No related branches found
No related tags found
No related merge requests found
......@@ -38,40 +38,14 @@ $app->add(function (\Slim\Http\Request $request, \Slim\Http\Response $response,
});
//Attachments
$app->get('/attachments/{id}', \Attachment\controllers\AttachmentController::class . ':getById');
//Documents
$app->get('/documents', \Document\controllers\DocumentController::class . ':get');
$app->get('/documents/{id}', \Document\controllers\DocumentController::class . ':getById');
////Ressources
//$app->post('/res', \Resource\controllers\ResController::class . ':create');
//$app->post('/resExt', \Resource\controllers\ResController::class . ':createExt');
//$app->get('/res/{resId}/thumbnail', \Resource\controllers\ResController::class . ':getThumbnailContent');
//$app->put('/res/resource/status', \Resource\controllers\ResController::class . ':updateStatus');
//$app->post('/res/list', \Resource\controllers\ResController::class . ':getList');
//$app->get('/res/{resId}/lock', \Resource\controllers\ResController::class . ':isLock');
//$app->get('/res/{resId}/notes/count', \Resource\controllers\ResController::class . ':getNotesCountForCurrentUserById');
//$app->put('/res/externalInfos', \Resource\controllers\ResController::class . ':updateExternalInfos');
//$app->get('/categories', \Resource\controllers\ResController::class . ':getCategories');
//$app->get('/natures', \Resource\controllers\ResController::class . ':getNatures');
//$app->get('/resources/groups/{groupSerialId}/baskets/{basketId}', \Resource\controllers\ResController::class . ':getResourcesByBasket');
//
////Attachments
//$app->post('/attachments', \Attachment\controllers\AttachmentController::class . ':create');
//$app->get('/res/{resId}/attachments', \Attachment\controllers\AttachmentController::class . ':getAttachmentsListById');
//$app->get('/res/{resIdMaster}/attachments/{resId}/content', \Attachment\controllers\AttachmentController::class . ':getFileContent');
//$app->get('/res/{resIdMaster}/attachments/{resId}/thumbnail', \Attachment\controllers\AttachmentController::class . ':getThumbnailContent');
//
////SignatureBook
//$app->get('/{basketId}/signatureBook/resList', \SignatureBook\controllers\SignatureBookController::class . ':getResList');
//$app->get('/{basketId}/signatureBook/resList/details', \SignatureBook\controllers\SignatureBookController::class . ':getDetailledResList');
//$app->get('/groups/{groupId}/baskets/{basketId}/signatureBook/{resId}', \SignatureBook\controllers\SignatureBookController::class . ':getSignatureBook');
//$app->get('/signatureBook/{resId}/attachments', \SignatureBook\controllers\SignatureBookController::class . ':getAttachmentsById');
//$app->get('/signatureBook/{resId}/incomingMailAttachments', \SignatureBook\controllers\SignatureBookController::class . ':getIncomingMailAndAttachmentsById');
//$app->put('/signatureBook/{resId}/unsign', \SignatureBook\controllers\SignatureBookController::class . ':unsignFile');
//$app->put('/attachments/{id}/inSignatureBook', \Attachment\controllers\AttachmentController::class . ':setInSignatureBook');
//
//
////Users
//$app->get('/users', \User\controllers\UserController::class . ':get');
//$app->post('/users', \User\controllers\UserController::class . ':create');
......
......@@ -9,7 +9,9 @@ INSERT INTO users (login, password, firstname, lastname, mail, enabled, status,
------------
TRUNCATE TABLE docservers;
INSERT INTO docservers (type, label, is_readonly, size_limit_number, actual_size_number, path, creation_date)
VALUES ('DOC', 'Documents principaux', 'N', 50000000000, 0, '/opt/maarchparapheur/docservers/manual/', CURRENT_TIMESTAMP);
VALUES ('DOC', 'Documents principaux', 'N', 50000000000, 0, '/opt/maarchparapheur/docservers/documents/', CURRENT_TIMESTAMP);
INSERT INTO docservers (type, label, is_readonly, size_limit_number, actual_size_number, path, creation_date)
VALUES ('ATTACH', 'Documents joints', 'N', 50000000000, 0, '/opt/maarchparapheur/docservers/attachments/', CURRENT_TIMESTAMP);
------------
--STATUS
......
......@@ -34,17 +34,11 @@ DROP TABLE IF EXISTS attachments;
CREATE TABLE attachments
(
id serial NOT NULL,
subject text,
main_document_id bigint NOT NULL,
reference character varying(255),
format character varying(50) NOT NULL,
typist character varying(128) NOT NULL,
creation_date timestamp without time zone NOT NULL,
docserver_id character varying(32) NOT NULL,
path character varying(255) DEFAULT NULL::character varying,
filename character varying(255) DEFAULT NULL::character varying,
fingerprint character varying(255) DEFAULT NULL::character varying,
filesize bigint,
main_document_id bigint,
subject text,
creation_date timestamp without time zone NOT NULL DEFAULT NOW(),
modification_date timestamp without time zone DEFAULT NOW(),
CONSTRAINT attachments_pkey PRIMARY KEY (id)
)
WITH (OIDS=FALSE);
......
This diff is collapsed.
......@@ -14,6 +14,59 @@
namespace Attachment\models;
class AttachmentModel extends AttachmentModelAbstract
use SrcCore\models\DatabaseModel;
use SrcCore\models\ValidatorModel;
class AttachmentModel
{
public static function get(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['select']);
ValidatorModel::arrayType($aArgs, ['select', 'where', 'data']);
$attachments = DatabaseModel::select([
'select' => $aArgs['select'],
'table' => ['attachments'],
'where' => empty($aArgs['where']) ? [] : $aArgs['where'],
'data' => empty($aArgs['data']) ? [] : $aArgs['data']
]);
return $attachments;
}
public static function getById(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['select', 'id']);
ValidatorModel::arrayType($aArgs, ['select']);
ValidatorModel::intVal($aArgs, ['id']);
$attachment = DatabaseModel::select([
'select' => $aArgs['select'],
'table' => ['attachments'],
'where' => ['id = ?'],
'data' => [$aArgs['id']]
]);
if (empty($attachment[0])) {
return [];
}
return $attachment[0];
}
public static function getByDocumentId(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['select', 'documentId']);
ValidatorModel::arrayType($aArgs, ['select']);
ValidatorModel::intVal($aArgs, ['documentId']);
$attachments = DatabaseModel::select([
'select' => $aArgs['select'],
'table' => ['attachments'],
'where' => ['main_document_id = ?'],
'data' => [$aArgs['documentId']]
]);
return $attachments;
}
}
<?php
/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.
*
*/
/**
* @brief Attachment Model Abstract
* @author dev@maarch.org
*/
namespace Attachment\models;
use SrcCore\models\CoreConfigModel;
use SrcCore\models\DatabaseModel;
use SrcCore\models\ValidatorModel;
abstract class AttachmentModelAbstract
{
public static function getOnView(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['select']);
ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy']);
ValidatorModel::intType($aArgs, ['limit']);
$aAttachments = DatabaseModel::select([
'select' => $aArgs['select'],
'table' => ['res_view_attachments'],
'where' => empty($aArgs['where']) ? [] : $aArgs['where'],
'data' => empty($aArgs['data']) ? [] : $aArgs['data'],
'order_by' => empty($aArgs['orderBy']) ? [] : $aArgs['orderBy'],
'limit' => empty($aArgs['limit']) ? 0 : $aArgs['limit']
]);
return $aAttachments;
}
public static function getById(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['id']);
ValidatorModel::intVal($aArgs, ['id']);
ValidatorModel::boolType($aArgs, ['isVersion']);
if (!empty($aArgs['isVersion'])) {
$table = 'res_version_attachments';
} else {
$table = 'res_attachments';
}
$aAttachment = DatabaseModel::select([
'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
'table' => [$table],
'where' => ['res_id = ?'],
'data' => [$aArgs['id']],
]);
if (empty($aAttachment[0])) {
return [];
}
return $aAttachment[0];
}
public static function getListByResIdMaster(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['id']);
ValidatorModel::intVal($aArgs, ['id']);
$aAttachments = DatabaseModel::select([
'select' => empty($aArgs['select']) ? ['res_id', 'res_attachments.identifier', 'title', 'format', 'creation_date', 'doc_date as update_date', 'validation_date as return_date', 'effective_date as real_return_date', 'u.firstname as firstname_updated', 'u.lastname as lastname_updated', 'relation', 'docserver_id', 'path', 'filename', 'fingerprint', 'filesize', 'label_status as status', 'attachment_type', 'dest_contact_id', 'dest_address_id', 'ut.firstname as firstname_typist', 'ut.lastname as lastname_typist'] : $aArgs['select'],
'table' => ['res_attachments','users ut', 'status', 'users u'],
'left_join' => ['res_attachments.typist = ut.user_id', 'res_attachments.status = status.id', 'res_attachments.updated_by = u.user_id'],
'where' => ['res_id_master = ?', 'res_attachments.status not in (?,?)', 'attachment_type not in (?,?)'],
'data' => [$aArgs['id'], 'OBS', 'DEL', 'converted_pdf', 'printed_folder'],
'order_by' => empty($aArgs['orderBy']) ? ['res_id DESC'] : $aArgs['orderBy'],
]);
return $aAttachments;
}
public static function create(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['format', 'typist', 'creation_date', 'docserver_id', 'path', 'filename', 'fingerprint', 'filesize', 'status']);
ValidatorModel::stringType($aArgs, ['format', 'typist', 'creation_date', 'docserver_id', 'path', 'filename', 'fingerprint', 'status']);
ValidatorModel::intVal($aArgs, ['filesize']);
$nextSequenceId = DatabaseModel::getNextSequenceValue(['sequenceId' => 'res_attachment_res_id_seq']);
$aArgs['res_id'] = $nextSequenceId;
DatabaseModel::insert([
'table' => 'res_attachments',
'columnsValues' => $aArgs
]);
return $nextSequenceId;
}
public static function update(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['set', 'where', 'data']);
ValidatorModel::arrayType($aArgs, ['set', 'where', 'data']);
ValidatorModel::boolType($aArgs, ['isVersion']);
if (!empty($aArgs['isVersion'])) {
$table = 'res_version_attachments';
} else {
$table = 'res_attachments';
}
DatabaseModel::update([
'table' => $table,
'set' => $aArgs['set'],
'where' => $aArgs['where'],
'data' => $aArgs['data']
]);
return true;
}
public static function getAttachmentsTypesByXML()
{
$attachmentTypes = [];
$loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/entreprise.xml']);
if ($loadedXml) {
$attachmentTypesXML = $loadedXml->attachment_types;
if (count($attachmentTypesXML) > 0) {
foreach ($attachmentTypesXML->type as $value) {
$label = defined((string) $value->label) ? constant((string) $value->label) : (string) $value->label;
$attachmentTypes[(string) $value->id] = [
'label' => $label,
'icon' => (string)$value['icon'],
'sign' => (empty($value['sign']) || (string)$value['sign'] == 'true') ? true : false
];
}
}
}
return $attachmentTypes;
}
public static function unsignAttachment(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['table', 'resId']);
ValidatorModel::stringType($aArgs, ['table']);
ValidatorModel::intVal($aArgs, ['resId']);
DatabaseModel::update([
'table' => $aArgs['table'],
'set' => ['status' => 'A_TRA', 'signatory_user_serial_id' => null],
'where' => ['res_id = ?'],
'data' => [$aArgs['resId']]
]);
DatabaseModel::update([
'table' => 'res_attachments',
'set' => ['status' => 'DEL'],
'where' => ['origin = ?', 'status != ?'],
'data' => ["{$aArgs['resId']},{$aArgs['table']}", 'DEL']
]);
return true;
}
public static function freezeAttachment(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['table', 'resId', 'externalId']);
ValidatorModel::stringType($aArgs, ['table', 'externalId']);
ValidatorModel::intType($aArgs, ['resId']);
DatabaseModel::update([
'table' => $aArgs['table'],
'set' => ['status' => 'FRZ', 'external_id' => $aArgs['externalId']],
'where' => ['res_id = ?'],
'data' => [$aArgs['resId']]
]);
return true;
}
public static function setInSignatureBook(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['id']);
ValidatorModel::intVal($aArgs, ['id']);
ValidatorModel::boolType($aArgs, ['inSignatureBook', 'isVersion']);
if ($aArgs['isVersion'] == true) {
$table = 'res_version_attachments';
} else {
$table = 'res_attachments';
}
if ($aArgs['inSignatureBook']) {
$aArgs['inSignatureBook'] = 'true';
} else {
$aArgs['inSignatureBook'] = 'false';
}
DatabaseModel::update([
'table' => $table,
'set' => [
'in_signature_book' => $aArgs['inSignatureBook']
],
'where' => ['res_id = ?'],
'data' => [$aArgs['id']],
]);
return true;
}
public static function hasAttachmentsSignedForUserById(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['id', 'user_serial_id', 'isVersion']);
ValidatorModel::intVal($aArgs, ['id', 'user_serial_id']);
ValidatorModel::stringType($aArgs, ['isVersion']);
if ($aArgs['isVersion'] == 'true') {
$table = 'res_version_attachments';
} else {
$table = 'res_attachments';
}
$attachment = DatabaseModel::select([
'select' => ['res_id_master'],
'table' => [$table],
'where' => ['res_id = ?'],
'data' => [$aArgs['id']],
]);
$attachments = DatabaseModel::select([
'select' => ['res_id_master'],
'table' => ['res_view_attachments'],
'where' => ['res_id_master = ?', 'signatory_user_serial_id = ?'],
'data' => [$attachment[0]['res_id_master'], $aArgs['user_serial_id']],
]);
if (empty($attachments)) {
return false;
}
return true;
}
}
<?php
/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.
*
*/
/**
* @brief Convert PDF Controller
* @author dev@maarch.org
*/
namespace Convert\controllers;
use Attachment\models\AttachmentModel;
use Convert\models\AdrModel;
use Docserver\controllers\DocserverController;
use Docserver\models\DocserverModel;
use Resource\models\ResModel;
use SrcCore\models\CoreConfigModel;
use SrcCore\models\ValidatorModel;
class ConvertPdfController
{
public static function tmpConvert(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['fullFilename']);
if (!file_exists($aArgs['fullFilename'])) {
return ['errors' => '[ConvertPdf] Document '.$aArgs['fullFilename'].' does not exist'];
}
$docInfo = pathinfo($aArgs['fullFilename']);
$tmpPath = CoreConfigModel::getTmpPath();
$command = "unoconv -f pdf " . escapeshellarg($aArgs['fullFilename']);
exec('export HOME=' . $tmpPath . ' && '.$command.' 2>&1', $output, $return);
if (!file_exists($tmpPath.$docInfo["filename"].'.pdf')) {
return ['errors' => '[ConvertPdf] Conversion failed ! '. implode(" ", $output)];
} else {
return ['fullFilename' => $tmpPath.$docInfo["filename"].'.pdf'];
}
}
public static function convert(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['collId', 'resId']);
ValidatorModel::stringType($aArgs, ['collId']);
ValidatorModel::intVal($aArgs, ['resId']);
ValidatorModel::boolType($aArgs, ['isVersion']);
if ($aArgs['collId'] == 'letterbox_coll') {
$resource = ResModel::getById(['resId' => $aArgs['resId'], 'select' => ['docserver_id', 'path', 'filename']]);
} else {
$resource = AttachmentModel::getById(['id' => $aArgs['resId'], 'isVersion' => $aArgs['isVersion'], 'select' => ['docserver_id', 'path', 'filename']]);
}
if (empty($resource)) {
return ['errors' => '[ConvertPdf] Resource does not exist'];
}
$docserver = DocserverModel::getByDocserverId(['docserverId' => $resource['docserver_id'], 'select' => ['path_template']]);
if (empty($docserver['path_template']) || !file_exists($docserver['path_template'])) {
return ['errors' => '[ConvertPdf] Docserver does not exist'];
}
$pathToDocument = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $resource['path']) . $resource['filename'];
if (!file_exists($pathToDocument)) {
return ['errors' => '[ConvertPdf] Document does not exist on docserver'];
}
$docInfo = pathinfo($pathToDocument);
$tmpPath = CoreConfigModel::getTmpPath();
$fileNameOnTmp = rand() . $docInfo["filename"];
copy($pathToDocument, $tmpPath.$fileNameOnTmp.'.'.$docInfo["extension"]);
$command = "unoconv -f pdf " . escapeshellarg($tmpPath.$fileNameOnTmp.'.'.$docInfo["extension"]);
exec('export HOME=' . $tmpPath . ' && '.$command, $output, $return);
if (!file_exists($tmpPath.$fileNameOnTmp.'.pdf')) {
return ['errors' => '[ConvertPdf] Conversion failed ! '. implode(" ", $output)];
}
$storeResult = DocserverController::storeResourceOnDocServer([
'collId' => $aArgs['collId'],
'fileInfos' => [
'tmpDir' => $tmpPath,
'tmpFileName' => $fileNameOnTmp . '.pdf',
],
'docserverTypeId' => 'CONVERT'
]);
if (!empty($storeResult['errors'])) {
return ['errors' => "[ConvertPdf] {$storeResult['errors']}"];
}
if ($aArgs['collId'] == 'letterbox_coll') {
AdrModel::createDocumentAdr([
'resId' => $aArgs['resId'],
'type' => 'PDF',
'docserverId' => $storeResult['docserver_id'],
'path' => $storeResult['destination_dir'],
'filename' => $storeResult['file_destination_name'],
]);
} else {
AdrModel::createAttachAdr([
'resId' => $aArgs['resId'],
'isVersion' => $aArgs['isVersion'],
'type' => 'PDF',
'docserverId' => $storeResult['docserver_id'],
'path' => $storeResult['destination_dir'],
'filename' => $storeResult['file_destination_name'],
]);
}
return ['docserver_id' => $storeResult['docserver_id'], 'path' => $storeResult['destination_dir'], 'filename' => $storeResult['file_destination_name']];
}
public static function getConvertedPdfById(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['resId', 'collId']);
ValidatorModel::intVal($aArgs, ['resId']);
ValidatorModel::boolType($aArgs, ['isVersion']);
ValidatorModel::arrayType($aArgs, ['select']);
$convertedDocument = AdrModel::getConvertedDocumentById([
'select' => ['docserver_id','path', 'filename'],
'resId' => $aArgs['resId'],
'collId' => $aArgs['collId'],
'type' => 'PDF',
'isVersion' => $aArgs['isVersion']
]);
if (empty($convertedDocument)) {
$convertedDocument = ConvertPdfController::convert([
'resId' => $aArgs['resId'],
'collId' => $aArgs['collId'],
'isVersion' => $aArgs['isVersion'],
]);
}
return $convertedDocument;
}
}
<?php
/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.
*
*/
/**
* @brief Convert Thumbnail Controller
* @author dev@maarch.org
*/
namespace Convert\controllers;
use Attachment\models\AttachmentModel;
use Convert\models\AdrModel;
use Docserver\controllers\DocserverController;
use Docserver\models\DocserverModel;
use Parameter\models\ParameterModel;
use Resource\models\ResModel;
use SrcCore\models\CoreConfigModel;
use SrcCore\models\ValidatorModel;
class ConvertThumbnailController
{
public static function convert(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['collId', 'resId']);
ValidatorModel::stringType($aArgs, ['collId']);
ValidatorModel::intVal($aArgs, ['resId', 'outgoingId']);
ValidatorModel::boolType($aArgs, ['isOutgoingVersion','isVersion']);
if ($aArgs['collId'] == 'letterbox_coll') {
if (empty($aArgs['outgoingId'])) {
$resource = ResModel::getById(['resId' => $aArgs['resId'], 'select' => ['docserver_id', 'path', 'filename']]);
$convertedDocument = AdrModel::getConvertedDocumentById([
'select' => ['docserver_id','path', 'filename'],
'resId' => $aArgs['resId'],
'collId' => $aArgs['collId'],
'type' => 'PDF',
'isVersion' => false
]);
} else {
$resource = AttachmentModel::getById(['id' => $aArgs['outgoingId'], 'isVersion' => $aArgs['isOutgoingVersion'], 'select' => ['docserver_id', 'path', 'filename']]);
$convertedDocument = AdrModel::getConvertedDocumentById([
'select' => ['docserver_id','path', 'filename'],
'resId' => $aArgs['outgoingId'],
'collId' => 'attachments_coll',
'type' => 'PDF',
'isVersion' => $aArgs['isOutgoingVersion']
]);
}
} else {
$resource = AttachmentModel::getById(['id' => $aArgs['resId'], 'isVersion' => $aArgs['isVersion'], 'select' => ['docserver_id', 'path', 'filename']]);
$convertedDocument = AdrModel::getConvertedDocumentById([
'select' => ['docserver_id','path', 'filename'],
'resId' => $aArgs['resId'],
'collId' => $aArgs['collId'],
'type' => 'PDF',
'isVersion' => $aArgs['isVersion']
]);
}
if (empty($resource)) {
return ['errors' => '[ConvertThumbnail] Resource does not exist'];
}
if (empty($convertedDocument)) {
$docserver = DocserverModel::getByDocserverId(['docserverId' => $resource['docserver_id'], 'select' => ['path_template']]);
if (empty($docserver['path_template']) || !file_exists($docserver['path_template'])) {
return ['errors' => '[ConvertThumbnail] Docserver does not exist'];
}
$pathToDocument = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $resource['path']) . $resource['filename'];
if (!file_exists($pathToDocument)) {
return ['errors' => '[ConvertThumbnail] Document does not exist on docserver'];
}
} else {
$docserver = DocserverModel::getByDocserverId(['docserverId' => $convertedDocument['docserver_id'], 'select' => ['path_template']]);
$pathToDocument = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $convertedDocument['path']) . $convertedDocument['filename'];
if (!file_exists($pathToDocument)) {
return ['errors' => '[ConvertThumbnail] Document does not exist on docserver'];
}
}
$ext = pathinfo($pathToDocument, PATHINFO_EXTENSION);
$filename = pathinfo($pathToDocument, PATHINFO_FILENAME);
$tmpPath = CoreConfigModel::getTmpPath();
$fileNameOnTmp = rand() . $filename;
if (in_array($ext, ['maarch', 'html'])) {
if ($ext == 'maarch') {
copy($pathToDocument, "{$tmpPath}{$fileNameOnTmp}.html");
$pathToDocument = "{$tmpPath}{$fileNameOnTmp}.html";
}
$command = "wkhtmltoimage --height 600 --width 400 --quality 100 --zoom 0.2 "
. escapeshellarg($pathToDocument) . ' ' . escapeshellarg("{$tmpPath}{$fileNameOnTmp}.png");
} else {
$size = '750x900';
$parameter = ParameterModel::getById(['id' => 'thumbnailsSize', 'select' => ['param_value_string']]);
if (!empty($parameter) && preg_match('/^[0-9]{3,4}[x][0-9]{3,4}$/', $parameter['param_value_string'])) {
$size = $parameter['param_value_string'];
}
$command = "convert -thumbnail {$size} -background white -alpha remove "
. escapeshellarg($pathToDocument) . '[0] ' . escapeshellarg("{$tmpPath}{$fileNameOnTmp}.png");
}
exec($command.' 2>&1', $output, $return);
if ($return !== 0) {
return ['errors' => "[ConvertThumbnail] ".implode(" ", $output)];
}
$storeResult = DocserverController::storeResourceOnDocServer([
'collId' => $aArgs['collId'],
'fileInfos' => [
'tmpDir' => $tmpPath,
'tmpFileName' => $fileNameOnTmp . '.png',
],
'docserverTypeId' => 'TNL'
]);
if (!empty($storeResult['errors'])) {
return ['errors' => "[ConvertThumbnail] {$storeResult['errors']}"];
}
if ($aArgs['collId'] == 'letterbox_coll') {
AdrModel::createDocumentAdr([
'resId' => $aArgs['resId'],
'type' => 'TNL',
'docserverId' => $storeResult['docserver_id'],
'path' => $storeResult['destination_dir'],
'filename' => $storeResult['file_destination_name'],
]);
} else {
AdrModel::createAttachAdr([
'resId' => $aArgs['resId'],
'type' => 'TNL',
'docserverId' => $storeResult['docserver_id'],
'path' => $storeResult['destination_dir'],
'filename' => $storeResult['file_destination_name'],
'isVersion' => $aArgs['isVersion'],
]);
}
return true;
}
}
......@@ -61,4 +61,18 @@ class AdrModel
return $addresses;
}
public static function getAttachmentsAdr(array $aArgs)
{
ValidatorModel::arrayType($aArgs, ['select', 'where', 'data']);
$addresses = DatabaseModel::select([
'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
'table' => ['adr_attachments'],
'where' => empty($aArgs['where']) ? [] : $aArgs['where'],
'data' => empty($aArgs['data']) ? [] : $aArgs['data'],
]);
return $addresses;
}
}
......@@ -14,6 +14,7 @@
namespace Document\controllers;
use Attachment\models\AttachmentModel;
use Convert\models\AdrModel;
use Docserver\models\DocserverModel;
use Document\models\DocumentModel;
......@@ -62,8 +63,7 @@ class DocumentController
$document['statusDisplay'] = $status['label'];
$document['processingUserDisplay'] = UserModel::getLabelledUserById(['id' => $document['processing_user']]);
$documentAdr = AdrModel::getDocumentsAdr([
$adr = AdrModel::getDocumentsAdr([
'select' => ['path', 'filename'],
'where' => ['main_document_id = ?', 'type = ?'],
'data' => [$args['id'], 'DOC']
......@@ -74,12 +74,13 @@ class DocumentController
return $response->withStatus(400)->withJson(['errors' => 'Docserver does not exist']);
}
$pathToDocument = $docserver['path'] . $documentAdr[0]['path'] . $documentAdr[0]['filename'];
$pathToDocument = $docserver['path'] . $adr[0]['path'] . $adr[0]['filename'];
if (!file_exists($pathToDocument)) {
return $response->withStatus(404)->withJson(['errors' => 'Document not found on docserver']);
}
$document['document'] = base64_encode(file_get_contents($pathToDocument));
$document['attachments'] = AttachmentModel::getByDocumentId(['select' => ['id'], 'documentId' => $args['id']]);
return $response->withJson(['document' => $document]);
}
......
This diff is collapsed.
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