From 761fe3548fb1e0fef67b11169dae86988e93025d Mon Sep 17 00:00:00 2001 From: Wade Womersley <155439365+wadedvsa@users.noreply.github.com> Date: Mon, 22 Apr 2024 10:42:22 +0100 Subject: [PATCH] fix: Prevent previously uploaded evidence from being deleted (#133) --- .../Lva/AbstractUploadEvidenceController.php | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/module/Olcs/src/Controller/Lva/AbstractUploadEvidenceController.php b/module/Olcs/src/Controller/Lva/AbstractUploadEvidenceController.php index b204f2fd5..e223e5117 100644 --- a/module/Olcs/src/Controller/Lva/AbstractUploadEvidenceController.php +++ b/module/Olcs/src/Controller/Lva/AbstractUploadEvidenceController.php @@ -8,6 +8,8 @@ use Common\RefData; use Common\Service\Helper\FileUploadHelperService; use Common\Service\Helper\FormHelperService; +use DateTimeImmutable; +use DateTimeInterface; use Dvsa\Olcs\Transfer\Query\Application\UploadEvidence; use Dvsa\Olcs\Utils\Translation\NiTextTranslation; use Olcs\Controller\Lva\Traits\ApplicationControllerTrait; @@ -36,6 +38,7 @@ abstract class AbstractUploadEvidenceController extends AbstractController */ private $application; protected FileUploadHelperService $uploadHelper; + protected string $startTime; /** * @param NiTextTranslation $niTextTranslationUtil @@ -50,6 +53,7 @@ public function __construct( FileUploadHelperService $uploadHelper ) { $this->uploadHelper = $uploadHelper; + $this->startTime = (new DateTimeImmutable())->format(DateTimeInterface::ATOM); parent::__construct( $niTextTranslationUtil, @@ -66,6 +70,7 @@ public function __construct( public function indexAction() { $form = $this->getForm(); + $form->get('correlationId')->setValue($this->startTime); $request = $this->getRequest(); if ($request->isPost() && $request->getPost('saveAndContinue') !== null) { @@ -162,11 +167,14 @@ private function getForm() */ public function operatingCentreLoadFileUpload() { + $startDateTime = new DateTimeImmutable($this->getRequest()->getPost('correlationId', $this->startTime)); $data = $this->getData(); foreach ($data['operatingCentres'] as $aocData) { if ($aocData['operatingCentre']['id'] === $this->operatingCentreId) { - $documents = $aocData['operatingCentre']['adDocuments']; - return array_filter($documents, fn($document) => $document['isPostSubmissionUpload']); + return array_filter( + $aocData['operatingCentre']['adDocuments'], + fn($document) => $document['isPostSubmissionUpload'] && (new DateTimeImmutable($document['createdOn'])) > $startDateTime, + ); } } @@ -190,7 +198,7 @@ public function operatingCentreProcessFileUpload($file) 'licence' => $this->getLicenceId(), 'application' => $this->getIdentifier(), 'operatingCentre' => $this->operatingCentreId, - 'isPostSubmissionUpload' => true + 'isPostSubmissionUpload' => true, ]; $this->uploadFile($file, $data); @@ -275,7 +283,7 @@ public function financialEvidenceProcessFileUpload($file) 'subCategory' => \Common\Category::DOC_SUB_CATEGORY_FINANCIAL_EVIDENCE_DIGITAL, 'licence' => $applicationData['licence']['id'], 'isExternal' => true, - 'isPostSubmissionUpload' => true + 'isPostSubmissionUpload' => true, ]; $this->uploadFile($file, $data); @@ -287,7 +295,11 @@ public function financialEvidenceProcessFileUpload($file) /** Get list of financial evidence documents */ public function financialEvidenceLoadFileUpload(): array { - return array_filter($this->getFinancialEvidenceData()['documents'], fn($doc) => $doc['isPostSubmissionUpload']); + $startDateTime = new DateTimeImmutable($this->getRequest()->getPost('correlationId', $this->startTime)); + return array_filter( + $this->getFinancialEvidenceData()['documents'], + fn($doc) => $doc['isPostSubmissionUpload'] && (new DateTimeImmutable($doc['createdOn'])) > $startDateTime, + ); } /** @@ -307,7 +319,7 @@ public function supportingEvidenceProcessFileUpload($file) 'subCategory' => \Common\Category::DOC_SUB_CATEGORY_SUPPORTING_EVIDENCE, 'licence' => $applicationData['licence']['id'], 'isExternal' => true, - 'isPostSubmissionUpload' => true + 'isPostSubmissionUpload' => true, ]; $this->uploadFile($file, $data); @@ -319,7 +331,11 @@ public function supportingEvidenceProcessFileUpload($file) /** Get list of supporting evidence documents */ public function supportingEvidenceLoadFileUpload(): array { - return array_filter($this->getData()['supportingEvidence'], fn($doc) => $doc['isPostSubmissionUpload']); + $startDateTime = new DateTimeImmutable($this->getRequest()->getPost('correlationId', $this->startTime)); + return array_filter( + $this->getData()['supportingEvidence'], + fn($doc) => $doc['isPostSubmissionUpload'] && (new DateTimeImmutable($doc['createdOn'])) > $startDateTime, + ); } /**