|
|
@@ -4,23 +4,25 @@ declare(strict_types=1);
|
|
|
namespace App\DataPersister\Organization;
|
|
|
|
|
|
use ApiPlatform\Core\DataPersister\ContextAwareDataPersisterInterface;
|
|
|
+use App\DataPersister\BaseDataPersister;
|
|
|
use App\Entity\Organization\Parameters;
|
|
|
use App\Message\Command\Parameters\AverageChange;
|
|
|
use App\Service\OnChange\Organization\OnParametersChange;
|
|
|
+use App\Service\Typo3\Typo3Service;
|
|
|
use Exception;
|
|
|
use Symfony\Component\Messenger\MessageBusInterface;
|
|
|
|
|
|
/**
|
|
|
* Classe ParametersDataPersister qui est un custom dataPersister gérant la resource Parameters
|
|
|
*/
|
|
|
-class ParametersDataPersister implements ContextAwareDataPersisterInterface
|
|
|
+class ParametersDataPersister extends BaseDataPersister
|
|
|
{
|
|
|
public function __construct(
|
|
|
- private ContextAwareDataPersisterInterface $decorated,
|
|
|
private MessageBusInterface $messageBus,
|
|
|
- private OnParametersChange $onParametersChange
|
|
|
+ private OnParametersChange $onParametersChange,
|
|
|
+ private Typo3Service $typo3Service
|
|
|
)
|
|
|
- { }
|
|
|
+ {}
|
|
|
|
|
|
public function supports($data, array $context = []): bool
|
|
|
{
|
|
|
@@ -28,43 +30,68 @@ class ParametersDataPersister implements ContextAwareDataPersisterInterface
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param Parameters $data
|
|
|
- * @param array $context
|
|
|
- * @return object|void
|
|
|
+ * @param Parameters $parameters
|
|
|
+ * @throws Exception
|
|
|
*/
|
|
|
- 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()){
|
|
|
+ public function prePersist($parameters): void{
|
|
|
+ if(
|
|
|
+ $this->previousData() &&
|
|
|
+ $this->previousData()->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());
|
|
|
+ if(
|
|
|
+ $this->previousData() &&
|
|
|
+ $this->previousData()->getMusicalDate() != $parameters->getMusicalDate()
|
|
|
+ ){
|
|
|
+ $this->onParametersChange->onMusicalDateChange(
|
|
|
+ $parameters->getOrganization(),
|
|
|
+ $this->previousData()->getMusicalDate()
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public function postPersist(Parameters $previousParameters, Parameters $parameters): void{
|
|
|
+ /**
|
|
|
+ * @param Parameters $parameters
|
|
|
+ */
|
|
|
+ public function postPersist($parameters): void{
|
|
|
//La note maximale du suivi pédagogique change
|
|
|
- if($previousParameters->getAverage() != $parameters->getAverage()){
|
|
|
+ if(
|
|
|
+ $this->previousData() &&
|
|
|
+ $this->previousData()->getAverage() != $parameters->getAverage()
|
|
|
+ ){
|
|
|
$this->messageBus->dispatch(
|
|
|
new AverageChange($parameters->getId())
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ // Le custom domain a été modifié
|
|
|
+ if(
|
|
|
+ $this->previousData() &&
|
|
|
+ !$parameters->getDesactivateOpentalentSiteWeb() &&
|
|
|
+ $this->previousData()->getCustomDomain() !== $parameters->getCustomDomain()
|
|
|
+ ){
|
|
|
+ $this->typo3Service->updateSite($parameters->getOrganization()->getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // Le site web opentalent a été désactivé / réactivé
|
|
|
+ if(
|
|
|
+ $this->previousData() &&
|
|
|
+ $this->previousData()->getDesactivateOpentalentSiteWeb() !== $parameters->getDesactivateOpentalentSiteWeb()
|
|
|
+ ){
|
|
|
+ if ($parameters->getDesactivateOpentalentSiteWeb()) {
|
|
|
+ $this->typo3Service->deleteSite($parameters->getOrganization()->getId());
|
|
|
+ } else {
|
|
|
+ $this->typo3Service->undeleteSite($parameters->getOrganization()->getId());
|
|
|
+ $this->typo3Service->updateSite($parameters->getOrganization()->getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function remove($data, array $context = []): void
|
|
|
+ {
|
|
|
+ throw new Exception('not supported', 500);
|
|
|
}
|
|
|
-}
|
|
|
+}
|