Commit e8006135 authored by Alexandre Morin's avatar Alexandre Morin
Browse files

Merge branch 'hotfix/2.6.2' into 'master'

Hotfix/2.6.2

See merge request !454
parents ec6d863e bfc3ef32
Pipeline #7393 failed with stages
# CHANGELOG # 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 ## Version 2.6.1
- `Fixed` Suppression du fichier temporaire lors de la validation de la ressource - `Fixed` Suppression du fichier temporaire lors de la validation de la ressource
......
# Migration 2.5 vers 2.6 # 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) ## Configuration des instances publiées (hôte(s) virtuel(s) http et scripts en ligne de commande)
......
2.6.1 2.6.2
\ No newline at end of file
...@@ -70,7 +70,12 @@ abstract class AbstractResponse ...@@ -70,7 +70,12 @@ abstract class AbstractResponse
public function send() 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
...@@ -25,7 +25,12 @@ class BatchResponse ...@@ -25,7 +25,12 @@ class BatchResponse
public function send() 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
...@@ -116,6 +116,9 @@ descriptionSchemes = "{ ...@@ -116,6 +116,9 @@ descriptionSchemes = "{
} }
}" }"
; The path of resource export folder
exportPath = "%laabsDirectory%/web/tmp"
[audit] [audit]
; Send notifications on audit event ; Send notifications on audit event
;notifications = "{ ;notifications = "{
......
...@@ -511,10 +511,11 @@ trait archiveAccessTrait ...@@ -511,10 +511,11 @@ trait archiveAccessTrait
* @param string $archiveId The archive identifier * @param string $archiveId The archive identifier
* @param string $resId The resource 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 $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 * @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 = \laabs::newController('auth/userAccount');
$accountController->isAuthorized('user'); $accountController->isAuthorized('user');
...@@ -553,18 +554,21 @@ trait archiveAccessTrait ...@@ -553,18 +554,21 @@ trait archiveAccessTrait
$binaryDataObject = \laabs::newInstance("recordsManagement/BinaryDataObject"); $binaryDataObject = \laabs::newInstance("recordsManagement/BinaryDataObject");
$binaryDataObject->attachment = new \stdClass(); $binaryDataObject->attachment = new \stdClass();
$binaryDataObject->attachment->uri = "";
$binaryDataObject->attachment->filename = $digitalResource->fileName;
if (\laabs::isServiceClient()) { if (\laabs::isServiceClient()) {
// Returns base64 encoded contents for web service clients // 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 { } else {
// Let presenter stream the contents // Let presenter stream the contents
$binaryDataObject->attachment->data = $digitalResource->getHandler(); $binaryDataObject->attachment->data = $digitalResource->getHandler();
} }
$binaryDataObject->attachment->uri = "";
$binaryDataObject->attachment->filename = $digitalResource->fileName;
if (!empty($digitalResource->fileExtension)) { if (!empty($digitalResource->fileExtension)) {
$digitalResource->fileName = $digitalResource->fileName . $digitalResource->fileExtension; $digitalResource->fileName = $digitalResource->fileName . $digitalResource->fileExtension;
} }
...@@ -1275,4 +1279,33 @@ trait archiveAccessTrait ...@@ -1275,4 +1279,33 @@ trait archiveAccessTrait
return $archive; 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;
}
} }
...@@ -95,7 +95,7 @@ interface archiveInterface ...@@ -95,7 +95,7 @@ interface archiveInterface
* *
* @action recordsManagement/archive/consultation * @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 * Retrieve an archive by its id
......
Supports Markdown
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