|
|
@@ -3,115 +3,26 @@ declare(strict_types=1);
|
|
|
|
|
|
namespace App\DataPersister\Organization;
|
|
|
|
|
|
-use App\DataPersister\BaseDataPersister;
|
|
|
+use App\DataPersister\EntityDataPersister;
|
|
|
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;
|
|
|
+use JetBrains\PhpStorm\Pure;
|
|
|
|
|
|
/**
|
|
|
* Classe ParametersDataPersister qui est un custom dataPersister gérant la resource Parameters
|
|
|
*/
|
|
|
-class ParametersDataPersister extends BaseDataPersister
|
|
|
+class ParametersDataPersister extends EntityDataPersister
|
|
|
{
|
|
|
+ #[Pure]
|
|
|
public function __construct(
|
|
|
- private MessageBusInterface $messageBus,
|
|
|
- private OnParametersChange $onParametersChange,
|
|
|
- private \App\Service\Network\Utils $networkUtils
|
|
|
+ OnParametersChange $onChange
|
|
|
)
|
|
|
- {}
|
|
|
-
|
|
|
- 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.');
|
|
|
- }
|
|
|
+ parent::__construct($onChange);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @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
|
|
|
+ public function supports($data, array $context = []): bool
|
|
|
{
|
|
|
- throw new Exception('not supported', 500);
|
|
|
+ return $data instanceof Parameters;
|
|
|
}
|
|
|
}
|