Commit d6847815 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

[FIX] Remplacement de classes Doctrine obsolètes dans SourceListener

parent ce27af12
Loading
Loading
Loading
Loading
+9 −27
Original line number Diff line number Diff line
@@ -4,9 +4,10 @@ namespace UnicaenDbImport\ORM\Event\Listeners;

use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PrePersistEventArgs;
use Doctrine\ORM\Event\PreUpdateEventArgs;
use Doctrine\ORM\Events;
use Doctrine\Persistence\Event\LifecycleEventArgs;
use RuntimeException;
use UnicaenDbImport\Entity\Db\Interfaces\SourceAwareInterface;
use UnicaenDbImport\Entity\Db\Interfaces\SourceInterface;
@@ -23,30 +24,16 @@ use UnicaenDbImport\Entity\Db\Source;
 */
class SourceListener implements EventSubscriber
{
    /**
     * @var string
     */
    protected $sourceEntityClass;
    protected ?string $sourceEntityClass = null;

    /**
     * @param string $sourceEntityClass
     * @return self
     */
    public function setSourceEntityClass(string $sourceEntityClass): self
    {
        $this->sourceEntityClass = $sourceEntityClass;
        return $this;
    }

    /**
     * @var string
     */
    protected $defaultSourceCode;
    protected ?string $defaultSourceCode = null;

    /**
     * @param string $defaultSourceCode
     * @return self
     */
    public function setDefaultSourceCode(string $defaultSourceCode): self
    {
        $this->defaultSourceCode = $defaultSourceCode;
@@ -54,8 +41,7 @@ class SourceListener implements EventSubscriber
    }

    /**
     * @param LifecycleEventArgs $args
     * @throws RuntimeException Aucun utilisateur disponible pour en faire l'auteur de la création/modification
     * @throws \Doctrine\ORM\Exception\NotSupported
     */
    protected function updateSource(LifecycleEventArgs $args)
    {
@@ -74,8 +60,7 @@ class SourceListener implements EventSubscriber
    }

    /**
     * @param EntityManager $entityManager
     * @return Source
     * @throws \Doctrine\ORM\Exception\NotSupported
     */
    private function fetchDefaultSource(EntityManager $entityManager): SourceInterface
    {
@@ -96,24 +81,21 @@ class SourceListener implements EventSubscriber
    }

    /**
     * @param LifecycleEventArgs $args
     * @throws \Doctrine\ORM\Exception\NotSupported
     */
    public function prePersist(LifecycleEventArgs $args)
    public function prePersist(PrePersistEventArgs $args)
    {
        $this->updateSource($args);
    }

    /**
     * @param PreUpdateEventArgs $args
     * @throws \Doctrine\ORM\Exception\NotSupported
     */
    public function preUpdate(PreUpdateEventArgs $args)
    {
        $this->updateSource($args);
    }

    /**
     * {@inheritdoc}
     */
    public function getSubscribedEvents(): array
    {
        return [Events::prePersist, Events::preUpdate];