Olivier Massot 3 лет назад
Родитель
Сommit
3d078a50d8

+ 2 - 2
src/Commands/PostUpgrade/V0_2/PostUpgradeCommand.php

@@ -61,7 +61,7 @@ class PostUpgradeCommand extends Command
 
         $opentalentCnn->beginTransaction();
 
-        $opentassosCnn = new PDO(
+        $openassosCnn = new PDO(
             "mysql:host=prod-front;dbname=openassos",
             'dbcloner',
             'wWZ4hYcrmHLW2mUK',
@@ -89,7 +89,7 @@ class PostUpgradeCommand extends Command
             $sql = "SELECT d.pid, REGEXP_REPLACE(d.domainName, '^(.+)\\\\.opentalent\\\\.fr$', '\\\\1')
                     FROM openassos.sys_domain d
                     where d.domainName like '%.opentalent.fr';";
-            $statement = $opentassosCnn->query($sql);
+            $statement = $openassosCnn->query($sql);
 
             foreach ($statement->fetchAll() as $row) {
                 [$cmsId, $subdomain] = $row;

+ 9 - 11
src/Service/OnChange/Organization/OnSubdomainChange.php

@@ -10,7 +10,6 @@ use App\Service\OnChange\OnChangeContext;
 use App\Service\OnChange\OnChangeDefault;
 use App\Service\Organization\Utils as OrganizationUtils;
 use App\Service\Typo3\BindFileService;
-use Doctrine\ORM\EntityManagerInterface;
 use Symfony\Component\Messenger\MessageBusInterface;
 
 class OnSubdomainChange extends OnChangeDefault
@@ -20,10 +19,10 @@ class OnSubdomainChange extends OnChangeDefault
         private AccessUtils $accessUtils,
         private MailHub $mailHub,
         private BindFileService $bindFileService,
-        private MessageBusInterface $messageBus,
-        private EntityManagerInterface $entityManager
+        private MessageBusInterface $messageBus
     ) {}
 
+    /** @noinspection PhpParameterNameChangedDuringInheritanceInspection */
     public function validate($subdomain, OnChangeContext $context): void {
         // Ensure we do not exceed the limit of 3 subdomains per organization
         if (
@@ -34,28 +33,27 @@ class OnSubdomainChange extends OnChangeDefault
         }
     }
 
-    public function onChange($subdomain, OnChangeContext $context): void {
-        $shallPersist = false;
-
+    /** @noinspection PhpParameterNameChangedDuringInheritanceInspection */
+    public function beforeChange($subdomain, OnChangeContext $context): void
+    {
         // Ensure it is the only active subdomain of this organization by disabling other organization subdomains
         if ($subdomain->isActive()) {
             foreach ($subdomain->getOrganization()->getSubdomains() as $other) {
                 if ($other !== $subdomain && $other->isActive()) {
                     $other->setActive(false);
-                    $shallPersist = true;
                 }
             }
         }
+    }
+
+    /** @noinspection PhpParameterNameChangedDuringInheritanceInspection */
+    public function onChange($subdomain, OnChangeContext $context): void {
 
         // Register into the BindFile
         if ($context->isPostRequest()) {
             $this->bindFileService->registerSubdomain($subdomain->getSubdomain());
         }
 
-        if ($shallPersist) {
-            $this->entityManager->flush();
-        }
-
         // A new subdomain is active
         // /!\ This has to be executed after everything has been persisted
         if ($subdomain->isActive() && !($context->previousData() && $context->previousData()->isActive())) {