diff --git a/migration/21.04/2104.sql b/migration/21.04/2104.sql index e23016251dc981cc9c2ef86e798e5c29cc45e370..c59f7502adf7f5b9d4c13093b13d1ab0c85280c7 100644 --- a/migration/21.04/2104.sql +++ b/migration/21.04/2104.sql @@ -20,6 +20,7 @@ CREATE TABLE attachment_types chrono BOOLEAN NOT NULL, version_enabled BOOLEAN NOT NULL, new_version_default BOOLEAN NOT NULL, - CONSTRAINT attachment_types_pkey PRIMARY KEY (id) + CONSTRAINT attachment_types_pkey PRIMARY KEY (id), + CONSTRAINT attachment_types_unique_key UNIQUE (type_id) ) WITH (OIDS=FALSE); diff --git a/sql/structure.sql b/sql/structure.sql index ad8039d6a9495454f79b59bac390936d020dec68..74ccdb47e9d4daa488bb525609ee764cb1b64171 100755 --- a/sql/structure.sql +++ b/sql/structure.sql @@ -1505,6 +1505,7 @@ CREATE TABLE attachment_types chrono BOOLEAN NOT NULL, version_enabled BOOLEAN NOT NULL, new_version_default BOOLEAN NOT NULL, - CONSTRAINT attachment_types_pkey PRIMARY KEY (id) + CONSTRAINT attachment_types_pkey PRIMARY KEY (id), + CONSTRAINT attachment_types_unique_key UNIQUE (type_id) ) WITH (OIDS=FALSE); diff --git a/src/app/attachment/models/AttachmentTypeModel.php b/src/app/attachment/models/AttachmentTypeModel.php index 34bb8587ddad98f52256acbac723b1eb6c49b4f4..9706086e0e63a2e5f84f940f4b19eeca354ba1d2 100644 --- a/src/app/attachment/models/AttachmentTypeModel.php +++ b/src/app/attachment/models/AttachmentTypeModel.php @@ -58,6 +58,26 @@ class AttachmentTypeModel return $type[0]; } + public static function getByTypeId(array $args) + { + ValidatorModel::notEmpty($args, ['typeId']); + ValidatorModel::stringType($args, ['typeId']); + ValidatorModel::arrayType($args, ['select']); + + $type = DatabaseModel::select([ + 'select' => empty($args['select']) ? ['*'] : $args['select'], + 'table' => ['attachment_types'], + 'where' => ['type_id = ?'], + 'data' => [$args['typeId']], + ]); + + if (empty($type[0])) { + return []; + } + + return $type[0]; + } + public static function create(array $args) { ValidatorModel::notEmpty($args, ['type_id', 'label', 'visible', 'email_link', 'signable', 'version_enabled', 'new_version_default', 'chrono']); diff --git a/src/app/external/alfresco/controllers/AlfrescoController.php b/src/app/external/alfresco/controllers/AlfrescoController.php index e79ee9bd89e2dccc9260408f307b260f33a936cb..ff833e09cc73dbe03e7e0fa87bb8b8c89e802192 100644 --- a/src/app/external/alfresco/controllers/AlfrescoController.php +++ b/src/app/external/alfresco/controllers/AlfrescoController.php @@ -795,9 +795,8 @@ class AlfrescoController if (!empty($alfrescoParameters['mapping']['attachment'])) { foreach ($alfrescoParameters['mapping']['attachment'] as $key => $alfrescoParameter) { if ($alfrescoParameter == 'typeLabel') { - $attachmentsTypes = AttachmentTypeModel::get(['select' => ['type_id', 'label']]); - $attachmentsTypes = array_column($attachmentsTypes, 'label', 'type_id'); - $properties[$key] = $attachmentsTypes[$attachment['attachment_type']]; + $attachmentType = AttachmentTypeModel::getByTypeId(['select' => ['label'], 'typeId' => $attachment['attachment_type']]); + $properties[$key] = $attachmentType['label'] ?? ''; } else { $properties[$key] = $attachment[$alfrescoParameter]; }