Skip to content

Commit

Permalink
Fix SF63 deprecations (doctrine subscriber deprecated)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlallement committed Aug 8, 2023
1 parent aa7c160 commit 8d6d423
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 78 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"doctrine/persistence": "^2.5|^3.0",
"doctrine/dbal": "^3.3",
"doctrine/orm": "^2.12",
"doctrine/doctrine-bundle": "^2.6",
"doctrine/doctrine-bundle": "^2.7.2",
"symfony/cache": "^5.4|^6.0",
"symfony/dependency-injection": "^5.4|^6.0",
"symfony/http-kernel": "^5.4|^6.0",
Expand Down
16 changes: 6 additions & 10 deletions src/EventSubscriber/BlameableEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Knp\DoctrineBehaviors\EventSubscriber;

use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
Expand All @@ -14,7 +14,11 @@
use Knp\DoctrineBehaviors\Contract\Entity\BlameableInterface;
use Knp\DoctrineBehaviors\Contract\Provider\UserProviderInterface;

final class BlameableEventSubscriber implements EventSubscriberInterface
#[AsDoctrineListener(event: Events::loadClassMetadata)]
#[AsDoctrineListener(event: Events::prePersist)]
#[AsDoctrineListener(event: Events::preUpdate)]
#[AsDoctrineListener(event: Events::preRemove)]
final class BlameableEventSubscriber
{
/**
* @var string
Expand Down Expand Up @@ -131,14 +135,6 @@ public function preRemove(LifecycleEventArgs $lifecycleEventArgs): void
->propertyChanged($entity, self::DELETED_BY, $oldDeletedBy, $user);
}

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

private function mapEntity(ClassMetadataInfo $classMetadataInfo): void
{
if ($this->blameableUserEntity !== null && class_exists($this->blameableUserEntity)) {
Expand Down
15 changes: 5 additions & 10 deletions src/EventSubscriber/LoggableEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@

namespace Knp\DoctrineBehaviors\EventSubscriber;

use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Events;
use Knp\DoctrineBehaviors\Contract\Entity\LoggableInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;

final class LoggableEventSubscriber implements EventSubscriberInterface
#[AsDoctrineListener(event: Events::postPersist)]
#[AsDoctrineListener(event: Events::postUpdate)]
#[AsDoctrineListener(event: Events::preRemove)]
final class LoggableEventSubscriber
{
public function __construct(
private LoggerInterface $logger
Expand Down Expand Up @@ -50,14 +53,6 @@ public function preRemove(LifecycleEventArgs $lifecycleEventArgs): void
}
}

/**
* @return string[]
*/
public function getSubscribedEvents(): array
{
return [Events::postPersist, Events::postUpdate, Events::preRemove];
}

/**
* Logs entity changeset
*/
Expand Down
15 changes: 5 additions & 10 deletions src/EventSubscriber/SluggableEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Knp\DoctrineBehaviors\EventSubscriber;

use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
Expand All @@ -13,7 +13,10 @@
use Knp\DoctrineBehaviors\Contract\Entity\SluggableInterface;
use Knp\DoctrineBehaviors\Repository\DefaultSluggableRepository;

final class SluggableEventSubscriber implements EventSubscriberInterface
#[AsDoctrineListener(event: Events::loadClassMetadata)]
#[AsDoctrineListener(event: Events::prePersist)]
#[AsDoctrineListener(event: Events::preUpdate)]
final class SluggableEventSubscriber
{
/**
* @var string
Expand Down Expand Up @@ -50,14 +53,6 @@ public function preUpdate(LifecycleEventArgs $lifecycleEventArgs): void
$this->processLifecycleEventArgs($lifecycleEventArgs);
}

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

private function shouldSkip(ClassMetadataInfo $classMetadataInfo): bool
{
if (! is_a($classMetadataInfo->getName(), SluggableInterface::class, true)) {
Expand Down
13 changes: 4 additions & 9 deletions src/EventSubscriber/SoftDeletableEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

namespace Knp\DoctrineBehaviors\EventSubscriber;

use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Event\OnFlushEventArgs;
use Doctrine\ORM\Events;
use Knp\DoctrineBehaviors\Contract\Entity\SoftDeletableInterface;

final class SoftDeletableEventSubscriber implements EventSubscriberInterface
#[AsDoctrineListener(event: Events::loadClassMetadata)]
#[AsDoctrineListener(event: Events::onFlush)]
final class SoftDeletableEventSubscriber
{
/**
* @var string
Expand Down Expand Up @@ -62,11 +64,4 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $loadClassMetadataE
]);
}

/**
* @return string[]
*/
public function getSubscribedEvents(): array
{
return [Events::onFlush, Events::loadClassMetadata];
}
}
12 changes: 3 additions & 9 deletions src/EventSubscriber/TimestampableEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

namespace Knp\DoctrineBehaviors\EventSubscriber;

use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Events;
use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;

final class TimestampableEventSubscriber implements EventSubscriberInterface
#[AsDoctrineListener(event: Events::loadClassMetadata)]
final class TimestampableEventSubscriber
{
public function __construct(
private string $timestampableDateFieldType
Expand Down Expand Up @@ -46,11 +47,4 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $loadClassMetadataE
}
}

/**
* @return string[]
*/
public function getSubscribedEvents(): array
{
return [Events::loadClassMetadata];
}
}
15 changes: 6 additions & 9 deletions src/EventSubscriber/TranslatableEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Knp\DoctrineBehaviors\EventSubscriber;

use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Events;
Expand All @@ -15,7 +15,10 @@
use Knp\DoctrineBehaviors\Contract\Provider\LocaleProviderInterface;
use ReflectionClass;

final class TranslatableEventSubscriber implements EventSubscriberInterface
#[AsDoctrineListener(event: Events::loadClassMetadata)]
#[AsDoctrineListener(event: Events::postLoad)]
#[AsDoctrineListener(event: Events::prePersist)]
final class TranslatableEventSubscriber
{
/**
* @var string
Expand Down Expand Up @@ -69,13 +72,7 @@ public function prePersist(LifecycleEventArgs $lifecycleEventArgs): void
$this->setLocales($lifecycleEventArgs);
}

/**
* @return string[]
*/
public function getSubscribedEvents(): array
{
return [Events::loadClassMetadata, Events::postLoad, Events::prePersist];
}


/**
* Convert string FETCH mode to required string
Expand Down
13 changes: 3 additions & 10 deletions src/EventSubscriber/TreeEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

namespace Knp\DoctrineBehaviors\EventSubscriber;

use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Events;
use Knp\DoctrineBehaviors\Contract\Entity\TreeNodeInterface;

final class TreeEventSubscriber implements EventSubscriberInterface
#[AsDoctrineListener(event: Events::loadClassMetadata)]
final class TreeEventSubscriber
{
public function loadClassMetadata(LoadClassMetadataEventArgs $loadClassMetadataEventArgs): void
{
Expand All @@ -33,12 +34,4 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $loadClassMetadataE
'length' => 255,
]);
}

/**
* @return string[]
*/
public function getSubscribedEvents(): array
{
return [Events::loadClassMetadata];
}
}
14 changes: 4 additions & 10 deletions src/EventSubscriber/UuidableEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

namespace Knp\DoctrineBehaviors\EventSubscriber;

use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Events;
use Knp\DoctrineBehaviors\Contract\Entity\UuidableInterface;

final class UuidableEventSubscriber implements EventSubscriberInterface
#[AsDoctrineListener(event: Events::loadClassMetadata)]
#[AsDoctrineListener(event: Events::prePersist)]
final class UuidableEventSubscriber
{
public function loadClassMetadata(LoadClassMetadataEventArgs $loadClassMetadataEventArgs): void
{
Expand Down Expand Up @@ -44,12 +46,4 @@ public function prePersist(LifecycleEventArgs $lifecycleEventArgs): void

$entity->generateUuid();
}

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

0 comments on commit 8d6d423

Please sign in to comment.