|
@@ -26,6 +26,7 @@ use App\Repository\Core\CountryRepository;
|
|
|
use App\Repository\Organization\OrganizationRepository;
|
|
use App\Repository\Organization\OrganizationRepository;
|
|
|
use App\Repository\Person\PersonRepository;
|
|
use App\Repository\Person\PersonRepository;
|
|
|
use App\Service\Dolibarr\DolibarrApiService;
|
|
use App\Service\Dolibarr\DolibarrApiService;
|
|
|
|
|
+use App\Service\File\FileManager;
|
|
|
use App\Service\Organization\Utils as OrganizationUtils;
|
|
use App\Service\Organization\Utils as OrganizationUtils;
|
|
|
use App\Service\Typo3\BindFileService;
|
|
use App\Service\Typo3\BindFileService;
|
|
|
use App\Service\Typo3\SubdomainService;
|
|
use App\Service\Typo3\SubdomainService;
|
|
@@ -57,10 +58,9 @@ class OrganizationFactory
|
|
|
private readonly Typo3Service $typo3Service,
|
|
private readonly Typo3Service $typo3Service,
|
|
|
private readonly DolibarrApiService $dolibarrApiService,
|
|
private readonly DolibarrApiService $dolibarrApiService,
|
|
|
private readonly EntityManagerInterface $entityManager,
|
|
private readonly EntityManagerInterface $entityManager,
|
|
|
- private readonly PersonRepository $personRepository,
|
|
|
|
|
- private readonly BindFileService $bindFileService,
|
|
|
|
|
- ) {
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ private readonly PersonRepository $personRepository,
|
|
|
|
|
+ private readonly BindFileService $bindFileService, private readonly FileManager $fileManager,
|
|
|
|
|
+ ) {}
|
|
|
|
|
|
|
|
#[Required]
|
|
#[Required]
|
|
|
/** @see https://symfony.com/doc/current/logging/channels_handlers.html#how-to-autowire-logger-channels */
|
|
/** @see https://symfony.com/doc/current/logging/channels_handlers.html#how-to-autowire-logger-channels */
|
|
@@ -596,6 +596,9 @@ class OrganizationFactory
|
|
|
SecurityUtils::preventIfNotLocalhost();
|
|
SecurityUtils::preventIfNotLocalhost();
|
|
|
|
|
|
|
|
$organization = $this->organizationRepository->find($organizationDeletionRequest->getOrganizationId());
|
|
$organization = $this->organizationRepository->find($organizationDeletionRequest->getOrganizationId());
|
|
|
|
|
+ if (!$organization) {
|
|
|
|
|
+ throw new \RuntimeException("No organization was found for id : " . $organizationDeletionRequest->getOrganizationId());
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
$this->logger->info(
|
|
$this->logger->info(
|
|
|
"Start the deletion of organization '".$organization->getName()."' [".$organization->getId().']'
|
|
"Start the deletion of organization '".$organization->getName()."' [".$organization->getId().']'
|
|
@@ -606,8 +609,7 @@ class OrganizationFactory
|
|
|
$withError = false;
|
|
$withError = false;
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- // On doit gérer à part la suppression des Access afin de supprimer au passage les Person devenues 'orphelines'
|
|
|
|
|
- $this->deleteOrganizationAccesses($organization);
|
|
|
|
|
|
|
+ $orphanPersons = $this->getOrphansToBePersons($organization);
|
|
|
|
|
|
|
|
// On est obligé de supprimer manuellement les paramètres, car c'est l'entité Parameters qui est
|
|
// On est obligé de supprimer manuellement les paramètres, car c'est l'entité Parameters qui est
|
|
|
// propriétaire de la relation Organization ↔ Parameters.
|
|
// propriétaire de la relation Organization ↔ Parameters.
|
|
@@ -616,6 +618,13 @@ class OrganizationFactory
|
|
|
// Toutes les autres entités liées seront supprimées en cascade
|
|
// Toutes les autres entités liées seront supprimées en cascade
|
|
|
$this->entityManager->remove($organization);
|
|
$this->entityManager->remove($organization);
|
|
|
|
|
|
|
|
|
|
+ // Supprime les personnes qui n'avaient pas d'autre Access attaché
|
|
|
|
|
+ $deletedPersonIds = [];
|
|
|
|
|
+ foreach ($orphanPersons as $person) {
|
|
|
|
|
+ $deletedPersonIds[] = $person->getId();
|
|
|
|
|
+ $this->entityManager->remove($person);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
$this->entityManager->flush();
|
|
$this->entityManager->flush();
|
|
|
$this->entityManager->commit();
|
|
$this->entityManager->commit();
|
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
@@ -625,7 +634,7 @@ class OrganizationFactory
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- $this->deleteTypo3Website($organization);
|
|
|
|
|
|
|
+ $this->deleteTypo3Website($organizationDeletionRequest->getOrganizationId());
|
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
|
$this->logger->critical('An error happened while deleting the Typo3 website, please proceed manually.');
|
|
$this->logger->critical('An error happened while deleting the Typo3 website, please proceed manually.');
|
|
|
$this->logger->debug($e);
|
|
$this->logger->debug($e);
|
|
@@ -641,27 +650,21 @@ class OrganizationFactory
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- $this->deleteLocalDirectories($organization);
|
|
|
|
|
- } catch (\Exception $e) {
|
|
|
|
|
- $this->logger->critical('An error happened while deleting the local directories, please proceed manually.');
|
|
|
|
|
- $this->logger->debug($e);
|
|
|
|
|
- $withError = true;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- $this->deleteDirectoriesV1($organization);
|
|
|
|
|
|
|
+ $this->fileManager->deleteOrganizationFiles($organizationDeletionRequest->getOrganizationId());
|
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
|
- $this->logger->critical('An error happened while deleting the V1 directories, please proceed manually.');
|
|
|
|
|
|
|
+ $this->logger->critical("An error happened while deleting the organization's files, please proceed manually.");
|
|
|
$this->logger->debug($e);
|
|
$this->logger->debug($e);
|
|
|
$withError = true;
|
|
$withError = true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- try {
|
|
|
|
|
- $this->deleteDirectories59($organization);
|
|
|
|
|
- } catch (\Exception $e) {
|
|
|
|
|
- $this->logger->critical('An error happened while deleting the 5.9 directories, please proceed manually.');
|
|
|
|
|
- $this->logger->debug($e);
|
|
|
|
|
- $withError = true;
|
|
|
|
|
|
|
+ foreach ($deletedPersonIds as $personId) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $this->fileManager->deletePersonFiles($personId);
|
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
|
+ $this->logger->critical("An error happened while deleting the person's files, please proceed manually (id=" . $person->getId() . ").");
|
|
|
|
|
+ $this->logger->debug($e);
|
|
|
|
|
+ $withError = true;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if ($withError) {
|
|
if ($withError) {
|
|
@@ -677,16 +680,21 @@ class OrganizationFactory
|
|
|
/**
|
|
/**
|
|
|
* Supprime tous les Access d'une organisation, ainsi que la Person
|
|
* Supprime tous les Access d'une organisation, ainsi que la Person
|
|
|
* rattachée (si celle-ci n'est pas liée à d'autres Access).
|
|
* rattachée (si celle-ci n'est pas liée à d'autres Access).
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param Organization $organization
|
|
|
|
|
+ * @return array<Person>
|
|
|
*/
|
|
*/
|
|
|
- protected function deleteOrganizationAccesses(Organization $organization): void
|
|
|
|
|
|
|
+ protected function getOrphansToBePersons(Organization $organization): array
|
|
|
{
|
|
{
|
|
|
|
|
+ $orphans = [];
|
|
|
|
|
+
|
|
|
foreach ($organization->getAccesses() as $access) {
|
|
foreach ($organization->getAccesses() as $access) {
|
|
|
$person = $access->getPerson();
|
|
$person = $access->getPerson();
|
|
|
if ($person->getAccesses()->count() === 1) {
|
|
if ($person->getAccesses()->count() === 1) {
|
|
|
- $this->entityManager->remove($person);
|
|
|
|
|
|
|
+ $orphans[] = $person;
|
|
|
}
|
|
}
|
|
|
- $this->entityManager->remove($access);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ return $orphans;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// TODO: à revoir, c'est du many to many
|
|
// TODO: à revoir, c'est du many to many
|
|
@@ -711,7 +719,8 @@ class OrganizationFactory
|
|
|
// }
|
|
// }
|
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
- protected function deleteTypo3Website(Organization $organization): void
|
|
|
|
|
|
|
+
|
|
|
|
|
+ protected function deleteTypo3Website(int $organizationId): void
|
|
|
{
|
|
{
|
|
|
// TODO: implement
|
|
// TODO: implement
|
|
|
// $this->typo3Service->deleteSite($organization->getId());
|
|
// $this->typo3Service->deleteSite($organization->getId());
|
|
@@ -721,19 +730,4 @@ class OrganizationFactory
|
|
|
{
|
|
{
|
|
|
$this->dolibarrApiService->switchSocietyToProspect($organization->getId());
|
|
$this->dolibarrApiService->switchSocietyToProspect($organization->getId());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- protected function deleteLocalDirectories(Organization $organization): void
|
|
|
|
|
- {
|
|
|
|
|
- // TODO: implement
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- protected function deleteDirectoriesV1(Organization $organization): void
|
|
|
|
|
- {
|
|
|
|
|
- // TODO: implement
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- protected function deleteDirectories59(Organization $organization): void
|
|
|
|
|
- {
|
|
|
|
|
- // TODO: implement
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|