Skip to content

Commit

Permalink
Merge pull request #3409 from acrobat/doctrine-event-fixes
Browse files Browse the repository at this point in the history
[AllBundles] More fixes of deprecations in doctrine event listeners
  • Loading branch information
acrobat authored Apr 20, 2024
2 parents 016e6ea + 3282b66 commit b27a4b1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function prePersist(PrePersistEventArgs $args)
$entity = $args->getObject();

if ($entity instanceof NodeTranslation) {
$this->setSlugWhenEmpty($entity, $args->getEntityManager());
$this->setSlugWhenEmpty($entity, $args->getObjectManager());
$this->ensureSlugIsSlugified($entity);
}
}
Expand All @@ -68,7 +68,7 @@ public function preUpdate(PreUpdateEventArgs $args)
$entity = $args->getObject();

if ($entity instanceof NodeTranslation) {
$this->setSlugWhenEmpty($entity, $args->getEntityManager());
$this->setSlugWhenEmpty($entity, $args->getObjectManager());
$this->ensureSlugIsSlugified($entity);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@
namespace Kunstmaan\NodeSearchBundle\EventListener;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PreUpdateEventArgs;
use Kunstmaan\NodeBundle\Entity\NodeTranslation;
use Kunstmaan\NodeBundle\Entity\StructureNode;
use Kunstmaan\NodeBundle\Event\NodeEvent;
use Kunstmaan\NodeSearchBundle\Configuration\NodePagesConfiguration;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* EventListener which will be triggered when a Node has been updated in order to update its related documents
* in the index
*/
class NodeIndexUpdateEventListener implements NodeIndexUpdateEventListenerInterface
{
/** @var ContainerInterface */
private $container;

/** @var EntityManagerInterface */
private $em;

Expand All @@ -34,13 +30,13 @@ public function __construct(NodePagesConfiguration $nodePagesConfiguration, ?Ent
$this->em = $em;
}

public function preUpdate(LifecycleEventArgs $args)
public function preUpdate(PreUpdateEventArgs $args)
{
if ($args->getObject() instanceof NodeTranslation) {
// unfortunately we have to keep a state to see what has changed
$this->entityChangeSet = [
'nodeTranslationId' => $args->getObject()->getId(),
'changeSet' => $args->getEntityManager()->getUnitOfWork()->getEntityChangeSet($args->getObject()),
'changeSet' => $args->getObjectManager()->getUnitOfWork()->getEntityChangeSet($args->getObject()),
];
}
}
Expand Down
14 changes: 8 additions & 6 deletions src/Kunstmaan/TaggingBundle/EventListener/TagsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Kunstmaan\TaggingBundle\EventListener;

use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PostLoadEventArgs;
use Doctrine\ORM\Event\PostPersistEventArgs;
use Doctrine\ORM\Event\PostUpdateEventArgs;
use DoctrineExtensions\Taggable\Taggable;
use Kunstmaan\NodeBundle\Event\NodeEvent;
use Kunstmaan\PagePartBundle\Event\PagePartEvent;
Expand All @@ -28,9 +30,9 @@ public function getTagManager()
return $this->tagManager;
}

public function postLoad(LifecycleEventArgs $args)
public function postLoad(PostLoadEventArgs $args)
{
$entity = $args->getEntity();
$entity = $args->getObject();

if ($entity instanceof Taggable) {
$this->getTagManager()->loadTagging($entity);
Expand All @@ -40,9 +42,9 @@ public function postLoad(LifecycleEventArgs $args)
/**
* Runs the postPersist doctrine event and updates the current flag if needed
*/
public function postPersist(LifecycleEventArgs $args)
public function postPersist(PostPersistEventArgs $args)
{
$entity = $args->getEntity();
$entity = $args->getObject();

if ($entity instanceof Taggable) {
$this->getTagManager()->saveTagging($entity);
Expand All @@ -52,7 +54,7 @@ public function postPersist(LifecycleEventArgs $args)
/**
* Runs the postUpdate doctrine event and updates the current flag if needed
*/
public function postUpdate(LifecycleEventArgs $args)
public function postUpdate(PostUpdateEventArgs $args)
{
$this->postPersist($args);
}
Expand Down

0 comments on commit b27a4b1

Please sign in to comment.