OrganizationFactory.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. <?php
  2. namespace App\Service\Organization;
  3. use App\ApiResources\Organization\OrganizationCreationRequest;
  4. use App\ApiResources\Organization\OrganizationMemberCreationRequest;
  5. use App\Entity\Access\Access;
  6. use App\Entity\Core\AddressPostal;
  7. use App\Entity\Core\ContactPoint;
  8. use App\Entity\Education\Cycle;
  9. use App\Entity\Network\NetworkOrganization;
  10. use App\Entity\Organization\Organization;
  11. use App\Entity\Organization\OrganizationAddressPostal;
  12. use App\Entity\Organization\Parameters;
  13. use App\Entity\Organization\Settings;
  14. use App\Entity\Organization\Subdomain;
  15. use App\Entity\Person\Person;
  16. use App\Entity\Person\PersonAddressPostal;
  17. use App\Enum\Core\ContactPointTypeEnum;
  18. use App\Enum\Education\CycleEnum;
  19. use App\Enum\Organization\AddressPostalOrganizationTypeEnum;
  20. use App\Enum\Person\AddressPostalPersonTypeEnum;
  21. use App\Repository\Core\CountryRepository;
  22. use App\Repository\Organization\OrganizationRepository;
  23. use App\Repository\Person\PersonRepository;
  24. use App\Service\Dolibarr\DolibarrApiService;
  25. use App\Service\Typo3\BindFileService;
  26. use App\Service\Typo3\SubdomainService;
  27. use App\Service\Typo3\Typo3Service;
  28. use App\Service\Utils\DatesUtils;
  29. use Doctrine\ORM\EntityManagerInterface;
  30. use Elastica\Param;
  31. use libphonenumber\NumberParseException;
  32. use libphonenumber\PhoneNumberUtil;
  33. use Psr\Log\LoggerInterface;
  34. use Symfony\Component\HttpFoundation\Response;
  35. use Symfony\Component\String\ByteString;
  36. use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
  37. use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
  38. use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
  39. use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
  40. use Symfony\Contracts\Service\Attribute\Required;
  41. use Throwable;
  42. use App\Service\Organization\Utils as OrganizationUtils;
  43. class OrganizationFactory
  44. {
  45. private LoggerInterface $logger;
  46. public function __construct(
  47. private readonly SubdomainService $subdomainService,
  48. private readonly OrganizationRepository $organizationRepository,
  49. private readonly CountryRepository $countryRepository,
  50. private readonly OrganizationUtils $organizationUtils,
  51. private readonly Typo3Service $typo3Service,
  52. private readonly DolibarrApiService $dolibarrApiService,
  53. private readonly EntityManagerInterface $entityManager,
  54. private readonly PersonRepository $personRepository,
  55. private readonly BindFileService $bindFileService,
  56. ) {}
  57. #[Required]
  58. /** @see https://symfony.com/doc/current/logging/channels_handlers.html#how-to-autowire-logger-channels */
  59. public function setLoggerInterface(LoggerInterface $adminLogger): void
  60. {
  61. $this->logger = $adminLogger;
  62. }
  63. /**
  64. * Créé une nouvelle organisation à partir des données contenues dans une OrganizationCreationRequest
  65. *
  66. * @param OrganizationCreationRequest $organizationCreationRequest
  67. * @return Organization
  68. * @throws TransportExceptionInterface
  69. * @throws Throwable
  70. */
  71. public function create(OrganizationCreationRequest $organizationCreationRequest): Organization
  72. {
  73. $this->logger->info(
  74. "Start the creation of a new organization named '" . $organizationCreationRequest->getName() . "'"
  75. );
  76. $this->entityManager->beginTransaction();
  77. try {
  78. // On vérifie si cette organisation n'existe pas déjà
  79. if ($this->isExistingOrganization($organizationCreationRequest)) {
  80. throw new \RuntimeException('An organization named ' . $organizationCreationRequest->getName() . ' already exists');
  81. }
  82. // On vérifie la validité et la disponibilité du sous domaine
  83. $this->validateSubdomain($organizationCreationRequest->getSubdomain());
  84. $this->logger->info("Subdomain is valid and available : '" . $organizationCreationRequest->getSubdomain() . "'");
  85. // On construit l'organisation et ses relations
  86. $organization = $this->makeOrganizationWithRelations($organizationCreationRequest);
  87. $this->logger->info("Organization created with all its relations");
  88. // On persiste et on commit
  89. $this->entityManager->persist($organization);
  90. $this->entityManager->flush();
  91. // Création de la société Dolibarr
  92. $dolibarrId = $this->dolibarrApiService->createSociety(
  93. $organization,
  94. $organizationCreationRequest->isClient()
  95. );
  96. $this->logger->info("New dolibarr structure created (uid : " . $dolibarrId . ")");
  97. $this->entityManager->commit();
  98. $this->logger->debug(" - New entities committed in DB");
  99. $this->logger->info("Organization persisted in the DB");
  100. } catch (\Exception $e) {
  101. $this->logger->critical("An error happened, operation cancelled\n" . $e);
  102. $this->entityManager->rollback();
  103. throw $e;
  104. }
  105. // Register the subdomain into the BindFile (takes up to 5min to take effect)
  106. $this->bindFileService->registerSubdomain($organizationCreationRequest->getSubdomain());
  107. $this->logger->info("Subdomain registered");
  108. // Création du site typo3 (on est obligé d'attendre que l'organisation soit persistée en base)
  109. if ($organizationCreationRequest->getCreateWebsite()) {
  110. $this->createTypo3Website($organization);
  111. } else {
  112. $this->logger->warning("Typo3 website creation was not required");
  113. }
  114. return $organization;
  115. }
  116. /**
  117. * Une organisation du même nom existe-t-elle déjà à la même adresse ?
  118. *
  119. * @param OrganizationCreationRequest $organizationCreationRequest
  120. * @return bool
  121. */
  122. protected function isExistingOrganization(OrganizationCreationRequest $organizationCreationRequest): bool
  123. {
  124. return $this
  125. ->organizationRepository
  126. ->count(
  127. [
  128. 'name' => $organizationCreationRequest->getName(),
  129. ]
  130. ) > 0;
  131. }
  132. /**
  133. * Vérifie la disponibilité et la validité d'un sous domaine
  134. *
  135. * @param string $subdomainValue
  136. * @return void
  137. * @throws \Exception
  138. */
  139. protected function validateSubdomain(string $subdomainValue): void
  140. {
  141. if (!$this->subdomainService->isValidSubdomain($subdomainValue)) {
  142. throw new \RuntimeException("Not a valid subdomain : " . $subdomainValue);
  143. }
  144. if ($this->subdomainService->isReservedSubdomain($subdomainValue)) {
  145. throw new \RuntimeException("This subdomain is not available : " . $subdomainValue);
  146. }
  147. if ($this->subdomainService->isRegistered($subdomainValue)) {
  148. throw new \RuntimeException("This subdomain is already registered : " . $subdomainValue);
  149. }
  150. }
  151. /**
  152. * Créé une nouvelle instance d'organisation, et toutes les instances liées (paramètres, contact, adresses, ...),
  153. * selon le contenu de la requête de création.
  154. *
  155. * @param OrganizationCreationRequest $organizationCreationRequest
  156. * @return Organization
  157. * @throws Throwable
  158. */
  159. protected function makeOrganizationWithRelations(
  160. OrganizationCreationRequest $organizationCreationRequest
  161. ): Organization
  162. {
  163. // Création de l'organisation
  164. $organization = $this->makeOrganization($organizationCreationRequest);
  165. $this->logger->debug(" - Organization created");
  166. // Création des Parameters
  167. $parameters = $this->makeParameters($organizationCreationRequest);
  168. $organization->setParameters($parameters);
  169. $this->logger->debug(" - Parameters created");
  170. // Création des Settings
  171. $settings = $this->makeSettings($organizationCreationRequest);
  172. $organization->setSettings($settings);
  173. $this->logger->debug(" - Settings created");
  174. // Création de l'adresse postale
  175. $organizationAddressPostal = $this->makePostalAddress($organizationCreationRequest);
  176. $organization->addOrganizationAddressPostal($organizationAddressPostal);
  177. $this->logger->debug(" - OrganizationAddressPostal created");
  178. // Création du point de contact
  179. $contactPoint = $this->makeContactPoint($organizationCreationRequest);
  180. $organization->addContactPoint($contactPoint);
  181. $this->logger->debug(" - ContactPoint created");
  182. // Rattachement au réseau
  183. $networkOrganization = $this->makeNetworkOrganization($organizationCreationRequest);
  184. $organization->addNetworkOrganization($networkOrganization);
  185. $this->logger->debug(" - NetworkOrganization created");
  186. // Créé l'admin
  187. $adminAccess = $this->makeAdminAccess($organizationCreationRequest);
  188. $organization->addAccess($adminAccess);
  189. $this->logger->debug(" - Admin access created");
  190. // Création des cycles
  191. foreach ($this->makeCycles() as $cycle) {
  192. $organization->addCycle($cycle);
  193. }
  194. $this->logger->debug(" - Cycles created");
  195. // Création du président (si renseigné)
  196. $presidentCreationRequest = $organizationCreationRequest->getPresident();
  197. if ($presidentCreationRequest !== null) {
  198. $presidentAccess = $this->makeAccess($presidentCreationRequest);
  199. $organization->addAccess($presidentAccess);
  200. $this->logger->debug(" - President access created");
  201. }
  202. // Création du directeur (si renseigné)
  203. $directorCreationRequest = $organizationCreationRequest->getDirector();
  204. if ($directorCreationRequest !== null) {
  205. $directorAccess = $this->makeAccess($directorCreationRequest);
  206. $organization->addAccess($directorAccess);
  207. $this->logger->debug(" - Director access created");
  208. }
  209. // Création du sous-domaine
  210. $subdomain = $this->makeSubdomain($organizationCreationRequest);
  211. $subdomain->setOrganization($organization);
  212. // <--- Pour la rétrocompatibilité avec la v1 ; pourra être supprimé lorsque la migration sera achevée
  213. $parameters = $organization->getParameters();
  214. $parameters->setSubDomain($organizationCreationRequest->getSubdomain());
  215. $parameters->setOtherWebsite('https://' . $organizationCreationRequest->getSubdomain() . '.opentalent.fr');
  216. $this->entityManager->persist($parameters);
  217. // --->
  218. $this->logger->debug(" - Subdomain created");
  219. return $organization;
  220. }
  221. /**
  222. * Créé une nouvelle instance d'organisation
  223. *
  224. * @param OrganizationCreationRequest $organizationCreationRequest
  225. * @return Organization
  226. */
  227. protected function makeOrganization(OrganizationCreationRequest $organizationCreationRequest): Organization
  228. {
  229. // Création de l'organisation
  230. $organization = new Organization();
  231. $organization->setName($organizationCreationRequest->getName());
  232. $organization->setLegalStatus($organizationCreationRequest->getLegalStatus());
  233. $organization->setPrincipalType($organizationCreationRequest->getPrincipalType());
  234. $this->entityManager->persist($organization);
  235. return $organization;
  236. }
  237. /**
  238. * Create a new Parameters object from the data in an OrganizationCreationRequest
  239. *
  240. * @param OrganizationCreationRequest $organizationCreationRequest The organization creation request
  241. * @return Parameters The created Parameters object
  242. * @throws Throwable If there is an error
  243. */
  244. protected function makeParameters(OrganizationCreationRequest $organizationCreationRequest): Parameters
  245. {
  246. $parameters = new Parameters();
  247. $this->entityManager->persist($parameters);
  248. return $parameters;
  249. }
  250. /**
  251. * Creates a new instance of the Settings class based on the given OrganizationCreationRequest object.
  252. *
  253. * @param OrganizationCreationRequest $organizationCreationRequest The OrganizationCreationRequest object containing the required data.
  254. *
  255. * @return Settings The newly created instance of the Settings class.
  256. */
  257. protected function makeSettings(OrganizationCreationRequest $organizationCreationRequest): Settings
  258. {
  259. $settings = new Settings();
  260. $settings->setProduct($organizationCreationRequest->getProduct());
  261. $this->entityManager->persist($settings);
  262. return $settings;
  263. }
  264. /**
  265. * Creates a new instance of the OrganizationAddressPostal class based on the given OrganizationCreationRequest object.
  266. *
  267. * @param OrganizationCreationRequest $organizationCreationRequest The OrganizationCreationRequest object containing the required data.
  268. *
  269. * @return OrganizationAddressPostal The newly created instance of the OrganizationAddressPostal class.
  270. */
  271. protected function makePostalAddress(OrganizationCreationRequest $organizationCreationRequest): OrganizationAddressPostal
  272. {
  273. $addressPostal = new AddressPostal();
  274. $addressPostal->setStreetAddress($organizationCreationRequest->getStreetAddress1());
  275. $addressPostal->setStreetAddressSecond($organizationCreationRequest->getStreetAddress2());
  276. $addressPostal->setStreetAddressThird($organizationCreationRequest->getStreetAddress3());
  277. $addressPostal->setPostalCode($organizationCreationRequest->getPostalCode());
  278. $addressPostal->setAddressCity($organizationCreationRequest->getCity());
  279. $country = $this->countryRepository->find($organizationCreationRequest->getCountryId());
  280. $addressPostal->setAddressCountry($country);
  281. $this->entityManager->persist($addressPostal);
  282. $organizationAddressPostal = new OrganizationAddressPostal();
  283. $organizationAddressPostal->setAddressPostal($addressPostal);
  284. $organizationAddressPostal->setType(AddressPostalOrganizationTypeEnum::ADDRESS_HEAD_OFFICE);
  285. $this->entityManager->persist($organizationAddressPostal);
  286. return $organizationAddressPostal;
  287. }
  288. /**
  289. * Creates a new instance of the ContactPoint class based on the given OrganizationCreationRequest object.
  290. *
  291. * @param OrganizationCreationRequest $organizationCreationRequest The OrganizationCreationRequest object containing the required data.
  292. *
  293. * @return ContactPoint The newly created instance of the ContactPoint class.
  294. * @throws NumberParseException
  295. */
  296. protected function makeContactPoint(OrganizationCreationRequest $organizationCreationRequest): ContactPoint
  297. {
  298. $phoneUtil = PhoneNumberUtil::getInstance();
  299. $phoneNumber = $phoneUtil->parse($organizationCreationRequest->getPhoneNumber());
  300. $contactPoint = new ContactPoint();
  301. $contactPoint->setContactType(ContactPointTypeEnum::PRINCIPAL);
  302. $contactPoint->setEmail($organizationCreationRequest->getEmail());
  303. $contactPoint->setTelphone($phoneNumber);
  304. $this->entityManager->persist($contactPoint);
  305. return $contactPoint;
  306. }
  307. /**
  308. * Creates a new instance of the NetworkOrganization class based on the given OrganizationCreationRequest object.
  309. *
  310. * @param OrganizationCreationRequest $organizationCreationRequest The OrganizationCreationRequest object containing the required data.
  311. *
  312. * @return NetworkOrganization The newly created instance of the NetworkOrganization class.
  313. *
  314. * @throws \RuntimeException|\Exception if no parent organization is found for the given parent ID or if no network is found for the given network ID.
  315. */
  316. protected function makeNetworkOrganization(OrganizationCreationRequest $organizationCreationRequest): NetworkOrganization
  317. {
  318. $parent = $this->organizationRepository->find($organizationCreationRequest->getParentId());
  319. if (!$parent) {
  320. throw new \RuntimeException('No parent organization found for id ' . $organizationCreationRequest->getParentId());
  321. }
  322. $networkOrganization = $this->organizationUtils->getActiveNetworkOrganization($parent);
  323. if (!$networkOrganization) {
  324. throw new \RuntimeException('No network found for parent ' . $organizationCreationRequest->getParentId());
  325. }
  326. $network = $networkOrganization->getNetwork();
  327. $networkOrganization = new NetworkOrganization();
  328. $networkOrganization->setParent($parent);
  329. $networkOrganization->setNetwork($network);
  330. $networkOrganization->setStartDate(DatesUtils::new());
  331. $this->entityManager->persist($networkOrganization);
  332. return $networkOrganization;
  333. }
  334. /**
  335. * Creates a new instance of the Access class with admin access based on the given OrganizationCreationRequest object.
  336. *
  337. * @param OrganizationCreationRequest $organizationCreationRequest The OrganizationCreationRequest object containing the required data.
  338. *
  339. * @return Access The newly created instance of the Access class with admin access.
  340. */
  341. protected function makeAdminAccess(OrganizationCreationRequest $organizationCreationRequest): Access
  342. {
  343. $admin = new Person();
  344. $admin->setUsername('admin' . strtolower($organizationCreationRequest->getSubdomain()));
  345. $randomString = ByteString::fromRandom(32)->toString();
  346. $admin->setPassword($randomString);
  347. $this->entityManager->persist($admin);
  348. $adminAccess = new Access();
  349. $adminAccess->setAdminAccess(true);
  350. $adminAccess->setPerson($admin);
  351. $this->entityManager->persist($adminAccess);
  352. return $adminAccess;
  353. }
  354. /**
  355. * Creates an array of Cycle objects based on a predefined set of data.
  356. *
  357. * @return Cycle[] An array of Cycle objects.
  358. */
  359. protected function makeCycles(): array
  360. {
  361. $cyclesData = [
  362. ['Cycle initiation', 10, CycleEnum::INITIATION_CYCLE],
  363. ['Cycle 1', 20, CycleEnum::CYCLE_1],
  364. ['Cycle 2', 30, CycleEnum::CYCLE_2],
  365. ['Cycle 3', 40, CycleEnum::CYCLE_3],
  366. ['Cycle 4', 50, CycleEnum::CYCLE_4],
  367. ['Hors cycle', 60, CycleEnum::OUT_CYCLE],
  368. ];
  369. $cycles = [];
  370. foreach ($cyclesData as $cycleData) {
  371. $cycle = new Cycle();
  372. $cycle->setLabel($cycleData[0]);
  373. $cycle->setOrder($cycleData[1]);
  374. $cycle->setCycleEnum($cycleData[2]);
  375. $cycle->setIsSystem(false);
  376. $this->entityManager->persist($cycle);
  377. $cycles[] = $cycle;
  378. }
  379. return $cycles;
  380. }
  381. /**
  382. * Creates an Access object based on the given OrganizationMemberCreationRequest.
  383. *
  384. * @param int|OrganizationMemberCreationRequest $creationRequestData The request object containing the
  385. * necessary data for creating a Person object,
  386. * or the id of an existing one.
  387. * @return Access The created Access object.
  388. * @throws NumberParseException
  389. */
  390. protected function makeAccess(
  391. int | OrganizationMemberCreationRequest $creationRequestData
  392. ): Access
  393. {
  394. if (is_int($creationRequestData)) {
  395. $person = $this->personRepository->find($creationRequestData);
  396. } else {
  397. $person = new Person();
  398. $person->setUsername($creationRequestData->getUsername());
  399. $person->setPassword(ByteString::fromRandom(32)->toString());
  400. $person->setGender($creationRequestData->getGender());
  401. $person->setName(
  402. ucfirst(strtolower($creationRequestData->getName()))
  403. );
  404. $person->setGivenName(
  405. ucfirst(strtolower($creationRequestData->getGivenName()))
  406. );
  407. $personPostalAddress = $this->makePersonPostalAddress($creationRequestData);
  408. $person->addPersonAddressPostal($personPostalAddress);
  409. $contactPoint = $this->makePersonContactPoint($creationRequestData);
  410. $person->addContactPoint($contactPoint);
  411. $this->entityManager->persist($person);
  412. }
  413. $access = new Access();
  414. $access->setPerson($person);
  415. $this->entityManager->persist($access);
  416. return $access;
  417. }
  418. /**
  419. * Creates a PersonAddressPostal object based on the given OrganizationMemberCreationRequest.
  420. *
  421. * @param OrganizationMemberCreationRequest $organizationMemberCreationRequest The request object containing the
  422. * necessary data for creating a
  423. * PersonAddressPostal object.
  424. * @return PersonAddressPostal The created PersonAddressPostal object.
  425. */
  426. protected function makePersonPostalAddress(OrganizationMemberCreationRequest $organizationMemberCreationRequest): PersonAddressPostal
  427. {
  428. $addressPostal = new AddressPostal();
  429. $addressPostal->setStreetAddress($organizationMemberCreationRequest->getStreetAddress1());
  430. $addressPostal->setStreetAddressSecond($organizationMemberCreationRequest->getStreetAddress2());
  431. $addressPostal->setStreetAddressThird($organizationMemberCreationRequest->getStreetAddress3());
  432. $addressPostal->setPostalCode($organizationMemberCreationRequest->getPostalCode());
  433. $addressPostal->setAddressCity($organizationMemberCreationRequest->getCity());
  434. $country = $this->countryRepository->find($organizationMemberCreationRequest->getCountryId());
  435. $addressPostal->setAddressCountry($country);
  436. $this->entityManager->persist($addressPostal);
  437. $personAddressPostal = new PersonAddressPostal();
  438. $personAddressPostal->setAddressPostal($addressPostal);
  439. $personAddressPostal->setType(AddressPostalPersonTypeEnum::ADDRESS_PRINCIPAL);
  440. $this->entityManager->persist($personAddressPostal);
  441. return $personAddressPostal;
  442. }
  443. /**
  444. * Creates a new instance of the ContactPoint class based on the given OrganizationCreationRequest object.
  445. *
  446. * @param OrganizationMemberCreationRequest $organizationMemberCreationRequest The OrganizationMemberCreationRequest object containing the required data.
  447. *
  448. * @return ContactPoint The newly created instance of the ContactPoint class.
  449. * @throws NumberParseException
  450. */
  451. protected function makePersonContactPoint(OrganizationMemberCreationRequest $organizationMemberCreationRequest): ContactPoint
  452. {
  453. $phoneUtil = PhoneNumberUtil::getInstance();
  454. $phoneNumber = $phoneUtil->parse($organizationMemberCreationRequest->getPhone());
  455. $contactPoint = new ContactPoint();
  456. $contactPoint->setContactType(ContactPointTypeEnum::PRINCIPAL);
  457. $contactPoint->setEmail($organizationMemberCreationRequest->getEmail());
  458. $contactPoint->setTelphone($phoneNumber);
  459. if ($organizationMemberCreationRequest->getMobile() !== null) {
  460. $mobileNumber = $phoneUtil->parse($organizationMemberCreationRequest->getMobile());
  461. $contactPoint->setMobilPhone($mobileNumber);
  462. }
  463. $this->entityManager->persist($contactPoint);
  464. return $contactPoint;
  465. }
  466. protected function makeSubdomain(OrganizationCreationRequest $organizationCreationRequest): Subdomain
  467. {
  468. $subdomain = new Subdomain();
  469. $subdomain->setSubdomain($organizationCreationRequest->getSubdomain());
  470. $subdomain->setActive(true);
  471. $this->entityManager->persist($subdomain);
  472. return $subdomain;
  473. }
  474. /**
  475. * Créé le site Typo3 et retourne l'id de la page racine du site nouvellement créé, ou null en cas d'erreur
  476. *
  477. * @throws RedirectionExceptionInterface
  478. * @throws ClientExceptionInterface
  479. * @throws TransportExceptionInterface
  480. * @throws ServerExceptionInterface
  481. */
  482. protected function createTypo3Website(Organization $organization): ?int {
  483. $response = $this->typo3Service->createSite($organization->getId());
  484. $rootPageUid = json_decode($response->getContent(), true);
  485. if ($response->getStatusCode() === Response::HTTP_OK && $rootPageUid > 0) {
  486. // TODO: revoir l'utilité du champs cmsId
  487. $organization->setCmsId($rootPageUid);
  488. $this->entityManager->persist($organization);
  489. $this->entityManager->flush();
  490. return $rootPageUid;
  491. } else {
  492. $this->logger->critical("/!\ A critical error happened while creating the Typo3 website");
  493. $this->logger->debug($response->getContent());
  494. }
  495. return null;
  496. }
  497. }