Browse Source

minor fixes, complete organization entities deletion

Olivier Massot 1 year ago
parent
commit
071e88f5fa

+ 1 - 5
src/ApiResources/Organization/OrganizationDeletionRequest.php

@@ -5,11 +5,7 @@ namespace App\ApiResources\Organization;
 use ApiPlatform\Metadata\ApiProperty;
 use ApiPlatform\Metadata\ApiResource;
 use ApiPlatform\Metadata\Post;
-use App\Enum\Organization\LegalEnum;
-use App\Enum\Organization\OrganizationIdsEnum;
-use App\Enum\Organization\PrincipalTypeEnum;
-use App\Enum\Organization\SettingsProductEnum;
-use App\State\Processor\Organization\OrganizationCreationRequestProcessor;
+use App\State\Processor\Organization\OrganizationDeletionRequestProcessor;
 use Symfony\Component\Validator\Constraints as Assert;
 
 /**

+ 1 - 1
src/Entity/Person/Person.php

@@ -362,7 +362,7 @@ class Person implements UserInterface, PasswordAuthenticatedUserInterface
     /**
      * @return Collection<int, Access>
      */
-    public function getAccess(): Collection
+    public function getAccesses(): Collection
     {
         return $this->access;
     }

+ 4 - 3
src/Service/Organization/OrganizationFactory.php

@@ -615,17 +615,18 @@ class OrganizationFactory
             $this->entityManager->remove($organization);
 
             $this->entityManager->flush();
+            $this->entityManager->commit();
         } catch (\Exception $e) {
             $this->logger->critical("An error happened, operation cancelled\n" . $e);
             $this->entityManager->rollback();
             throw $e;
         }
 
-        $this->deleteTypo3Website($organization);
+//        $this->deleteTypo3Website($organization);
 
-        $this->deleteDolibarrSociety($organization);
+//        $this->deleteDolibarrSociety($organization);
 
-        $this->deleteDirectories($organization);
+//        $this->deleteDirectories($organization);
     }
 
     /**

+ 7 - 2
src/State/Processor/Organization/OrganizationCreationRequestProcessor.php

@@ -21,14 +21,19 @@ class OrganizationCreationRequestProcessor implements ProcessorInterface
     ) {}
 
     /**
-     * @param OrganizationCreationRequest $organizationCreationRequest
+     * @param OrganizationCreationRequest $data
      * @param mixed[]       $uriVariables
      * @param mixed[]       $context
      *
      * @throws \Exception
      */
-    public function process(mixed $organizationCreationRequest, Operation $operation, array $uriVariables = [], array $context = []): OrganizationCreationRequest
+    public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): OrganizationCreationRequest
     {
+        /**
+         * @var OrganizationCreationRequest $organizationCreationRequest
+         */
+        $organizationCreationRequest = $data;
+
         if (!$operation instanceof Post) {
             throw new \RuntimeException('not supported', Response::HTTP_METHOD_NOT_ALLOWED);
         }

+ 10 - 3
src/State/Processor/Organization/OrganizationDeletionRequestProcessor.php

@@ -6,10 +6,12 @@ namespace App\State\Processor\Organization;
 
 use ApiPlatform\Metadata\Delete;
 use ApiPlatform\Metadata\Operation;
+use ApiPlatform\Metadata\Post;
 use ApiPlatform\State\ProcessorInterface;
 use App\ApiResources\Organization\OrganizationCreationRequest;
 use App\ApiResources\Organization\OrganizationDeletionRequest;
 use App\Message\Command\OrganizationCreationCommand;
+use App\Message\Command\OrganizationDeletionCommand;
 use App\Service\Organization\OrganizationFactory;
 use Symfony\Component\HttpFoundation\Response;
 use Symfony\Component\Messenger\MessageBusInterface;
@@ -22,15 +24,20 @@ class OrganizationDeletionRequestProcessor implements ProcessorInterface
     ) {}
 
     /**
-     * @param OrganizationDeletionRequest $organizationDeletionRequest
+     * @param OrganizationDeletionRequest $data
      * @param mixed[]       $uriVariables
      * @param mixed[]       $context
      *
      * @throws \Exception
      */
-    public function process(mixed $organizationDeletionRequest, Operation $operation, array $uriVariables = [], array $context = []): OrganizationCreationRequest
+    public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): OrganizationDeletionRequest
     {
-        if (!$operation instanceof Delete) {
+        /**
+         * @var OrganizationDeletionRequest $organizationDeletionRequest
+         */
+        $organizationDeletionRequest = $data;
+
+        if (!$operation instanceof Post) {
             throw new \RuntimeException('not supported', Response::HTTP_METHOD_NOT_ALLOWED);
         }