diff --git a/CHANGELOG.md b/CHANGELOG.md index dde0736910d5e976248fa6d1975f0f17be8c127b..bd67f07e51803fca583b785f1b74c13812fe8cd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ # CHANGELOG +## Version 2.6.2 + +- `Added` Possibiliter de récupérer un lien de téléchargement à la place du contenu binaire dans les réponses à l'appel web service de consultation + ## Version 2.6.1 - `Fixed` Suppression du fichier temporaire lors de la validation de la ressource diff --git a/MIGRATION.md b/MIGRATION.md index 8b60e70890de12b1698e3b24bec77cd96408e754..a8b30f6d0e8dbb88b23d9cebb7858eed44fa5e6a 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -1,4 +1,12 @@ # Migration 2.5 vers 2.6 +## Configuration +### Lien de téléchargement d'une ressource +Cette configuration facultative permet au moment de la consultation, de recevoir une uri vers une ressource au lieu du contenu binaire. + +À renseigner dans [recordsManagement] : +``` +exportPath = "%laabsDirectory%/web/tmp" +``` ## Configuration des instances publiées (hôte(s) virtuel(s) http et scripts en ligne de commande) diff --git a/VERSION.md b/VERSION.md index 6a6a3d8e35c7a98eaeb47d4212cc13d1d8938003..d5724cd41b6aa69cc4040994487301a4f25bd78a 100644 --- a/VERSION.md +++ b/VERSION.md @@ -1 +1 @@ -2.6.1 +2.6.2 \ No newline at end of file diff --git a/core/Response/AbstractResponse.php b/core/Response/AbstractResponse.php index fb418cd6e768a1ac8a0d69ed3f7f7343fd295948..1933feed967c18a53bc892188bad51bf84182682 100755 --- a/core/Response/AbstractResponse.php +++ b/core/Response/AbstractResponse.php @@ -70,7 +70,12 @@ abstract class AbstractResponse public function send() { - echo $this->body . PHP_EOL; + if (is_scalar($this->body)) { + echo $this->body. PHP_EOL; + } elseif (is_resource($this->body)) { + $output = fopen('php://output', 'w+'); + stream_copy_to_stream($this->body, $output); + echo PHP_EOL; + } } - } \ No newline at end of file diff --git a/core/Response/BatchResponse.php b/core/Response/BatchResponse.php index ccd50a427bc5f95a6d459b835c25cb70c5c10f11..30ea4004e74a08c0e4b60457c3b3668c48026bd1 100755 --- a/core/Response/BatchResponse.php +++ b/core/Response/BatchResponse.php @@ -25,7 +25,12 @@ class BatchResponse public function send() { - echo $this->body; + if (is_scalar($this->body)) { + echo $this->body. PHP_EOL; + } elseif (is_resource($this->body)) { + $output = fopen('php://output', 'w+'); + stream_copy_to_stream($this->body, $output); + echo PHP_EOL; + } } - } \ No newline at end of file diff --git a/data/maarchRM/conf/configuration.ini.default b/data/maarchRM/conf/configuration.ini.default index 37e1c35bd03693612a66de2ef94f68713a8c3e26..511037833350f12b1b6a6b59f059e5798407e52c 100755 --- a/data/maarchRM/conf/configuration.ini.default +++ b/data/maarchRM/conf/configuration.ini.default @@ -116,6 +116,9 @@ descriptionSchemes = "{ } }" +; The path of resource export folder +exportPath = "%laabsDirectory%/web/tmp" + [audit] ; Send notifications on audit event ;notifications = "{ diff --git a/src/bundle/recordsManagement/Controller/archiveAccessTrait.php b/src/bundle/recordsManagement/Controller/archiveAccessTrait.php index 086c1de2db5d0c99a85fe63e4c0dc2385e8cbf85..002028f3795a9977c2ef0f0bddf7f55a1d3d512d 100755 --- a/src/bundle/recordsManagement/Controller/archiveAccessTrait.php +++ b/src/bundle/recordsManagement/Controller/archiveAccessTrait.php @@ -511,10 +511,11 @@ trait archiveAccessTrait * @param string $archiveId The archive identifier * @param string $resId The resource identifier * @param bool $checkAccess Check access for originator or archiver. if false, caller MUST control access before or after + * @param bool $embedded Generate a binary content or a link * * @return digitalResource/digitalResource Archive resource contents */ - public function consultation($archiveId, $resId, $checkAccess = true, $isCommunication = false) + public function consultation($archiveId, $resId, $checkAccess = true, $isCommunication = false, $embedded = true) { $accountController = \laabs::newController('auth/userAccount'); $accountController->isAuthorized('user'); @@ -553,18 +554,21 @@ trait archiveAccessTrait $binaryDataObject = \laabs::newInstance("recordsManagement/BinaryDataObject"); $binaryDataObject->attachment = new \stdClass(); + $binaryDataObject->attachment->uri = ""; + $binaryDataObject->attachment->filename = $digitalResource->fileName; if (\laabs::isServiceClient()) { // Returns base64 encoded contents for web service clients - $binaryDataObject->attachment->data = \core\Encoding\Base64::encode($digitalResource->getHandler()); + if ($embedded === false || $embedded === 'false') { + $binaryDataObject->attachment->uri = $this->createPublicResource($digitalResource->getHandler()); + } else { + $binaryDataObject->attachment->data = \core\Encoding\Base64::encode($digitalResource->getHandler()); + } } else { // Let presenter stream the contents $binaryDataObject->attachment->data = $digitalResource->getHandler(); } - $binaryDataObject->attachment->uri = ""; - $binaryDataObject->attachment->filename = $digitalResource->fileName; - if (!empty($digitalResource->fileExtension)) { $digitalResource->fileName = $digitalResource->fileName . $digitalResource->fileExtension; } @@ -1275,4 +1279,33 @@ trait archiveAccessTrait return $archive; } + + /** + * Create public resource + * @param $content The content of resource + * + * @return string $uri The uri of resource + */ + private function createPublicResource($content) { + if (is_scalar($content)) { + $uid = hash('md5', $content); + } else { + $uid = \laabs\uniqid(); + } + + if (isset(\laabs::configuration("recordsManagement")["exportPath"])) { + $dir = \laabs::configuration("recordsManagement")["exportPath"]; + } else { + $dir = "..".DIRECTORY_SEPARATOR.LAABS_WEB.DIRECTORY_SEPARATOR.LAABS_TMP; + } + + $pathUri = str_replace(DIRECTORY_SEPARATOR, LAABS_URI_SEPARATOR, $dir); + $uri = $pathUri.LAABS_URI_SEPARATOR.$uid; + + $fp = fopen($uri, 'w'); + stream_copy_to_stream($content, $fp); + fclose($fp); + + return $uri; + } } diff --git a/src/bundle/recordsManagement/archiveInterface.php b/src/bundle/recordsManagement/archiveInterface.php index 35add5d6e1d3f74c3dcb3304ab81edc555ce76ac..4c9f6b555fedf6b182e0e0886ebd67f6af7a8dd9 100755 --- a/src/bundle/recordsManagement/archiveInterface.php +++ b/src/bundle/recordsManagement/archiveInterface.php @@ -95,7 +95,7 @@ interface archiveInterface * * @action recordsManagement/archive/consultation */ - public function readConsultation_archiveId_Digitalresource_resId_($isCommunication = false); + public function readConsultation_archiveId_Digitalresource_resId_($isCommunication = false, $embedded = true); /** * Retrieve an archive by its id