|
@@ -35,6 +35,9 @@ use libphonenumber\PhoneNumberUtil;
|
|
|
use Psr\Log\LoggerInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
use Symfony\Component\String\ByteString;
|
|
use Symfony\Component\String\ByteString;
|
|
|
|
|
+use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
|
|
|
|
+use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
|
|
|
|
+use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
|
|
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
|
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
|
|
use Symfony\Contracts\Service\Attribute\Required;
|
|
use Symfony\Contracts\Service\Attribute\Required;
|
|
|
use Throwable;
|
|
use Throwable;
|
|
@@ -74,98 +77,37 @@ class OrganizationFactory
|
|
|
public function create(OrganizationCreationRequest $organizationCreationRequest): Organization
|
|
public function create(OrganizationCreationRequest $organizationCreationRequest): Organization
|
|
|
{
|
|
{
|
|
|
$this->logger->info(
|
|
$this->logger->info(
|
|
|
- 'Start the creation of a new organization named ' . $organizationCreationRequest->getName()
|
|
|
|
|
|
|
+ "Start the creation of a new organization named '" . $organizationCreationRequest->getName() . "'"
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
$this->entityManager->beginTransaction();
|
|
$this->entityManager->beginTransaction();
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
|
|
+ // On vérifie si cette organisation n'existe pas déjà
|
|
|
if ($this->isExistingOrganization($organizationCreationRequest)) {
|
|
if ($this->isExistingOrganization($organizationCreationRequest)) {
|
|
|
throw new \RuntimeException('An organization named ' . $organizationCreationRequest->getName() . ' already exists.');
|
|
throw new \RuntimeException('An organization named ' . $organizationCreationRequest->getName() . ' already exists.');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // On vérifie la validité et la disponibilité du sous domaine
|
|
|
$this->validateSubdomain($organizationCreationRequest->getSubdomain());
|
|
$this->validateSubdomain($organizationCreationRequest->getSubdomain());
|
|
|
$this->logger->info("Subdomain is valid and available : " . $organizationCreationRequest->getSubdomain());
|
|
$this->logger->info("Subdomain is valid and available : " . $organizationCreationRequest->getSubdomain());
|
|
|
|
|
|
|
|
- // Création de l'organisation
|
|
|
|
|
- $organization = $this->makeOrganization($organizationCreationRequest);
|
|
|
|
|
- $this->logger->debug(" - Organization created");
|
|
|
|
|
-
|
|
|
|
|
- // Création des Parameters
|
|
|
|
|
- $parameters = $this->makeParameters($organizationCreationRequest);
|
|
|
|
|
- $organization->setParameters($parameters);
|
|
|
|
|
- $this->logger->debug(" - Parameters created");
|
|
|
|
|
-
|
|
|
|
|
- // Création des Settings
|
|
|
|
|
- $settings = $this->makeSettings($organizationCreationRequest);
|
|
|
|
|
- $organization->setSettings($settings);
|
|
|
|
|
- $this->logger->debug(" - Settings created");
|
|
|
|
|
-
|
|
|
|
|
- // Création de l'adresse postale
|
|
|
|
|
- $organizationAddressPostal = $this->makePostalAddress($organizationCreationRequest);
|
|
|
|
|
- $organization->addOrganizationAddressPostal($organizationAddressPostal);
|
|
|
|
|
- $this->logger->debug(" - OrganizationAddressPostal created");
|
|
|
|
|
-
|
|
|
|
|
- // Création du point de contact
|
|
|
|
|
- $contactPoint = $this->makeContactPoint($organizationCreationRequest);
|
|
|
|
|
- $organization->addContactPoint($contactPoint);
|
|
|
|
|
- $this->logger->debug(" - ContactPoint created");
|
|
|
|
|
-
|
|
|
|
|
- // Rattachement au réseau
|
|
|
|
|
- $networkOrganization = $this->makeNetworkOrganization($organizationCreationRequest);
|
|
|
|
|
- $organization->addNetworkOrganization($networkOrganization);
|
|
|
|
|
- $this->logger->debug(" - NetworkOrganization created");
|
|
|
|
|
-
|
|
|
|
|
- // Créé l'admin
|
|
|
|
|
- $adminAccess = $this->makeAdminAccess($organizationCreationRequest);
|
|
|
|
|
- $organization->addAccess($adminAccess);
|
|
|
|
|
- $this->logger->debug(" - Admin access created");
|
|
|
|
|
-
|
|
|
|
|
- // Création des cycles
|
|
|
|
|
- foreach ($this->makeCycles() as $cycle) {
|
|
|
|
|
- $organization->addCycle($cycle);
|
|
|
|
|
- }
|
|
|
|
|
- $this->logger->debug(" - Cycles created");
|
|
|
|
|
-
|
|
|
|
|
- // Création du président (si renseigné)
|
|
|
|
|
- $presidentCreationRequest = $organizationCreationRequest->getPresident();
|
|
|
|
|
- if ($presidentCreationRequest !== null) {
|
|
|
|
|
- $presidentAccess = $this->makeAccess($presidentCreationRequest);
|
|
|
|
|
- $organization->addAccess($presidentAccess);
|
|
|
|
|
- $this->logger->debug(" - President access created");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Création du directeur (si renseigné)
|
|
|
|
|
- $directorCreationRequest = $organizationCreationRequest->getDirector();
|
|
|
|
|
- if ($directorCreationRequest !== null) {
|
|
|
|
|
- $directorAccess = $this->makeAccess($directorCreationRequest);
|
|
|
|
|
- $organization->addAccess($directorAccess);
|
|
|
|
|
- $this->logger->debug(" - Director access created");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- $subdomain = new Subdomain();
|
|
|
|
|
- $subdomain->setSubdomain($organizationCreationRequest->getSubdomain());
|
|
|
|
|
- $subdomain->setOrganization($organization);
|
|
|
|
|
- $subdomain->setActive(true);
|
|
|
|
|
- $this->entityManager->persist($subdomain);
|
|
|
|
|
|
|
+ // On construit l'organisation et ses relations
|
|
|
|
|
+ $organization = $this->makeOrganizationWithRelations($organizationCreationRequest);
|
|
|
|
|
+ $this->logger->info("Organization created with all its relations");
|
|
|
|
|
|
|
|
- // <--- Pour la rétrocompatibilité avec la v1 ; pourra être supprimé lorsque la migration sera achevée
|
|
|
|
|
- $parameters = $organization->getParameters();
|
|
|
|
|
- $parameters->setSubDomain($organizationCreationRequest->getSubdomain());
|
|
|
|
|
- $parameters->setOtherWebsite('https://' . $organizationCreationRequest->getSubdomain() . '.opentalent.fr');
|
|
|
|
|
- $this->entityManager->persist($parameters);
|
|
|
|
|
- // --->
|
|
|
|
|
|
|
+ // On persiste et on commit
|
|
|
|
|
+ $this->entityManager->persist($organization);
|
|
|
|
|
+ $this->entityManager->flush();
|
|
|
|
|
|
|
|
// Création de la société Dolibarr
|
|
// Création de la société Dolibarr
|
|
|
$dolibarrId = $this->dolibarrApiService->createSociety($organization);
|
|
$dolibarrId = $this->dolibarrApiService->createSociety($organization);
|
|
|
$this->logger->info("New dolibarr structure created (uid : " . $dolibarrId . ")");
|
|
$this->logger->info("New dolibarr structure created (uid : " . $dolibarrId . ")");
|
|
|
|
|
|
|
|
- $this->entityManager->persist($organization);
|
|
|
|
|
- $this->entityManager->flush();
|
|
|
|
|
$this->entityManager->commit();
|
|
$this->entityManager->commit();
|
|
|
|
|
+ $this->logger->debug(" - New entities committed in DB");
|
|
|
|
|
|
|
|
- $this->logger->debug(" - New records commited");
|
|
|
|
|
- $this->logger->info("Organization created in the DB");
|
|
|
|
|
|
|
+ $this->logger->info("Organization persisted in the DB");
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
|
$this->logger->critical("An error happened, operation cancelled : " . $e);
|
|
$this->logger->critical("An error happened, operation cancelled : " . $e);
|
|
@@ -174,28 +116,12 @@ class OrganizationFactory
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Register the subdomain into the BindFile (takes up to 5min to take effect)
|
|
// Register the subdomain into the BindFile (takes up to 5min to take effect)
|
|
|
- $this->bindFileService->registerSubdomain($subdomain->getSubdomain());
|
|
|
|
|
|
|
+ $this->bindFileService->registerSubdomain($organizationCreationRequest->getSubdomain());
|
|
|
$this->logger->info("Subdomain registered");
|
|
$this->logger->info("Subdomain registered");
|
|
|
|
|
|
|
|
// Création du site typo3 (on est obligé d'attendre que l'organisation soit persistée en base)
|
|
// Création du site typo3 (on est obligé d'attendre que l'organisation soit persistée en base)
|
|
|
if ($organizationCreationRequest->getCreateWebsite()) {
|
|
if ($organizationCreationRequest->getCreateWebsite()) {
|
|
|
- $response = $this->typo3Service->createSite($organization->getId());
|
|
|
|
|
- $rootPageUid = json_decode($response->getContent(), true);
|
|
|
|
|
-
|
|
|
|
|
- if (
|
|
|
|
|
- $response->getStatusCode() === Response::HTTP_OK ||
|
|
|
|
|
- !$rootPageUid
|
|
|
|
|
- ) {
|
|
|
|
|
- // TODO: revoir l'utilité du champs cmsId
|
|
|
|
|
- $organization->setCmsId($rootPageUid);
|
|
|
|
|
- $this->entityManager->persist($organization);
|
|
|
|
|
- $this->entityManager->flush();
|
|
|
|
|
- $this->logger->info("New typo3 website created (root uid : " . $rootPageUid . ")");
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
- $this->logger->critical("/!\ A critical error happened while creating the Typo3 website ");
|
|
|
|
|
- $this->logger->debug($response->getContent());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ $this->createTypo3Website($organization);
|
|
|
} else {
|
|
} else {
|
|
|
$this->logger->warning("Typo3 website creation was not required");
|
|
$this->logger->warning("Typo3 website creation was not required");
|
|
|
}
|
|
}
|
|
@@ -242,6 +168,89 @@ class OrganizationFactory
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Créé une nouvelle instance d'organisation, et toutes les instances liées (paramètres, contact, adresses, ...),
|
|
|
|
|
+ * selon le contenu de la requête de création.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param OrganizationCreationRequest $organizationCreationRequest
|
|
|
|
|
+ * @return Organization
|
|
|
|
|
+ * @throws Throwable
|
|
|
|
|
+ */
|
|
|
|
|
+ protected function makeOrganizationWithRelations(
|
|
|
|
|
+ OrganizationCreationRequest $organizationCreationRequest
|
|
|
|
|
+ ): Organization
|
|
|
|
|
+ {
|
|
|
|
|
+ // Création de l'organisation
|
|
|
|
|
+ $organization = $this->makeOrganization($organizationCreationRequest);
|
|
|
|
|
+ $this->logger->debug(" - Organization created");
|
|
|
|
|
+
|
|
|
|
|
+ // Création des Parameters
|
|
|
|
|
+ $parameters = $this->makeParameters($organizationCreationRequest);
|
|
|
|
|
+ $organization->setParameters($parameters);
|
|
|
|
|
+ $this->logger->debug(" - Parameters created");
|
|
|
|
|
+
|
|
|
|
|
+ // Création des Settings
|
|
|
|
|
+ $settings = $this->makeSettings($organizationCreationRequest);
|
|
|
|
|
+ $organization->setSettings($settings);
|
|
|
|
|
+ $this->logger->debug(" - Settings created");
|
|
|
|
|
+
|
|
|
|
|
+ // Création de l'adresse postale
|
|
|
|
|
+ $organizationAddressPostal = $this->makePostalAddress($organizationCreationRequest);
|
|
|
|
|
+ $organization->addOrganizationAddressPostal($organizationAddressPostal);
|
|
|
|
|
+ $this->logger->debug(" - OrganizationAddressPostal created");
|
|
|
|
|
+
|
|
|
|
|
+ // Création du point de contact
|
|
|
|
|
+ $contactPoint = $this->makeContactPoint($organizationCreationRequest);
|
|
|
|
|
+ $organization->addContactPoint($contactPoint);
|
|
|
|
|
+ $this->logger->debug(" - ContactPoint created");
|
|
|
|
|
+
|
|
|
|
|
+ // Rattachement au réseau
|
|
|
|
|
+ $networkOrganization = $this->makeNetworkOrganization($organizationCreationRequest);
|
|
|
|
|
+ $organization->addNetworkOrganization($networkOrganization);
|
|
|
|
|
+ $this->logger->debug(" - NetworkOrganization created");
|
|
|
|
|
+
|
|
|
|
|
+ // Créé l'admin
|
|
|
|
|
+ $adminAccess = $this->makeAdminAccess($organizationCreationRequest);
|
|
|
|
|
+ $organization->addAccess($adminAccess);
|
|
|
|
|
+ $this->logger->debug(" - Admin access created");
|
|
|
|
|
+
|
|
|
|
|
+ // Création des cycles
|
|
|
|
|
+ foreach ($this->makeCycles() as $cycle) {
|
|
|
|
|
+ $organization->addCycle($cycle);
|
|
|
|
|
+ }
|
|
|
|
|
+ $this->logger->debug(" - Cycles created");
|
|
|
|
|
+
|
|
|
|
|
+ // Création du président (si renseigné)
|
|
|
|
|
+ $presidentCreationRequest = $organizationCreationRequest->getPresident();
|
|
|
|
|
+ if ($presidentCreationRequest !== null) {
|
|
|
|
|
+ $presidentAccess = $this->makeAccess($presidentCreationRequest);
|
|
|
|
|
+ $organization->addAccess($presidentAccess);
|
|
|
|
|
+ $this->logger->debug(" - President access created");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Création du directeur (si renseigné)
|
|
|
|
|
+ $directorCreationRequest = $organizationCreationRequest->getDirector();
|
|
|
|
|
+ if ($directorCreationRequest !== null) {
|
|
|
|
|
+ $directorAccess = $this->makeAccess($directorCreationRequest);
|
|
|
|
|
+ $organization->addAccess($directorAccess);
|
|
|
|
|
+ $this->logger->debug(" - Director access created");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $subdomain = $this->makeSubdomain($organizationCreationRequest);
|
|
|
|
|
+ $subdomain->setOrganization($organization);
|
|
|
|
|
+
|
|
|
|
|
+ // <--- Pour la rétrocompatibilité avec la v1 ; pourra être supprimé lorsque la migration sera achevée
|
|
|
|
|
+ $parameters = $organization->getParameters();
|
|
|
|
|
+ $parameters->setSubDomain($organizationCreationRequest->getSubdomain());
|
|
|
|
|
+ $parameters->setOtherWebsite('https://' . $organizationCreationRequest->getSubdomain() . '.opentalent.fr');
|
|
|
|
|
+ $this->entityManager->persist($parameters);
|
|
|
|
|
+ // --->
|
|
|
|
|
+ $this->logger->debug(" - Subdomain created");
|
|
|
|
|
+
|
|
|
|
|
+ return $organization;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Créé une nouvelle instance d'organisation
|
|
* Créé une nouvelle instance d'organisation
|
|
|
*
|
|
*
|
|
@@ -520,4 +529,41 @@ class OrganizationFactory
|
|
|
$this->entityManager->persist($contactPoint);
|
|
$this->entityManager->persist($contactPoint);
|
|
|
return $contactPoint;
|
|
return $contactPoint;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ protected function makeSubdomain(OrganizationCreationRequest $organizationCreationRequest): Subdomain
|
|
|
|
|
+ {
|
|
|
|
|
+ $subdomain = new Subdomain();
|
|
|
|
|
+ $subdomain->setSubdomain($organizationCreationRequest->getSubdomain());
|
|
|
|
|
+ $subdomain->setActive(true);
|
|
|
|
|
+ $this->entityManager->persist($subdomain);
|
|
|
|
|
+
|
|
|
|
|
+ return $subdomain;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Créé le site Typo3 et retourne l'id de la page racine du site nouvellement créé, ou null en cas d'erreur
|
|
|
|
|
+ *
|
|
|
|
|
+ * @throws RedirectionExceptionInterface
|
|
|
|
|
+ * @throws ClientExceptionInterface
|
|
|
|
|
+ * @throws TransportExceptionInterface
|
|
|
|
|
+ * @throws ServerExceptionInterface
|
|
|
|
|
+ */
|
|
|
|
|
+ protected function createTypo3Website(Organization $organization): ?int {
|
|
|
|
|
+ $response = $this->typo3Service->createSite($organization->getId());
|
|
|
|
|
+ $rootPageUid = json_decode($response->getContent(), true);
|
|
|
|
|
+
|
|
|
|
|
+ if ($response->getStatusCode() === Response::HTTP_OK && $rootPageUid > 0) {
|
|
|
|
|
+ // TODO: revoir l'utilité du champs cmsId
|
|
|
|
|
+ $organization->setCmsId($rootPageUid);
|
|
|
|
|
+ $this->entityManager->persist($organization);
|
|
|
|
|
+ $this->entityManager->flush();
|
|
|
|
|
+
|
|
|
|
|
+ return $rootPageUid;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $this->logger->critical("/!\ A critical error happened while creating the Typo3 website ");
|
|
|
|
|
+ $this->logger->debug($response->getContent());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|