|
|
@@ -13,6 +13,7 @@ use App\Entity\Organization\Organization;
|
|
|
use App\Entity\Organization\OrganizationAddressPostal;
|
|
|
use App\Entity\Organization\Parameters;
|
|
|
use App\Entity\Organization\Settings;
|
|
|
+use App\Entity\Organization\Subdomain;
|
|
|
use App\Entity\Person\Person;
|
|
|
use App\Entity\Person\PersonAddressPostal;
|
|
|
use App\Enum\Core\ContactPointTypeEnum;
|
|
|
@@ -24,6 +25,7 @@ use App\Repository\Network\NetworkRepository;
|
|
|
use App\Repository\Organization\OrganizationRepository;
|
|
|
use App\Repository\Person\PersonRepository;
|
|
|
use App\Service\Dolibarr\DolibarrApiService;
|
|
|
+use App\Service\Typo3\BindFileService;
|
|
|
use App\Service\Typo3\SubdomainService;
|
|
|
use App\Service\Typo3\Typo3Service;
|
|
|
use App\Service\Utils\DatesUtils;
|
|
|
@@ -49,7 +51,8 @@ class OrganizationFactory
|
|
|
private readonly Typo3Service $typo3Service,
|
|
|
private readonly DolibarrApiService $dolibarrApiService,
|
|
|
private readonly EntityManagerInterface $entityManager,
|
|
|
- private readonly PersonRepository $personRepository
|
|
|
+ private readonly PersonRepository $personRepository,
|
|
|
+ private readonly BindFileService $bindFileService,
|
|
|
) {}
|
|
|
|
|
|
#[Required]
|
|
|
@@ -77,7 +80,7 @@ class OrganizationFactory
|
|
|
|
|
|
try {
|
|
|
if ($this->isExistingOrganization($organizationCreationRequest)) {
|
|
|
- throw new \RuntimeException('An organization named ' . $organizationCreationRequest->getName() . ' already exists at this address.');
|
|
|
+ throw new \RuntimeException('An organization named ' . $organizationCreationRequest->getName() . ' already exists.');
|
|
|
}
|
|
|
|
|
|
$this->validateSubdomain($organizationCreationRequest->getSubdomain());
|
|
|
@@ -139,6 +142,23 @@ class OrganizationFactory
|
|
|
$this->logger->debug(" - Director access created");
|
|
|
}
|
|
|
|
|
|
+ $subdomain = new Subdomain();
|
|
|
+ $subdomain->setSubdomain($organizationCreationRequest->getSubdomain());
|
|
|
+ $subdomain->setOrganization($organization);
|
|
|
+ $subdomain->setActive(true);
|
|
|
+ $this->entityManager->persist($subdomain);
|
|
|
+
|
|
|
+ // <--- 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);
|
|
|
+ // --->
|
|
|
+
|
|
|
+ // Création de la société Dolibarr
|
|
|
+ $dolibarrId = $this->dolibarrApiService->createSociety($organization);
|
|
|
+ $this->logger->info("New dolibarr structure created (uid : " . $dolibarrId . ")");
|
|
|
+
|
|
|
$this->entityManager->persist($organization);
|
|
|
$this->entityManager->flush();
|
|
|
$this->entityManager->commit();
|
|
|
@@ -152,14 +172,6 @@ class OrganizationFactory
|
|
|
throw $e;
|
|
|
}
|
|
|
|
|
|
- // Création et enregistrement du sous-domaine
|
|
|
- $this->subdomainService->addNewSubdomain(
|
|
|
- $organization,
|
|
|
- $organizationCreationRequest->getSubdomain(),
|
|
|
- true
|
|
|
- );
|
|
|
- $this->logger->info("Subdomain created and activated");
|
|
|
-
|
|
|
// Création du site typo3
|
|
|
if ($organizationCreationRequest->getCreateWebsite()) {
|
|
|
$response = $this->typo3Service->createSite($organization->getId());
|
|
|
@@ -174,32 +186,28 @@ class OrganizationFactory
|
|
|
$this->logger->warning("Typo3 website creation was not required");
|
|
|
}
|
|
|
|
|
|
- // Création de la société Dolibarr
|
|
|
- $dolibarrId = $this->dolibarrApiService->createSociety($organization);
|
|
|
- $this->logger->info("New dolibarr structure created (uid : " . $dolibarrId . ")");
|
|
|
+ // Register the subdomain into the BindFile (takes up to 5min to take effect)
|
|
|
+ $this->bindFileService->registerSubdomain($subdomain->getSubdomain());
|
|
|
+ $this->logger->info("Subdomain registered");
|
|
|
|
|
|
return $organization;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Une organisation du même nom existe-t-elle déjà à la même adresse?
|
|
|
+ * Une organisation du même nom existe-t-elle déjà à la même adresse ?
|
|
|
*
|
|
|
* @param OrganizationCreationRequest $organizationCreationRequest
|
|
|
* @return bool
|
|
|
*/
|
|
|
protected function isExistingOrganization(OrganizationCreationRequest $organizationCreationRequest): bool
|
|
|
{
|
|
|
- $results = $this
|
|
|
- -> organizationRepository
|
|
|
- ->findBy(
|
|
|
+ return $this
|
|
|
+ ->organizationRepository
|
|
|
+ ->count(
|
|
|
[
|
|
|
'name' => $organizationCreationRequest->getName(),
|
|
|
- 'streetAddress' => $organizationCreationRequest->getStreetAddress1(),
|
|
|
- 'postalCode' => $organizationCreationRequest->getPostalCode()
|
|
|
]
|
|
|
- );
|
|
|
-
|
|
|
- return count($results) > 0;
|
|
|
+ ) > 0;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -236,6 +244,7 @@ class OrganizationFactory
|
|
|
$organization = new Organization();
|
|
|
$organization->setName($organizationCreationRequest->getName());
|
|
|
$organization->setLegalStatus($organizationCreationRequest->getLegalStatus());
|
|
|
+ $organization->setPrincipalType($organizationCreationRequest->getPrincipalType());
|
|
|
|
|
|
$this->entityManager->persist($organization);
|
|
|
|