문제

I'm using Oneup\AclBundle and after last update I can't save any entity no more.

When I try to save my entity to the Database:

$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();

... I get this error:

ContextErrorException: Catchable Fatal Error: Argument 1 passed to Oneup\AclBundle\EventListener\DoctrineSubscriber::postPersist() must be an instance of Doctrine\Common\Persistence\Event\LifecycleEventArgs, instance of Doctrine\ORM\Event\LifecycleEventArgs given, called in vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php on line 61 and defined in vendor/oneup/acl-bundle/Oneup/AclBundle/EventListener/DoctrineSubscriber.php line 18

I found this change for Oneup/AclBundle: https://github.com/danez/OneupAclBundle/commit/f3eacf040677019caad73d221a610c73cbd7dd25

Based on this, I tried to change the file vendor/oneup/acl-bundle/Oneup/AclBundle/EventListener/DoctrineSubscriber.php:

use Doctrine\Common\Persistence\Event\LifecycleEventArgs;

...

class DoctrineSubscriber implements EventSubscriber
{
    ...
    public function postPersist(LifecycleEventArgs $args)
    {
        ...

        $entity = $args->getObject();
        $object = new \ReflectionClass($entity);

        ...
    }
}

... to:

use Doctrine\ORM\Event\LifecycleEventArgs;

...

class DoctrineSubscriber implements EventSubscriber
{
    ...

    public function postPersist(LifecycleEventArgs $args)
    {
        ...

        $entity = method_exists($args, 'getObject')? $args->getObject(): $args->getEntity(); // the called method sometimes changes
        $object = new \ReflectionClass($entity);

        ...
    }
}

... and like this it works.

How can I manage to get things working again with this update? I guess I must somehow make a common doctrine EventClass gets fired, not a ORM doctrine EventClass.

Upon update the log for this bundle was:

  • Updating oneup/acl-bundle dev-master (b3c6ddb => fc3fdbc) Checking out fc3fdbcf3547f0e0520ebb7f7f7e86e3a05779d4
도움이 되었습니까?

해결책

The mentioned error was thrown because of a combination of too narrow inheritance and a too wide defined composer dependency.

For the record: The bug was reported in oneup/acl-bundle#7 and fixed with the commit d07385b. If you run into this error, update the bundle to the new version v0.9.1 and doctrine/orm to 2.4.2 as mentioned in the bug report.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top