Patrick
Patrick

Reputation: 1620

Trigger doctrine events without change

I have a doctrine Entity which is already persisted. There is a plugin that listens to livecycle events.

I'd like to trigger these Events without changing the entity at all. Is this possible somehow? I'm searching for something like that:

$entityManager->touch($entity)

Upvotes: 0

Views: 392

Answers (1)

Patrick
Patrick

Reputation: 1620

I found the solution. You can get the EventManager directly from your EntityManager and call it.

    $repo = $this->entityManager->getRepository(MyClass::class);
    $entity = $repo->find($parent);

    $eventArgs = new LifecycleEventArgs($entity, $this->entityManager);
    $this->entityManager
        ->getEventManager()
        ->dispatchEvent(\Doctrine\ORM\Events::postPersist, $eventArgs);

Upvotes: 1

Related Questions