Skip to content

Commit 921e1f7

Browse files
authored
Cleanup schema (#82)
* fix: clear schema during archiving * v0.5.5
1 parent 25309f3 commit 921e1f7

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

docs/specs/validator-api.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ info:
66
contact:
77
name: IGNF/validator
88
url: "https://github.com/IGNF/validator/issues"
9-
version: "0.5.3"
9+
version: "0.5.5"
1010
title: "API Validator"
1111
license:
1212
name: "AGPL-3.0-or-later"

src/Repository/ValidationRepository.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,17 @@ public function findAllToBeArchived(DateTime $expiryDate)
7373
->getResult()
7474
;
7575
}
76+
77+
/**
78+
* Drop schema corresponding to input validation
79+
*
80+
* @param Validation $validation
81+
* @return boolean
82+
*/
83+
public function dropSchema(Validation $validation)
84+
{
85+
$sql = sprintf('DROP SCHEMA IF EXISTS "validation%s" CASCADE', $validation->getUid());
86+
$reponse = $this->getEntityManager()->getConnection()->executeQuery($sql);
87+
return $reponse->rowCount() != 0;
88+
}
7689
}

src/Validation/ValidationManager.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Entity\Validation;
66
use App\Exception\ZipArchiveValidationException;
7+
use App\Repository\ValidationRepository;
78
use App\Storage\ValidationsStorage;
89
use Doctrine\ORM\EntityManagerInterface;
910
use Psr\Log\LoggerInterface;
@@ -40,6 +41,11 @@ class ValidationManager
4041
*/
4142
private $zipArchiveValidator;
4243

44+
/**
45+
* @var ValidationRepository
46+
*/
47+
private $validationRepository;
48+
4349
/**
4450
* Current validation (in order to handle SIGTERM)
4551
* @var Validation
@@ -51,13 +57,15 @@ public function __construct(
5157
ValidationsStorage $storage,
5258
ValidatorCLI $validatorCli,
5359
ZipArchiveValidator $zipArchiveValidator,
54-
LoggerInterface $logger
60+
LoggerInterface $logger,
61+
ValidationRepository $validationRepository
5562
) {
5663
$this->em = $em;
5764
$this->storage = $storage;
5865
$this->validatorCli = $validatorCli;
5966
$this->zipArchiveValidator = $zipArchiveValidator;
6067
$this->logger = $logger;
68+
$this->validationRepository = $validationRepository;
6169
}
6270

6371
/**
@@ -96,6 +104,10 @@ public function archive(Validation $validation)
96104
if ($this->storage->getStorage()->directoryExists($outputDirectory)) {
97105
$this->storage->getStorage()->deleteDirectory($outputDirectory);
98106
}
107+
$this->logger->info('Validation[{uid}] : drop validation schema', [
108+
'uid' => $validation->getUid(),
109+
]);
110+
$this->validationRepository->dropSchema($validation);
99111
$this->logger->info('Validation[{uid}] : archive removing all files : completed', [
100112
'uid' => $validation->getUid(),
101113
'status' => Validation::STATUS_ARCHIVED,

0 commit comments

Comments
 (0)