소스 검색

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

Olivier Massot 2 년 전
부모
커밋
38e0b32a59
2개의 변경된 파일30개의 추가작업 그리고 8개의 파일을 삭제
  1. 23 7
      src/Service/Typo3/SubdomainService.php
  2. 7 1
      tests/Unit/Service/Typo3/SubdomainServiceTest.php

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

@@ -120,16 +120,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;
@@ -149,18 +150,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);
         $this->subdomainRepository->expects(self::once())->method('findBy')->with(['subdomain' => 'sub'])->willReturn(0);
 
-        $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');