Browse Source

Merge branch 'hotfix/V8-5343-corriger-les-outils-de-maj-de-so' into develop

Olivier Massot 2 years ago
parent
commit
434e35e111

+ 23 - 7
src/Service/Typo3/SubdomainService.php

@@ -129,16 +129,32 @@ class SubdomainService
         $subdomain->setOrganization($organization);
         $subdomain->setActive(false);
 
-        $this->em->persist($subdomain);
-        $this->em->flush();
+        $this->em->beginTransaction();
 
-        // Register into the BindFile (takes up to 5min to take effect)
-        $this->bindFileService->registerSubdomain($subdomain->getSubdomain());
+        try {
 
-        if ($activate) {
-            $subdomain = $this->activateSubdomain($subdomain);
-        }
+            // <--- Pour la rétrocompatibilité avec la v1; pourra être supprimé lorsque la migration sera achevée
+            $parameters = $organization->getParameters();
+            $parameters->setSubDomain($subdomainValue);
+            $parameters->setOtherWebsite('https://' . $subdomainValue . '.opentalent.fr');
+            $this->em->persist($parameters);
+            // --->
+
+            $this->em->persist($subdomain);
+            $this->em->flush();
+
+            // Register into the BindFile (takes up to 5min to take effect)
+            $this->bindFileService->registerSubdomain($subdomain->getSubdomain());
 
+            if ($activate) {
+                $subdomain = $this->activateSubdomain($subdomain);
+            }
+
+            $this->em->commit();
+        } catch (\Throwable $e) {
+            $this->em->rollback();
+            throw $e;
+        }
         return $subdomain;
     }
 

+ 7 - 1
tests/Unit/Service/Typo3/SubdomainServiceTest.php

@@ -5,6 +5,7 @@ namespace App\Tests\Unit\Service\Typo3;
 
 use App\Entity\Access\Access;
 use App\Entity\Organization\Organization;
+use App\Entity\Organization\Parameters;
 use App\Entity\Organization\Subdomain;
 use App\Entity\Person\Person;
 use App\Message\Command\MailerCommand;
@@ -164,18 +165,23 @@ class SubdomainServiceTest extends TestCase
     public function testAddNewSubdomain(): void {
         $subdomainService = $this->makeSubdomainServiceMockFor('addNewSubdomain');
 
+        $parameters = $this->getMockBuilder(Parameters::class)->disableOriginalConstructor()->getMock();
         $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
+        $organization->method('getParameters')->willReturn($parameters);
 
         $subdomainService->expects(self::once())->method('isValidSubdomain')->with('sub')->willReturn(True);
         $subdomainService->expects(self::once())->method('canRegisterNewSubdomain')->with($organization)->willReturn(True);
         $subdomainService->expects(self::once())->method('isReservedSubdomain')->with('sub')->willReturn(false);
         $subdomainService->expects(self::once())->method('isRegistered')->with('sub')->willReturn(false);
 
-        $this->entityManager->expects(self::once())->method('persist');
+        $this->entityManager->expects(self::exactly(2))->method('persist');
         $this->entityManager->expects(self::once())->method('flush');
 
         $this->bindFileService->expects(self::once())->method('registerSubdomain')->with('sub');
 
+        $parameters->expects(self::once())->method('setSubDomain')->with('sub');
+        $parameters->expects(self::once())->method('setOtherWebsite')->with('https://sub.opentalent.fr');
+
         // Subdomain is not activated by default
         $subdomainService->expects(self::never())->method('activateSubdomain');