|
|
@@ -28,6 +28,7 @@ use App\Repository\Core\CountryRepository;
|
|
|
use App\Repository\Organization\OrganizationRepository;
|
|
|
use App\Repository\Person\PersonRepository;
|
|
|
use App\Service\Dolibarr\DolibarrApiService;
|
|
|
+use App\Service\File\FileManager;
|
|
|
use App\Service\Typo3\BindFileService;
|
|
|
use App\Service\Typo3\SubdomainService;
|
|
|
use App\Service\Typo3\Typo3Service;
|
|
|
@@ -63,7 +64,7 @@ class OrganizationFactory
|
|
|
private readonly DolibarrApiService $dolibarrApiService,
|
|
|
private readonly EntityManagerInterface $entityManager,
|
|
|
private readonly PersonRepository $personRepository,
|
|
|
- private readonly BindFileService $bindFileService,
|
|
|
+ private readonly BindFileService $bindFileService, private readonly FileManager $fileManager,
|
|
|
) {}
|
|
|
|
|
|
#[Required]
|
|
|
@@ -609,8 +610,7 @@ class OrganizationFactory
|
|
|
$withError = false;
|
|
|
|
|
|
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
|
|
|
// propriétaire de la relation Organization ↔ Parameters.
|
|
|
@@ -619,6 +619,11 @@ class OrganizationFactory
|
|
|
// Toutes les autres entités liées seront supprimées en cascade
|
|
|
$this->entityManager->remove($organization);
|
|
|
|
|
|
+ // Supprime les personnes qui n'avaient pas d'autre Access attaché
|
|
|
+ foreach ($orphanPersons as $person) {
|
|
|
+ $this->entityManager->remove($person);
|
|
|
+ }
|
|
|
+
|
|
|
$this->entityManager->flush();
|
|
|
$this->entityManager->commit();
|
|
|
} catch (\Exception $e) {
|
|
|
@@ -628,7 +633,7 @@ class OrganizationFactory
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- $this->deleteTypo3Website($organization);
|
|
|
+ $this->deleteTypo3Website($organizationDeletionRequest->getOrganizationId());
|
|
|
} catch (\Exception $e) {
|
|
|
$this->logger->critical("An error happened while deleting the Typo3 website, please proceed manually.");
|
|
|
$this->logger->debug($e);
|
|
|
@@ -636,7 +641,7 @@ class OrganizationFactory
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- $this->deleteDolibarrSociety($organization);
|
|
|
+ $this->deleteDolibarrSociety($organizationDeletionRequest->getOrganizationId());
|
|
|
} catch (\Exception $e) {
|
|
|
$this->logger->critical("An error happened while deleting the Dolibarr society, please proceed manually.");
|
|
|
$this->logger->debug($e);
|
|
|
@@ -644,27 +649,21 @@ class OrganizationFactory
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- $this->deleteLocalDirectories($organization);
|
|
|
+ $this->fileManager->deleteOrganizationFiles($organizationDeletionRequest->getOrganizationId());
|
|
|
} catch (\Exception $e) {
|
|
|
- $this->logger->critical("An error happened while deleting the local directories, please proceed manually.");
|
|
|
+ $this->logger->critical("An error happened while deleting the organization's files, please proceed manually.");
|
|
|
$this->logger->debug($e);
|
|
|
$withError = true;
|
|
|
}
|
|
|
|
|
|
- try {
|
|
|
- $this->deleteDirectoriesV1($organization);
|
|
|
- } catch (\Exception $e) {
|
|
|
- $this->logger->critical("An error happened while deleting the V1 directories, please proceed manually.");
|
|
|
- $this->logger->debug($e);
|
|
|
- $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 ($orphanPersons as $person) {
|
|
|
+ try {
|
|
|
+ $this->fileManager->deletePersonFiles($person->getId());
|
|
|
+ } 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) {
|
|
|
@@ -682,63 +681,29 @@ class OrganizationFactory
|
|
|
* rattachée (si celle-ci n'est pas liée à d'autres Access)
|
|
|
*
|
|
|
* @param Organization $organization
|
|
|
- * @return void
|
|
|
+ * @return array<Person>
|
|
|
*/
|
|
|
- protected function deleteOrganizationAccesses(Organization $organization): void
|
|
|
+ protected function getOrphansToBePersons(Organization $organization): array
|
|
|
{
|
|
|
+ $orphans = [];
|
|
|
+
|
|
|
foreach ($organization->getAccesses() as $access) {
|
|
|
$person = $access->getPerson();
|
|
|
if ($person->getAccesses()->count() === 1) {
|
|
|
- $this->entityManager->remove($person);
|
|
|
+ $orphans[] = $person;
|
|
|
}
|
|
|
- $this->entityManager->remove($access);
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- // TODO: à revoir, c'est du many to many
|
|
|
-// protected function removeTypeOfPractices(Organization $organization): void {
|
|
|
-// foreach ($organization->getTypeOfPractices() as $typeOfPractice) {
|
|
|
-// $organization->removeTypeOfPractice($typeOfPractice);
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
- // TODO: à revoir, c'est du many to many
|
|
|
-// protected function deleteContactPoints(Organization $organization): void
|
|
|
-// {
|
|
|
-// foreach ($organization->getContactPoints() as $contactPoint) {
|
|
|
-// $this->entityManager->remove($contactPoint);
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
- // TODO: à revoir, c'est du many to many
|
|
|
-// protected function deleteBankAccounts(Organization $organization): void {
|
|
|
-// foreach ($organization->getBankAccounts() as $bankAccount) {
|
|
|
-// $this->entityManager->remove($bankAccount);
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
- protected function deleteTypo3Website(Organization $organization): void
|
|
|
- {
|
|
|
- // TODO: implement
|
|
|
-// $this->typo3Service->deleteSite($organization->getId());
|
|
|
+ return $orphans;
|
|
|
}
|
|
|
|
|
|
- protected function deleteDolibarrSociety(Organization $organization): void
|
|
|
- {
|
|
|
- // TODO: implement
|
|
|
- }
|
|
|
-
|
|
|
- protected function deleteLocalDirectories(Organization $organization): void
|
|
|
- {
|
|
|
- // TODO: implement
|
|
|
- }
|
|
|
-
|
|
|
- protected function deleteDirectoriesV1(Organization $organization): void
|
|
|
+ protected function deleteTypo3Website(int $organizationId): void
|
|
|
{
|
|
|
// TODO: implement
|
|
|
+// $this->typo3Service->deleteSite($organization->getId());
|
|
|
}
|
|
|
|
|
|
- protected function deleteDirectories59(Organization $organization): void
|
|
|
+ protected function deleteDolibarrSociety(int $organizationId): void
|
|
|
{
|
|
|
// TODO: implement
|
|
|
}
|