|
|
@@ -6,10 +6,8 @@ use App\ApiResources\Organization\OrganizationCreationRequest;
|
|
|
use App\ApiResources\Organization\OrganizationDeletionRequest;
|
|
|
use App\ApiResources\Organization\OrganizationMemberCreationRequest;
|
|
|
use App\Entity\Access\Access;
|
|
|
-use App\Entity\Billing\BillingSetting;
|
|
|
use App\Entity\Core\AddressPostal;
|
|
|
use App\Entity\Core\ContactPoint;
|
|
|
-use App\Entity\Education\CriteriaNotation;
|
|
|
use App\Entity\Education\Cycle;
|
|
|
use App\Entity\Network\NetworkOrganization;
|
|
|
use App\Entity\Organization\Organization;
|
|
|
@@ -28,18 +26,17 @@ use App\Repository\Core\CountryRepository;
|
|
|
use App\Repository\Organization\OrganizationRepository;
|
|
|
use App\Repository\Person\PersonRepository;
|
|
|
use App\Service\Dolibarr\DolibarrApiService;
|
|
|
+use App\Service\Organization\Utils as OrganizationUtils;
|
|
|
use App\Service\Typo3\BindFileService;
|
|
|
use App\Service\Typo3\SubdomainService;
|
|
|
use App\Service\Typo3\Typo3Service;
|
|
|
use App\Service\Utils\DatesUtils;
|
|
|
-use Doctrine\Common\Collections\Collection;
|
|
|
+use App\Service\Utils\SecurityUtils;
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
use Elastica\Param;
|
|
|
-use Exception;
|
|
|
use libphonenumber\NumberParseException;
|
|
|
use libphonenumber\PhoneNumberUtil;
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
-use SebastianBergmann\Type\RuntimeException;
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
use Symfony\Component\String\ByteString;
|
|
|
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
|
|
@@ -47,24 +44,23 @@ use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
|
|
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
|
|
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
|
|
use Symfony\Contracts\Service\Attribute\Required;
|
|
|
-use Throwable;
|
|
|
-use App\Service\Organization\Utils as OrganizationUtils;
|
|
|
|
|
|
class OrganizationFactory
|
|
|
{
|
|
|
private LoggerInterface $logger;
|
|
|
|
|
|
public function __construct(
|
|
|
- private readonly SubdomainService $subdomainService,
|
|
|
+ private readonly SubdomainService $subdomainService,
|
|
|
private readonly OrganizationRepository $organizationRepository,
|
|
|
- private readonly CountryRepository $countryRepository,
|
|
|
- private readonly OrganizationUtils $organizationUtils,
|
|
|
- private readonly Typo3Service $typo3Service,
|
|
|
- private readonly DolibarrApiService $dolibarrApiService,
|
|
|
+ private readonly CountryRepository $countryRepository,
|
|
|
+ private readonly OrganizationUtils $organizationUtils,
|
|
|
+ private readonly Typo3Service $typo3Service,
|
|
|
+ private readonly DolibarrApiService $dolibarrApiService,
|
|
|
private readonly EntityManagerInterface $entityManager,
|
|
|
- private readonly PersonRepository $personRepository,
|
|
|
- private readonly BindFileService $bindFileService,
|
|
|
- ) {}
|
|
|
+ private readonly PersonRepository $personRepository,
|
|
|
+ private readonly BindFileService $bindFileService,
|
|
|
+ ) {
|
|
|
+ }
|
|
|
|
|
|
#[Required]
|
|
|
/** @see https://symfony.com/doc/current/logging/channels_handlers.html#how-to-autowire-logger-channels */
|
|
|
@@ -74,17 +70,15 @@ class OrganizationFactory
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Créé une nouvelle organisation à partir des données contenues dans une OrganizationCreationRequest
|
|
|
+ * Créé une nouvelle organisation à partir des données contenues dans une OrganizationCreationRequest.
|
|
|
*
|
|
|
- * @param OrganizationCreationRequest $organizationCreationRequest
|
|
|
- * @return Organization
|
|
|
* @throws TransportExceptionInterface
|
|
|
- * @throws Throwable
|
|
|
+ * @throws \Throwable
|
|
|
*/
|
|
|
public function create(OrganizationCreationRequest $organizationCreationRequest): Organization
|
|
|
{
|
|
|
$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();
|
|
|
@@ -92,16 +86,16 @@ class OrganizationFactory
|
|
|
try {
|
|
|
// On vérifie si cette organisation n'existe pas déjà
|
|
|
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->logger->info("Subdomain is valid and available : '" . $organizationCreationRequest->getSubdomain() . "'");
|
|
|
+ $this->logger->info("Subdomain is valid and available : '".$organizationCreationRequest->getSubdomain()."'");
|
|
|
|
|
|
// On construit l'organisation et ses relations
|
|
|
$organization = $this->makeOrganizationWithRelations($organizationCreationRequest);
|
|
|
- $this->logger->info("Organization created with all its relations");
|
|
|
+ $this->logger->info('Organization created with all its relations');
|
|
|
|
|
|
// On persiste et on commit
|
|
|
$this->entityManager->persist($organization);
|
|
|
@@ -112,28 +106,27 @@ class OrganizationFactory
|
|
|
$organization,
|
|
|
$organizationCreationRequest->isClient()
|
|
|
);
|
|
|
- $this->logger->info("New dolibarr structure created (uid : " . $dolibarrId . ")");
|
|
|
+ $this->logger->info('New dolibarr structure created (uid : '.$dolibarrId.')');
|
|
|
|
|
|
$this->entityManager->commit();
|
|
|
- $this->logger->debug(" - New entities committed in DB");
|
|
|
-
|
|
|
- $this->logger->info("Organization persisted in the DB");
|
|
|
+ $this->logger->debug(' - New entities committed in DB');
|
|
|
|
|
|
+ $this->logger->info('Organization persisted in the DB');
|
|
|
} catch (\Exception $e) {
|
|
|
- $this->logger->critical("An error happened, operation cancelled\n" . $e);
|
|
|
+ $this->logger->critical("An error happened, operation cancelled\n".$e);
|
|
|
$this->entityManager->rollback();
|
|
|
throw $e;
|
|
|
}
|
|
|
|
|
|
// Register the subdomain into the BindFile (takes up to 5min to take effect)
|
|
|
$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)
|
|
|
if ($organizationCreationRequest->getCreateWebsite()) {
|
|
|
$this->createTypo3Website($organization);
|
|
|
} else {
|
|
|
- $this->logger->warning("Typo3 website creation was not required");
|
|
|
+ $this->logger->warning('Typo3 website creation was not required');
|
|
|
}
|
|
|
|
|
|
return $organization;
|
|
|
@@ -141,9 +134,6 @@ class OrganizationFactory
|
|
|
|
|
|
/**
|
|
|
* 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
|
|
|
{
|
|
|
@@ -157,24 +147,22 @@ class OrganizationFactory
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Vérifie la disponibilité et la validité d'un sous domaine
|
|
|
+ * Vérifie la disponibilité et la validité d'un sous domaine.
|
|
|
*
|
|
|
- * @param string $subdomainValue
|
|
|
- * @return void
|
|
|
* @throws \Exception
|
|
|
*/
|
|
|
protected function validateSubdomain(string $subdomainValue): void
|
|
|
{
|
|
|
if (!$this->subdomainService->isValidSubdomain($subdomainValue)) {
|
|
|
- throw new \RuntimeException("Not a valid subdomain : " . $subdomainValue);
|
|
|
+ throw new \RuntimeException('Not a valid subdomain : '.$subdomainValue);
|
|
|
}
|
|
|
|
|
|
if ($this->subdomainService->isReservedSubdomain($subdomainValue)) {
|
|
|
- throw new \RuntimeException("This subdomain is not available : " . $subdomainValue);
|
|
|
+ throw new \RuntimeException('This subdomain is not available : '.$subdomainValue);
|
|
|
}
|
|
|
|
|
|
if ($this->subdomainService->isRegistered($subdomainValue)) {
|
|
|
- throw new \RuntimeException("This subdomain is already registered : " . $subdomainValue);
|
|
|
+ throw new \RuntimeException('This subdomain is already registered : '.$subdomainValue);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -182,60 +170,57 @@ 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
|
|
|
+ * @throws \Throwable
|
|
|
*/
|
|
|
protected function makeOrganizationWithRelations(
|
|
|
- OrganizationCreationRequest $organizationCreationRequest
|
|
|
- ): Organization
|
|
|
- {
|
|
|
+ OrganizationCreationRequest $organizationCreationRequest,
|
|
|
+ ): Organization {
|
|
|
// Création de l'organisation
|
|
|
$organization = $this->makeOrganization($organizationCreationRequest);
|
|
|
- $this->logger->debug(" - Organization created");
|
|
|
+ $this->logger->debug(' - Organization created');
|
|
|
|
|
|
// Création des Parameters
|
|
|
$parameters = $this->makeParameters($organizationCreationRequest);
|
|
|
$organization->setParameters($parameters);
|
|
|
- $this->logger->debug(" - Parameters created");
|
|
|
+ $this->logger->debug(' - Parameters created');
|
|
|
|
|
|
// Création des Settings
|
|
|
$settings = $this->makeSettings($organizationCreationRequest);
|
|
|
$organization->setSettings($settings);
|
|
|
- $this->logger->debug(" - Settings created");
|
|
|
+ $this->logger->debug(' - Settings created');
|
|
|
|
|
|
// Création de l'adresse postale
|
|
|
$organizationAddressPostal = $this->makePostalAddress($organizationCreationRequest);
|
|
|
$organization->addOrganizationAddressPostal($organizationAddressPostal);
|
|
|
- $this->logger->debug(" - OrganizationAddressPostal created");
|
|
|
+ $this->logger->debug(' - OrganizationAddressPostal created');
|
|
|
|
|
|
// Création du point de contact
|
|
|
$contactPoint = $this->makeContactPoint($organizationCreationRequest);
|
|
|
$organization->addContactPoint($contactPoint);
|
|
|
- $this->logger->debug(" - ContactPoint created");
|
|
|
+ $this->logger->debug(' - ContactPoint created');
|
|
|
|
|
|
// Rattachement au réseau
|
|
|
$networkOrganization = $this->makeNetworkOrganization($organizationCreationRequest);
|
|
|
$organization->addNetworkOrganization($networkOrganization);
|
|
|
- $this->logger->debug(" - NetworkOrganization created");
|
|
|
+ $this->logger->debug(' - NetworkOrganization created');
|
|
|
|
|
|
// Créé l'admin
|
|
|
$adminAccess = $this->makeAdminAccess($organizationCreationRequest);
|
|
|
$organization->addAccess($adminAccess);
|
|
|
- $this->logger->debug(" - Admin access created");
|
|
|
+ $this->logger->debug(' - Admin access created');
|
|
|
|
|
|
// Création des cycles
|
|
|
foreach ($this->makeCycles() as $cycle) {
|
|
|
$organization->addCycle($cycle);
|
|
|
}
|
|
|
- $this->logger->debug(" - Cycles created");
|
|
|
+ $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");
|
|
|
+ $this->logger->debug(' - President access created');
|
|
|
}
|
|
|
|
|
|
// Création du directeur (si renseigné)
|
|
|
@@ -243,7 +228,7 @@ class OrganizationFactory
|
|
|
if ($directorCreationRequest !== null) {
|
|
|
$directorAccess = $this->makeAccess($directorCreationRequest);
|
|
|
$organization->addAccess($directorAccess);
|
|
|
- $this->logger->debug(" - Director access created");
|
|
|
+ $this->logger->debug(' - Director access created');
|
|
|
}
|
|
|
|
|
|
// Création du sous-domaine
|
|
|
@@ -253,19 +238,16 @@ class OrganizationFactory
|
|
|
// <--- 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');
|
|
|
+ $parameters->setOtherWebsite('https://'.$organizationCreationRequest->getSubdomain().'.opentalent.fr');
|
|
|
$this->entityManager->persist($parameters);
|
|
|
// --->
|
|
|
- $this->logger->debug(" - Subdomain created");
|
|
|
+ $this->logger->debug(' - Subdomain created');
|
|
|
|
|
|
return $organization;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Créé une nouvelle instance d'organisation
|
|
|
- *
|
|
|
- * @param OrganizationCreationRequest $organizationCreationRequest
|
|
|
- * @return Organization
|
|
|
+ * Créé une nouvelle instance d'organisation.
|
|
|
*/
|
|
|
protected function makeOrganization(OrganizationCreationRequest $organizationCreationRequest): Organization
|
|
|
{
|
|
|
@@ -282,40 +264,44 @@ class OrganizationFactory
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Create a new Parameters object from the data in an OrganizationCreationRequest
|
|
|
+ * Create a new Parameters object from the data in an OrganizationCreationRequest.
|
|
|
*
|
|
|
* @param OrganizationCreationRequest $organizationCreationRequest The organization creation request
|
|
|
+ *
|
|
|
* @return Parameters The created Parameters object
|
|
|
- * @throws Throwable If there is an error
|
|
|
+ *
|
|
|
+ * @throws \Throwable If there is an error
|
|
|
*/
|
|
|
protected function makeParameters(OrganizationCreationRequest $organizationCreationRequest): Parameters
|
|
|
{
|
|
|
$parameters = new Parameters();
|
|
|
$this->entityManager->persist($parameters);
|
|
|
+
|
|
|
return $parameters;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Creates a new instance of the Settings class based on the given OrganizationCreationRequest object.
|
|
|
*
|
|
|
- * @param OrganizationCreationRequest $organizationCreationRequest The OrganizationCreationRequest object containing the required data.
|
|
|
+ * @param OrganizationCreationRequest $organizationCreationRequest the OrganizationCreationRequest object containing the required data
|
|
|
*
|
|
|
- * @return Settings The newly created instance of the Settings class.
|
|
|
+ * @return Settings the newly created instance of the Settings class
|
|
|
*/
|
|
|
protected function makeSettings(OrganizationCreationRequest $organizationCreationRequest): Settings
|
|
|
{
|
|
|
$settings = new Settings();
|
|
|
$settings->setProduct($organizationCreationRequest->getProduct());
|
|
|
$this->entityManager->persist($settings);
|
|
|
+
|
|
|
return $settings;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Creates a new instance of the OrganizationAddressPostal class based on the given OrganizationCreationRequest object.
|
|
|
*
|
|
|
- * @param OrganizationCreationRequest $organizationCreationRequest The OrganizationCreationRequest object containing the required data.
|
|
|
+ * @param OrganizationCreationRequest $organizationCreationRequest the OrganizationCreationRequest object containing the required data
|
|
|
*
|
|
|
- * @return OrganizationAddressPostal The newly created instance of the OrganizationAddressPostal class.
|
|
|
+ * @return OrganizationAddressPostal the newly created instance of the OrganizationAddressPostal class
|
|
|
*/
|
|
|
protected function makePostalAddress(OrganizationCreationRequest $organizationCreationRequest): OrganizationAddressPostal
|
|
|
{
|
|
|
@@ -340,9 +326,10 @@ class OrganizationFactory
|
|
|
/**
|
|
|
* Creates a new instance of the ContactPoint class based on the given OrganizationCreationRequest object.
|
|
|
*
|
|
|
- * @param OrganizationCreationRequest $organizationCreationRequest The OrganizationCreationRequest object containing the required data.
|
|
|
+ * @param OrganizationCreationRequest $organizationCreationRequest the OrganizationCreationRequest object containing the required data
|
|
|
+ *
|
|
|
+ * @return ContactPoint the newly created instance of the ContactPoint class
|
|
|
*
|
|
|
- * @return ContactPoint The newly created instance of the ContactPoint class.
|
|
|
* @throws NumberParseException
|
|
|
*/
|
|
|
protected function makeContactPoint(OrganizationCreationRequest $organizationCreationRequest): ContactPoint
|
|
|
@@ -362,22 +349,22 @@ class OrganizationFactory
|
|
|
/**
|
|
|
* Creates a new instance of the NetworkOrganization class based on the given OrganizationCreationRequest object.
|
|
|
*
|
|
|
- * @param OrganizationCreationRequest $organizationCreationRequest The OrganizationCreationRequest object containing the required data.
|
|
|
+ * @param OrganizationCreationRequest $organizationCreationRequest the OrganizationCreationRequest object containing the required data
|
|
|
*
|
|
|
- * @return NetworkOrganization The newly created instance of the NetworkOrganization class.
|
|
|
+ * @return NetworkOrganization the newly created instance of the NetworkOrganization class
|
|
|
*
|
|
|
- * @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.
|
|
|
+ * @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
|
|
|
*/
|
|
|
protected function makeNetworkOrganization(OrganizationCreationRequest $organizationCreationRequest): NetworkOrganization
|
|
|
{
|
|
|
$parent = $this->organizationRepository->find($organizationCreationRequest->getParentId());
|
|
|
if (!$parent) {
|
|
|
- throw new \RuntimeException('No parent organization found for id ' . $organizationCreationRequest->getParentId());
|
|
|
+ throw new \RuntimeException('No parent organization found for id '.$organizationCreationRequest->getParentId());
|
|
|
}
|
|
|
|
|
|
$networkOrganization = $this->organizationUtils->getActiveNetworkOrganization($parent);
|
|
|
if (!$networkOrganization) {
|
|
|
- throw new \RuntimeException('No network found for parent ' . $organizationCreationRequest->getParentId());
|
|
|
+ throw new \RuntimeException('No network found for parent '.$organizationCreationRequest->getParentId());
|
|
|
}
|
|
|
|
|
|
$network = $networkOrganization->getNetwork();
|
|
|
@@ -385,7 +372,7 @@ class OrganizationFactory
|
|
|
// Si réseau CMF, on vérifie que le matricule est valide
|
|
|
if ($network->getId() === NetworkEnum::CMF->value) {
|
|
|
if (!preg_match("/FR\d{12}/", $organizationCreationRequest->getIdentifier())) {
|
|
|
- throw new \RuntimeException("CMF identifier is missing or invalid.");
|
|
|
+ throw new \RuntimeException('CMF identifier is missing or invalid.');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -401,14 +388,14 @@ class OrganizationFactory
|
|
|
/**
|
|
|
* Creates a new instance of the Access class with admin access based on the given OrganizationCreationRequest object.
|
|
|
*
|
|
|
- * @param OrganizationCreationRequest $organizationCreationRequest The OrganizationCreationRequest object containing the required data.
|
|
|
+ * @param OrganizationCreationRequest $organizationCreationRequest the OrganizationCreationRequest object containing the required data
|
|
|
*
|
|
|
- * @return Access The newly created instance of the Access class with admin access.
|
|
|
+ * @return Access the newly created instance of the Access class with admin access
|
|
|
*/
|
|
|
protected function makeAdminAccess(OrganizationCreationRequest $organizationCreationRequest): Access
|
|
|
{
|
|
|
$admin = new Person();
|
|
|
- $admin->setUsername('admin' . strtolower($organizationCreationRequest->getSubdomain()));
|
|
|
+ $admin->setUsername('admin'.strtolower($organizationCreationRequest->getSubdomain()));
|
|
|
$randomString = ByteString::fromRandom(32)->toString();
|
|
|
$admin->setPassword($randomString);
|
|
|
$this->entityManager->persist($admin);
|
|
|
@@ -424,7 +411,7 @@ class OrganizationFactory
|
|
|
/**
|
|
|
* Creates an array of Cycle objects based on a predefined set of data.
|
|
|
*
|
|
|
- * @return Cycle[] An array of Cycle objects.
|
|
|
+ * @return Cycle[] an array of Cycle objects
|
|
|
*/
|
|
|
protected function makeCycles(): array
|
|
|
{
|
|
|
@@ -455,16 +442,17 @@ class OrganizationFactory
|
|
|
/**
|
|
|
* Creates an Access object based on the given OrganizationMemberCreationRequest.
|
|
|
*
|
|
|
- * @param int|OrganizationMemberCreationRequest $creationRequestData The request object containing the
|
|
|
+ * @param int|OrganizationMemberCreationRequest $creationRequestData the request object containing the
|
|
|
* necessary data for creating a Person object,
|
|
|
- * or the id of an existing one.
|
|
|
- * @return Access The created Access object.
|
|
|
+ * or the id of an existing one
|
|
|
+ *
|
|
|
+ * @return Access the created Access object
|
|
|
+ *
|
|
|
* @throws NumberParseException
|
|
|
*/
|
|
|
protected function makeAccess(
|
|
|
- int | OrganizationMemberCreationRequest $creationRequestData
|
|
|
- ): Access
|
|
|
- {
|
|
|
+ int|OrganizationMemberCreationRequest $creationRequestData,
|
|
|
+ ): Access {
|
|
|
if (is_int($creationRequestData)) {
|
|
|
$person = $this->personRepository->find($creationRequestData);
|
|
|
} else {
|
|
|
@@ -499,10 +487,11 @@ class OrganizationFactory
|
|
|
/**
|
|
|
* Creates a PersonAddressPostal object based on the given OrganizationMemberCreationRequest.
|
|
|
*
|
|
|
- * @param OrganizationMemberCreationRequest $organizationMemberCreationRequest The request object containing the
|
|
|
+ * @param OrganizationMemberCreationRequest $organizationMemberCreationRequest the request object containing the
|
|
|
* necessary data for creating a
|
|
|
- * PersonAddressPostal object.
|
|
|
- * @return PersonAddressPostal The created PersonAddressPostal object.
|
|
|
+ * PersonAddressPostal object
|
|
|
+ *
|
|
|
+ * @return PersonAddressPostal the created PersonAddressPostal object
|
|
|
*/
|
|
|
protected function makePersonPostalAddress(OrganizationMemberCreationRequest $organizationMemberCreationRequest): PersonAddressPostal
|
|
|
{
|
|
|
@@ -528,9 +517,10 @@ class OrganizationFactory
|
|
|
/**
|
|
|
* Creates a new instance of the ContactPoint class based on the given OrganizationCreationRequest object.
|
|
|
*
|
|
|
- * @param OrganizationMemberCreationRequest $organizationMemberCreationRequest The OrganizationMemberCreationRequest object containing the required data.
|
|
|
+ * @param OrganizationMemberCreationRequest $organizationMemberCreationRequest the OrganizationMemberCreationRequest object containing the required data
|
|
|
+ *
|
|
|
+ * @return ContactPoint the newly created instance of the ContactPoint class
|
|
|
*
|
|
|
- * @return ContactPoint The newly created instance of the ContactPoint class.
|
|
|
* @throws NumberParseException
|
|
|
*/
|
|
|
protected function makePersonContactPoint(OrganizationMemberCreationRequest $organizationMemberCreationRequest): ContactPoint
|
|
|
@@ -549,6 +539,7 @@ class OrganizationFactory
|
|
|
}
|
|
|
|
|
|
$this->entityManager->persist($contactPoint);
|
|
|
+
|
|
|
return $contactPoint;
|
|
|
}
|
|
|
|
|
|
@@ -563,14 +554,15 @@ class OrganizationFactory
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Créé le site Typo3 et retourne l'id de la page racine du site nouvellement créé, ou null en cas d'erreur
|
|
|
+ * 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 {
|
|
|
+ protected function createTypo3Website(Organization $organization): ?int
|
|
|
+ {
|
|
|
$response = $this->typo3Service->createSite($organization->getId());
|
|
|
$rootPageUid = json_decode($response->getContent(), true);
|
|
|
|
|
|
@@ -590,25 +582,23 @@ class OrganizationFactory
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * /!\ Danger zone /!\
|
|
|
+ * /!\ Danger zone /!\.
|
|
|
*
|
|
|
* Supprime définitivement une organisation, ses données, ses fichiers, son site internet, et son profil Dolibarr.
|
|
|
*
|
|
|
* Pour éviter une suppression accidentelle, cette méthode ne doit pouvoir être exécutée que si la requête a été
|
|
|
* envoyée depuis le localhost.
|
|
|
*
|
|
|
- * @param OrganizationDeletionRequest $organizationDeletionRequest
|
|
|
- * @return OrganizationDeletionRequest
|
|
|
- * @throws Exception
|
|
|
+ * @throws \Exception
|
|
|
*/
|
|
|
public function delete(OrganizationDeletionRequest $organizationDeletionRequest): OrganizationDeletionRequest
|
|
|
{
|
|
|
- $this->preventIfNotLocalhost();
|
|
|
+ SecurityUtils::preventIfNotLocalhost();
|
|
|
|
|
|
$organization = $this->organizationRepository->find($organizationDeletionRequest->getOrganizationId());
|
|
|
|
|
|
$this->logger->info(
|
|
|
- "Start the deletion of organization '" . $organization->getName() . "' [" . $organization->getId() . "]"
|
|
|
+ "Start the deletion of organization '".$organization->getName()."' [".$organization->getId().']'
|
|
|
);
|
|
|
|
|
|
$this->entityManager->beginTransaction();
|
|
|
@@ -629,7 +619,7 @@ class OrganizationFactory
|
|
|
$this->entityManager->flush();
|
|
|
$this->entityManager->commit();
|
|
|
} catch (\Exception $e) {
|
|
|
- $this->logger->critical("An error happened, operation cancelled\n" . $e);
|
|
|
+ $this->logger->critical("An error happened, operation cancelled\n".$e);
|
|
|
$this->entityManager->rollback();
|
|
|
throw $e;
|
|
|
}
|
|
|
@@ -637,15 +627,15 @@ class OrganizationFactory
|
|
|
try {
|
|
|
$this->deleteTypo3Website($organization);
|
|
|
} catch (\Exception $e) {
|
|
|
- $this->logger->critical("An error happened while deleting the Typo3 website, please proceed manually.");
|
|
|
+ $this->logger->critical('An error happened while deleting the Typo3 website, please proceed manually.');
|
|
|
$this->logger->debug($e);
|
|
|
$withError = true;
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- $this->deleteDolibarrSociety($organization);
|
|
|
+ $this->switchDolibarrSocietyToProspect($organization);
|
|
|
} catch (\Exception $e) {
|
|
|
- $this->logger->critical("An error happened while deleting the Dolibarr society, please proceed manually.");
|
|
|
+ $this->logger->critical('An error happened while updating the Dolibarr society, please proceed manually.');
|
|
|
$this->logger->debug($e);
|
|
|
$withError = true;
|
|
|
}
|
|
|
@@ -653,7 +643,7 @@ class OrganizationFactory
|
|
|
try {
|
|
|
$this->deleteLocalDirectories($organization);
|
|
|
} catch (\Exception $e) {
|
|
|
- $this->logger->critical("An error happened while deleting the local directories, please proceed manually.");
|
|
|
+ $this->logger->critical('An error happened while deleting the local directories, please proceed manually.');
|
|
|
$this->logger->debug($e);
|
|
|
$withError = true;
|
|
|
}
|
|
|
@@ -661,7 +651,7 @@ class OrganizationFactory
|
|
|
try {
|
|
|
$this->deleteDirectoriesV1($organization);
|
|
|
} catch (\Exception $e) {
|
|
|
- $this->logger->critical("An error happened while deleting the V1 directories, please proceed manually.");
|
|
|
+ $this->logger->critical('An error happened while deleting the V1 directories, please proceed manually.');
|
|
|
$this->logger->debug($e);
|
|
|
$withError = true;
|
|
|
}
|
|
|
@@ -669,14 +659,14 @@ class OrganizationFactory
|
|
|
try {
|
|
|
$this->deleteDirectories59($organization);
|
|
|
} catch (\Exception $e) {
|
|
|
- $this->logger->critical("An error happened while deleting the 5.9 directories, please proceed manually.");
|
|
|
+ $this->logger->critical('An error happened while deleting the 5.9 directories, please proceed manually.');
|
|
|
$this->logger->debug($e);
|
|
|
$withError = true;
|
|
|
}
|
|
|
|
|
|
if ($withError) {
|
|
|
$organizationDeletionRequest->setStatus(OrganizationDeletionRequest::STATUS_OK_WITH_ERRORS);
|
|
|
- $this->logger->warning("-- Operation ended with errors, check the logs for more information --");
|
|
|
+ $this->logger->warning('-- Operation ended with errors, check the logs for more information --');
|
|
|
} else {
|
|
|
$organizationDeletionRequest->setStatus(OrganizationDeletionRequest::STATUS_OK);
|
|
|
}
|
|
|
@@ -684,29 +674,9 @@ class OrganizationFactory
|
|
|
return $organizationDeletionRequest;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Lève une exception si la méthode a été appelée dans le cadre d'un appel API originaire d'un hôte
|
|
|
- * différent de localhost.
|
|
|
- *
|
|
|
- * @return void
|
|
|
- */
|
|
|
- protected function preventIfNotLocalhost(): void
|
|
|
- {
|
|
|
- if (
|
|
|
- $_SERVER &&
|
|
|
- $_SERVER['APP_ENV'] !== 'docker' &&
|
|
|
- $_SERVER['SERVER_ADDR'] !== $_SERVER['REMOTE_ADDR']
|
|
|
- ) {
|
|
|
- throw new \RuntimeException("This operation is restricted to localhost");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Supprime tous les Access d'une organisation, ainsi que la Person
|
|
|
- * rattachée (si celle-ci n'est pas liée à d'autres Access)
|
|
|
- *
|
|
|
- * @param Organization $organization
|
|
|
- * @return void
|
|
|
+ * rattachée (si celle-ci n'est pas liée à d'autres Access).
|
|
|
*/
|
|
|
protected function deleteOrganizationAccesses(Organization $organization): void
|
|
|
{
|
|
|
@@ -720,36 +690,36 @@ class OrganizationFactory
|
|
|
}
|
|
|
|
|
|
// TODO: à revoir, c'est du many to many
|
|
|
-// protected function removeTypeOfPractices(Organization $organization): void {
|
|
|
-// foreach ($organization->getTypeOfPractices() as $typeOfPractice) {
|
|
|
-// $organization->removeTypeOfPractice($typeOfPractice);
|
|
|
-// }
|
|
|
-// }
|
|
|
+ // protected function removeTypeOfPractices(Organization $organization): void {
|
|
|
+ // foreach ($organization->getTypeOfPractices() as $typeOfPractice) {
|
|
|
+ // $organization->removeTypeOfPractice($typeOfPractice);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
|
|
|
// TODO: à revoir, c'est du many to many
|
|
|
-// protected function deleteContactPoints(Organization $organization): void
|
|
|
-// {
|
|
|
-// foreach ($organization->getContactPoints() as $contactPoint) {
|
|
|
-// $this->entityManager->remove($contactPoint);
|
|
|
-// }
|
|
|
-// }
|
|
|
+ // protected function deleteContactPoints(Organization $organization): void
|
|
|
+ // {
|
|
|
+ // foreach ($organization->getContactPoints() as $contactPoint) {
|
|
|
+ // $this->entityManager->remove($contactPoint);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
|
|
|
// TODO: à revoir, c'est du many to many
|
|
|
-// protected function deleteBankAccounts(Organization $organization): void {
|
|
|
-// foreach ($organization->getBankAccounts() as $bankAccount) {
|
|
|
-// $this->entityManager->remove($bankAccount);
|
|
|
-// }
|
|
|
-// }
|
|
|
+ // protected function deleteBankAccounts(Organization $organization): void {
|
|
|
+ // foreach ($organization->getBankAccounts() as $bankAccount) {
|
|
|
+ // $this->entityManager->remove($bankAccount);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
|
|
|
protected function deleteTypo3Website(Organization $organization): void
|
|
|
{
|
|
|
// TODO: implement
|
|
|
-// $this->typo3Service->deleteSite($organization->getId());
|
|
|
+ // $this->typo3Service->deleteSite($organization->getId());
|
|
|
}
|
|
|
|
|
|
- protected function deleteDolibarrSociety(Organization $organization): void
|
|
|
+ protected function switchDolibarrSocietyToProspect(Organization $organization): void
|
|
|
{
|
|
|
- // TODO: implement
|
|
|
+ $this->dolibarrApiService->switchSocietyToProspect($organization->getId());
|
|
|
}
|
|
|
|
|
|
protected function deleteLocalDirectories(Organization $organization): void
|