Browse Source

add Typo3Service

Olivier Massot 3 years ago
parent
commit
62a3226d9d

+ 4 - 0
.env.ci

@@ -27,6 +27,10 @@ BLACKFIRE_SERVER_TOKEN=dbd1cfbea015fe83cccfc189a36ca3c16f3a1b43b94f50032a15e41e5
 DATABASE_ADMINASSOS_URL=mysql://root:xxx@preprod:3306/none?serverVersion=5.7
 ###< AdminAssos configuration ###
 
+###> typo3 client ###
+TYPO3_BASE_URI=http://docker.sub.opentalent.fr
+###< typo3 client ###
+
 ###> dolibarr client ###
 DOLIBARR_API_BASE_URI='https://dev-erp.2iopenservice.com/api/index.php/'
 ###< dolibarr client ###

+ 4 - 0
.env.preprod

@@ -16,6 +16,10 @@ DATABASE_URL=mysql://root:mysql2iopenservice369566@preprod:3306/opentalent?serve
 CORS_ALLOW_ORIGIN=^https?://(localhost|127\.0\.0\.1)(:[0-9]+)$
 ###< nelmio/cors-bundle ###
 
+###> typo3 client ###
+TYPO3_BASE_URI=http://preprod.opentalent.fr/ohcluses
+###< typo3 client ###
+
 ###> BlackFire configuration ###
 BLACKFIRE_CLIENT_ID=988fcba8-552d-48df-a9c2-035c76535b69
 BLACKFIRE_CLIENT_TOKEN=8cfbeb263d044da9678dc2612531504da3790c308da7448e35724a5da91c136f

+ 4 - 0
.env.prod

@@ -23,6 +23,10 @@ BLACKFIRE_SERVER_ID=1171e53b-459b-41da-a292-80ff68cee8c2
 BLACKFIRE_SERVER_TOKEN=dbd1cfbea015fe83cccfc189a36ca3c16f3a1b43b94f50032a15e41e53548e8b
 ###< BlackFire configuration ###
 
+###> typo3 client ###
+TYPO3_BASE_URI=http://ohcluses.opentalent.fr
+###< typo3 client ###
+
 ###> AdminAssos configuration ###
 DATABASE_ADMINASSOS_URL=mysql://root:mysql2iopenservice369566@prod-back:3306/adminassos?serverVersion=5.7
 ###< AdminAssos configuration ###

+ 4 - 0
.env.test

@@ -4,6 +4,10 @@ APP_SECRET='$ecretf0rt3st'
 SYMFONY_DEPRECATIONS_HELPER=999999
 PANTHER_APP_ENV=panther
 
+###> typo3 client ###
+TYPO3_BASE_URI=http://test.opentalent.fr/ohcluses
+###< typo3 client ###
+
 ###> dolibarr client ###
 DOLIBARR_API_BASE_URI='https://dev-erp.2iopenservice.com/api/index.php/'
 ###< dolibarr client ###

+ 5 - 0
config/packages/framework.yaml

@@ -27,6 +27,11 @@ framework:
                 headers:
                     DOLAPIKEY: '%env(DOLIBARR_API_TOKEN)%'
                     Accept: 'application/json'
+            typo3_client:
+                base_uri: '%env(TYPO3_BASE_URI)%'
+                headers:
+                    Content-Type: 'application/json'
+                    Accept: 'application/json'
             mobyt_client:
                 base_uri: '%env(MOBYT_API_BASE_URI)%'
                 headers:

+ 26 - 0
src/DataPersister/BaseDataPersister.php

@@ -0,0 +1,26 @@
+<?php
+
+namespace App\DataPersister;
+
+use ApiPlatform\Core\DataPersister\ContextAwareDataPersisterInterface;
+
+class ContextAwareDataPersister implements ContextAwareDataPersisterInterface
+{
+    public function __construct(
+        private ContextAwareDataPersisterInterface $decorated,
+    )
+    { }
+
+    public function supports($data, array $context = []): bool
+    {
+        return false;
+    }
+
+    public function persist($data, array $context = [])
+    {
+    }
+
+    public function remove($data, array $context = [])
+    {
+    }
+}

+ 70 - 0
src/DataPersister/Organization/SubdomainDataPersister.php

@@ -0,0 +1,70 @@
+<?php
+declare(strict_types=1);
+
+namespace App\DataPersister\Organization;
+
+use ApiPlatform\Core\DataPersister\ContextAwareDataPersisterInterface;
+use App\Entity\Organization\Parameters;
+use App\Message\Command\Parameters\AverageChange;
+use App\Service\OnChange\Organization\OnParametersChange;
+use Exception;
+use Symfony\Component\Messenger\MessageBusInterface;
+
+/**
+ * Classe ParametersDataPersister qui est un custom dataPersister gérant la resource Parameters
+ */
+class ParametersDataPersister implements ContextAwareDataPersisterInterface
+{
+    public function __construct(
+        private ContextAwareDataPersisterInterface $decorated,
+        private MessageBusInterface $messageBus,
+        private OnParametersChange $onParametersChange
+    )
+    { }
+
+    public function supports($data, array $context = []): bool
+    {
+        return $data instanceof Parameters;
+    }
+
+    /**
+     * @param Parameters $data
+     * @param array $context
+     * @return object|void
+     */
+    public function persist($data, array $context = [])
+    {
+        $this->prePersist($context['previous_data'], $data);
+
+        $result = $this->decorated->persist($data, $context);
+
+        $this->postPersist($context['previous_data'], $data);
+
+        return $result;
+    }
+
+    public function remove($data, array $context = [])
+    {
+        throw new Exception('not supported', 500);
+    }
+
+    public function prePersist(Parameters $previousParameters, Parameters $parameters): void{
+        if($previousParameters->getAdvancedEducationNotationType() != $parameters->getAdvancedEducationNotationType()){
+            $this->onParametersChange->onAdvancedEducationNotationTypeChange($parameters);
+        }
+
+        //La date de début d'activité change
+        if($previousParameters->getMusicalDate() != $parameters->getMusicalDate()){
+            $this->onParametersChange->onMusicalDateChange($parameters->getOrganization(), $previousParameters->getMusicalDate());
+        }
+    }
+
+    public function postPersist(Parameters $previousParameters, Parameters $parameters): void{
+        //La note maximale du suivi pédagogique change
+        if($previousParameters->getAverage() != $parameters->getAverage()){
+            $this->messageBus->dispatch(
+                new AverageChange($parameters->getId())
+            );
+        }
+    }
+}

+ 8 - 0
src/Service/Typo3/BindFileService.php

@@ -0,0 +1,8 @@
+<?php
+
+namespace App\Service\Typo3;
+
+class BindFileServic
+{
+
+}

+ 118 - 0
src/Service/Typo3/Typo3Service.php

@@ -0,0 +1,118 @@
+<?php
+
+namespace App\Service\Typo3;
+
+use App\Service\Utils\UrlBuilder;
+use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
+use Symfony\Contracts\HttpClient\HttpClientInterface;
+
+class Typo3Service
+{
+    public function __construct(
+        private HttpClientInterface $typo3_client
+    )
+    {}
+
+    /**
+     * Send a command to the given route of the Typo3 API
+     *
+     * @param string $route
+     * @param array $parameters
+     *
+     * @return \Symfony\Contracts\HttpClient\ResponseInterface
+     * @throws TransportExceptionInterface
+     */
+    private function sendCommand(string $route, array $parameters): \Symfony\Contracts\HttpClient\ResponseInterface
+    {
+        $url = UrlBuilder::concatParameters('/typo3/index.php?route=' . $route, $parameters);
+        return $this->typo3_client->request('GET', $url);
+    }
+
+    /**
+     * Clear the cache of the given organization's website
+     * @throws TransportExceptionInterface
+     */
+    public function clearSiteCache(int $organizationId): \Symfony\Contracts\HttpClient\ResponseInterface
+    {
+        return $this->sendCommand('/otadmin/site/clear-cache', ['organization-id' => $organizationId]);
+    }
+
+    /**
+     * Create a new Typo3 website for the given organization
+     * @throws TransportExceptionInterface
+     */
+    public function createSite(int $organizationId): \Symfony\Contracts\HttpClient\ResponseInterface
+    {
+        return $this->sendCommand('/otadmin/site/create', ['organization-id' => $organizationId]);
+    }
+
+    /**
+     * Update the given organization's website with the Opentalent DB data
+     * @throws TransportExceptionInterface
+     */
+    public function updateSite(int $organizationId): \Symfony\Contracts\HttpClient\ResponseInterface
+    {
+        return $this->sendCommand('/otadmin/site/update', ['organization-id' => $organizationId]);
+    }
+
+    /**
+     * Mark the given organization's website as deleted. This can be reverted with 'undeleteSite'
+     * @throws TransportExceptionInterface
+     */
+    public function deleteSite(int $organizationId): \Symfony\Contracts\HttpClient\ResponseInterface
+    {
+        return $this->sendCommand('/otadmin/site/delete', ['organization-id' => $organizationId]);
+    }
+
+    /**
+     * Restore a website that has been deleted with 'deleteSite'
+     * @throws TransportExceptionInterface
+     */
+    public function undeleteSite(int $organizationId): \Symfony\Contracts\HttpClient\ResponseInterface
+    {
+        return $this->sendCommand('/otadmin/site/undelete', ['organization-id' => $organizationId]);
+    }
+
+    /**
+     * Set a custom domain for the given website
+     * @throws TransportExceptionInterface
+     */
+    public function setSiteDomain(int $organizationId, string $newDomain, bool $addRedirection=false): \Symfony\Contracts\HttpClient\ResponseInterface
+    {
+        $params = ['organization-id' => $organizationId, 'domain' => $newDomain];
+        if ($addRedirection) {
+            $params['redirect'] = 1;
+        }
+        return $this->sendCommand('/otadmin/site/set-domain', $params);
+    }
+
+    /**
+     * Reset the permissions of the BE users of the given organization's website
+     * @throws TransportExceptionInterface
+     */
+    public function resetSitePerms(int $organizationId): \Symfony\Contracts\HttpClient\ResponseInterface
+    {
+        return $this->sendCommand('/otadmin/site/reset-perms', ['organization-id' => $organizationId]);
+    }
+
+    /**
+     * Returns the given organization's website status
+     * @throws TransportExceptionInterface
+     */
+    public function getSiteStatus(int $organizationId): \Symfony\Contracts\HttpClient\ResponseInterface
+    {
+        return $this->sendCommand('/otadmin/site/status', ['organization-id' => $organizationId]);
+    }
+
+    /**
+     * Returns the given organization's website status
+     * @throws TransportExceptionInterface
+     */
+    public function addRedirection(string $fromDomain, string $toDomain): \Symfony\Contracts\HttpClient\ResponseInterface
+    {
+        return $this->sendCommand(
+            '/otadmin/redirect/add',
+            ['from-domain' => $fromDomain, 'to-domain' => $toDomain]
+        );
+    }
+}