Skip to content
Snippets Groups Projects
Commit ca4e40dd authored by Jean-Laurent DUZANT's avatar Jean-Laurent DUZANT
Browse files

FEAT #17671 TIME 1:00 remove files physically if physicalPurge is true

parent f30982ed
No related branches found
No related tags found
No related merge requests found
...@@ -38,6 +38,25 @@ class DocserverModel ...@@ -38,6 +38,25 @@ class DocserverModel
return $aDocserver[0]; return $aDocserver[0];
} }
public static function getByTypes(array $args)
{
ValidatorModel::notEmpty($args, ['types']);
ValidatorModel::arrayType($args, ['types']);
ValidatorModel::arrayType($args, ['select']);
$docServers = DatabaseModel::select([
'select' => empty($args['select']) ? ['*'] : $args['select'],
'table' => ['docservers'],
'where' => ['type IN (?)'],
'data' => [$args['types']]
]);
if (empty($docServers)) {
return [];
}
return $docServers;
}
public static function update(array $aArgs) public static function update(array $aArgs)
{ {
ValidatorModel::notEmpty($aArgs, ['set', 'where', 'data']); ValidatorModel::notEmpty($aArgs, ['set', 'where', 'data']);
......
...@@ -276,6 +276,8 @@ class DocumentController ...@@ -276,6 +276,8 @@ class DocumentController
return $response->withStatus(403)->withJson(['errors' => 'Privilege forbidden']); return $response->withStatus(403)->withJson(['errors' => 'Privilege forbidden']);
} }
$queryParams = $request->getQueryParams();
$lastStep = WorkflowModel::get([ $lastStep = WorkflowModel::get([
'select' => ['process_date'], 'select' => ['process_date'],
'where' => ['main_document_id = ?'], 'where' => ['main_document_id = ?'],
...@@ -294,6 +296,41 @@ class DocumentController ...@@ -294,6 +296,41 @@ class DocumentController
return $response->withStatus(500)->withJson(['errors' => 'No document associated with this workflow']); return $response->withStatus(500)->withJson(['errors' => 'No document associated with this workflow']);
} }
if(!empty($queryParams['physicalPurge'])) {
$documentTypes = ['ORIGINAL', 'DOC'];
$filePaths = AdrModel::getDocumentsAdr([
'select'=> ['id', 'type', 'CONCAT(path, filename) as path'],
'where' => ['main_document_id = ?', 'type IN (?)'],
'data' => [$args['id'], $documentTypes]
]);
if (empty($filePaths)) {
return $response->withStatus(500)->withJson(['errors' => 'No documents found on Docserver']);
}
$docServers = DocserverModel::getByTypes(['types' => $documentTypes, 'select' => ['path']]);
if (empty($docServers)) {
return $response->withStatus(500)->withJson(['errors' => 'No available Docserver']);
}
foreach ($docServers as $key => $docserver) {
foreach ($filePaths as $filePath) {
if ($docserver['type'] == $filePath['type']) {
$docFilePath = "{$docserver['path']}{$filePath['path']}";
if (file_exists("$docFilePath")) {
AdrModel::deleteDocumentAdr([
'where' => ['id = ?'],
'data' => [$filePath['id']]
]);
unlink($docFilePath);
}
}
}
}
}
DocumentModel::update([ DocumentModel::update([
'set' => ['status' => 'DELETED'], 'set' => ['status' => 'DELETED'],
'where' => ['id = ?'], 'where' => ['id = ?'],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment