-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #728 from Pixilib/new-export
Dissociate export study and export study-files api and make export database works as stream
- Loading branch information
Showing
23 changed files
with
1,073 additions
and
923 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ on: | |
branches: | ||
- GaelO2 | ||
- GaelO2-dev | ||
- new-export | ||
tags: | ||
- '*' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace App\GaelO\Adapters; | ||
|
||
use App\GaelO\Interfaces\Adapters\ZipStreamInterface; | ||
use Psr\Http\Message\StreamInterface; | ||
use ZipStream; | ||
|
||
class ZipStreamAdapter implements ZipStreamInterface | ||
{ | ||
|
||
private ZipStream\ZipStream $zipStream; | ||
|
||
public function init(string $filename): void | ||
{ | ||
$this->zipStream = new ZipStream\ZipStream( | ||
outputName: $filename, | ||
sendHttpHeaders: true, | ||
); | ||
} | ||
|
||
public function addFileFromString(string $filename, string $content): void | ||
{ | ||
$this->zipStream->addFile( | ||
fileName: $filename, | ||
data: $content, | ||
); | ||
} | ||
|
||
public function addFileFromStream(string $filename, $stream): void | ||
{ | ||
$this->zipStream->addFileFromStream( | ||
fileName: $filename, | ||
stream: $stream, | ||
); | ||
} | ||
|
||
public function finish() | ||
{ | ||
return $this->zipStream->finish(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
GaelO2/app/GaelO/Interfaces/Adapters/ZipStreamInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace App\GaelO\Interfaces\Adapters; | ||
|
||
use Psr\Http\Message\StreamInterface; | ||
|
||
Interface ZipStreamInterface { | ||
public function init(string $filename): void; | ||
public function addFileFromString(string $filename, string $content): void; | ||
public function addFileFromStream(string $filename, $stream) :void; | ||
public function finish(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
GaelO2/app/GaelO/UseCases/ExportStudyFiles/ExportStudyFiles.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace App\GaelO\UseCases\ExportStudyFiles; | ||
|
||
use App\GaelO\Constants\Constants; | ||
use App\GaelO\Exceptions\AbstractGaelOException; | ||
use App\GaelO\Exceptions\GaelOForbiddenException; | ||
use App\GaelO\Services\AuthorizationService\AuthorizationStudyService; | ||
use App\GaelO\Util; | ||
use Exception; | ||
|
||
class ExportStudyFiles | ||
{ | ||
|
||
private AuthorizationStudyService $authorizationStudyService; | ||
private string $studyName; | ||
|
||
public function __construct(AuthorizationStudyService $authorizationStudyService) | ||
{ | ||
$this->authorizationStudyService = $authorizationStudyService; | ||
} | ||
|
||
public function execute(ExportStudyFilesRequest $exportStudyFilesRequest, ExportStudyFilesResponse $exportStudyFilesResponse) | ||
{ | ||
|
||
try { | ||
|
||
#increase memory limit as php zip stores metadata file in memory until final generation of zip | ||
$studyName = $exportStudyFilesRequest->studyName; | ||
|
||
$this->checkAuthorization($exportStudyFilesRequest->currentUserId, $studyName); | ||
|
||
$this->studyName = $studyName; | ||
|
||
//Operation might be long, set max execution time to 30 minutes | ||
set_time_limit(1800); | ||
|
||
$exportStudyFilesResponse->status = 200; | ||
$exportStudyFilesResponse->statusText = 'OK'; | ||
$exportStudyFilesResponse->fileName = "export_files_" . $studyName . ".zip"; | ||
} catch (AbstractGaelOException $e) { | ||
$exportStudyFilesResponse->status = $e->statusCode; | ||
$exportStudyFilesResponse->statusText = $e->statusText; | ||
} catch (Exception $e) { | ||
throw $e; | ||
} | ||
} | ||
|
||
private function checkAuthorization(int $currentUserId, string $studyName) | ||
{ | ||
|
||
$this->authorizationStudyService->setStudyName($studyName); | ||
$this->authorizationStudyService->setUserId($currentUserId); | ||
if (!$this->authorizationStudyService->isAllowedStudy(Constants::ROLE_SUPERVISOR)) { | ||
throw new GaelOForbiddenException(); | ||
} | ||
} | ||
|
||
public function readExport(){ | ||
Util::exportAssociatedFiles($this->studyName); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
GaelO2/app/GaelO/UseCases/ExportStudyFiles/ExportStudyFilesRequest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace App\GaelO\UseCases\ExportStudyFiles; | ||
|
||
class ExportStudyFilesRequest | ||
{ | ||
public int $currentUserId; | ||
public string $studyName; | ||
} |
13 changes: 13 additions & 0 deletions
13
GaelO2/app/GaelO/UseCases/ExportStudyFiles/ExportStudyFilesResponse.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace App\GaelO\UseCases\ExportStudyFiles; | ||
|
||
use Psr\Http\Message\StreamInterface; | ||
|
||
class ExportStudyFilesResponse | ||
{ | ||
public int $status; | ||
public string $statusText; | ||
public StreamInterface $stream; | ||
public string $fileName; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.