diff --git a/src/app/document/controllers/DocumentController.php b/src/app/document/controllers/DocumentController.php index 88403c0a8cfbcfb742f505a2545b0ab429382810..11fd0770f6247eee6719e9cb8926bdc1f6d86b9b 100755 --- a/src/app/document/controllers/DocumentController.php +++ b/src/app/document/controllers/DocumentController.php @@ -302,10 +302,10 @@ class DocumentController } if($queryParams['physicalPurge']) { - $documentTypes = ['ORIGINAL', 'DOC']; + $documentTypes = ['ORIGINAL', 'DOC', 'ATTACH', 'TNL1']; $filePaths = AdrModel::getDocumentsAdr([ - 'select'=> ['id', 'type', 'CONCAT(path, filename) as path'], + 'select'=> ['CONCAT(path, filename) as path'], 'where' => ['main_document_id = ?', 'type IN (?)'], 'data' => [$args['id'], $documentTypes] ]); @@ -313,6 +313,21 @@ class DocumentController return $response->withStatus(500)->withJson(['errors' => 'No documents found on Docserver']); } + $attachments = AttachmentModel::get([ + 'select'=> ['id'], + 'where' => ['main_document_id = ?'], + 'data' => [$args['id']] + ]); + + if (!empty($attachments)) { + $attachmentFilePaths = AdrModel::getAttachmentsAdr([ + 'select'=> ['CONCAT(path, filename) as path'], + 'where' => ['attachment_id IN (?)', 'type IN (?)'], + 'data' => [array_column($attachments, 'id'), $documentTypes] + ]); + $filePaths = array_merge($filePaths, $attachmentFilePaths); + } + $docServers = DocserverModel::getByTypes(['types' => $documentTypes, 'select' => ['path']]); if (empty($docServers)) { return $response->withStatus(500)->withJson(['errors' => 'No available Docserver']); @@ -334,6 +349,17 @@ class DocumentController } } } + + if (!empty($attachments)) { + AdrModel::deleteAttachmentAdr([ + 'where' => ['attachment_id IN (?)'], + 'data' => [array_column($attachments, 'id')] + ]); + } + AdrModel::deleteDocumentAdr([ + 'where' => ['main_document_id = ?'], + 'data' => [$args['id']] + ]); DocumentModel::update([ 'set' => ['status' => 'HARD_DEL'], 'where' => ['id = ?'],