| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- declare(strict_types=1);
- namespace App\DataPersister\Organization;
- use App\DataPersister\BaseDataPersister;
- use App\Entity\Organization\Parameters;
- use App\Message\Command\Parameters\AverageChange;
- use App\Message\Command\Typo3\Typo3DeleteCommand;
- use App\Message\Command\Typo3\Typo3UndeleteCommand;
- use App\Message\Command\Typo3\Typo3UpdateCommand;
- 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 extends BaseDataPersister
- {
- public function __construct(
- private MessageBusInterface $messageBus,
- private OnParametersChange $onParametersChange,
- private \App\Service\Network\Utils $networkUtils
- )
- {}
- public function supports($data, array $context = []): bool
- {
- return $data instanceof Parameters;
- }
- protected function validate($parameters): void
- {
- // Une structure CMF n'a pas le droit de désactiver son site typo3
- if (
- $parameters->getDesactivateOpentalentSiteWeb() === true &&
- $this->networkUtils->isCMFAndActiveNow($parameters->getOrganization())
- ) {
- throw new \RuntimeException('This structure is currently active in the CMF network, the website can not be disabled.');
- }
- }
- /**
- * @param Parameters $parameters
- * @throws Exception
- */
- 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(
- $this->previousData() &&
- $this->previousData()->getMusicalDate() != $parameters->getMusicalDate()
- ){
- $this->onParametersChange->onMusicalDateChange(
- $parameters->getOrganization(),
- $this->previousData()->getMusicalDate()
- );
- }
- }
- /**
- * @param Parameters $parameters
- */
- public function postPersist($parameters): void{
- //La note maximale du suivi pédagogique change
- if(
- $this->previousData() &&
- $this->previousData()->getAverage() !== $parameters->getAverage()
- ){
- $this->messageBus->dispatch(
- new AverageChange($parameters->getId())
- );
- }
- // Le customDomain a été modifié, on met à jour le site typo3 (s'il est actif)
- if(
- $this->previousData() &&
- !$parameters->getDesactivateOpentalentSiteWeb() &&
- $this->previousData()->getCustomDomain() !== $parameters->getCustomDomain()
- ){
- $this->messageBus->dispatch(
- new Typo3UpdateCommand($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->messageBus->dispatch(
- new Typo3DeleteCommand($parameters->getOrganization()->getId())
- );
- } else {
- $this->messageBus->dispatch(
- new Typo3UndeleteCommand($parameters->getOrganization()->getId())
- );
- $this->messageBus->dispatch(
- new Typo3UpdateCommand($parameters->getOrganization()->getId())
- );
- }
- }
- }
- public function remove($data, array $context = []): void
- {
- throw new Exception('not supported', 500);
- }
- }
|