Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listener "SoftDeleteableListener" was not added to the EventManager! #380

Closed
NZRicky opened this issue Jul 2, 2012 · 10 comments
Closed

Comments

@NZRicky
Copy link

NZRicky commented Jul 2, 2012

Hi, everyone

I followed the instruction

https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/softdeleteable.md to test softdeteable extension under

Symfony 2.1.0-DEV, I configured my config.yml like below:

orm:
    auto_generate_proxy_classes: %kernel.debug%
    auto_mapping: true
    filters:
          softdeleteable:
            class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
            enabled: true
    mappings:
        translatable:
            type: annotation
            alias: Gedmo
            prefix: Gedmo\Translatable\Entity
            # make sure vendor library location is correct
            dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"
        loggable:
            type: annotation
            alias: Gedmo
            prefix: Gedmo\Loggable\Entity
            dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/Entity"
        tree:
            type: annotation
            alias: Gedmo
            prefix: Gedmo\Tree\Entity
            dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity"   

and my controller file:

   /**
 * @Route("/del", name="del_article")
 */
public function delAction() {
    $em = $this->getDoctrine()->getEntityManager();

    $article = $em->find('Article', 3);
    $em->remove($article);
            $em->flush();
    die('ok');
}

when I run the code, it always show the exception: Listener "SoftDeleteableListener" was not added to the EventManager!

And I use netbeans xdebug the code, I found that the class "SoftDeleteableFilter" function "getListener()",

        foreach ($evm->getListeners() as $listeners) {
            foreach ($listeners as $listener) {
                if ($listener instanceof SoftDeleteableListener) {
                    $this->listener = $listener;

                    break 2;
                }
            }
        }

        if ($this->listener === null) {
            throw new \RuntimeException('Listener "SoftDeleteableListener" was not added to the EventManager!');
        }

the $listeners has no instanceof SoftDeleteableListener, but it has other listeners, such as

Gedmo\Tree\TreeListener
Gedmo\Sortable\SortableListener
Gedmo\Sluggable\SluggableListener
Gedmo\Loggable\LoggableListener
Gedmo\Timestampable\TimestampableListener
Gedmo\Translatable\TranslatableListener

which all generated from loadClassMetadata, I think it might generate from my doctrine_extensions.yml service listener:

services:
extension.listener:
class: Infinitz\UserBundle\Listener\DoctrineExtensionListener
calls:
- [ setContainer, [ @service_container ] ]
tags:
- { name: kernel.event_listener, event: kernel.request, method: onLateKernelRequest, priority: -10 }
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }

gedmo.listener.tree:
    class: Gedmo\Tree\TreeListener
    tags:
        - { name: doctrine.event_subscriber, connection: default }
    calls:
        - [ setAnnotationReader, [ @annotation_reader ] ]

gedmo.listener.translatable:
    class: Gedmo\Translatable\TranslatableListener
    tags:
        - { name: doctrine.event_subscriber, connection: default }
    calls:
        - [ setAnnotationReader, [ @annotation_reader ] ]
        - [ setDefaultLocale, [ %locale% ] ]
        - [ setTranslationFallback, [ false ] ]

gedmo.listener.timestampable:
    class: Gedmo\Timestampable\TimestampableListener
    tags:
        - { name: doctrine.event_subscriber, connection: default }
    calls:
        - [ setAnnotationReader, [ @annotation_reader ] ]

gedmo.listener.sluggable:
    class: Gedmo\Sluggable\SluggableListener
    tags:
        - { name: doctrine.event_subscriber, connection: default }
    calls:
        - [ setAnnotationReader, [ @annotation_reader ] ]

gedmo.listener.sortable:
    class: Gedmo\Sortable\SortableListener
    tags:
        - { name: doctrine.event_subscriber, connection: default }
    calls:
        - [ setAnnotationReader, [ @annotation_reader ] ]

gedmo.listener.loggable:
    class: Gedmo\Loggable\LoggableListener
    tags:
        - { name: doctrine.event_subscriber, connection: default }
    calls:
        - [ setAnnotationReader, [ @annotation_reader ] ]         

And I tried to add:

gedmo.listener.softdeleteable:
    class: Gedmo\SoftDeleteable\SoftDeleteableListener
    tags:
        - { name: doctrine.event_subscriber, connection: default }
    calls:
        - [ setAnnotationReader, [ @annotation_reader ] ]

it still showing "Listener "SoftDeleteableListener" was not added to the EventManager! "....

Do I need to add an listener which instance of SoftDeleteableListener ?

Any help will be very appreciated...Thanks.

@l3pp4rd
Copy link
Contributor

l3pp4rd commented Jul 2, 2012

Try to clear the cache rm -rf app/cache/*

@NZRicky
Copy link
Author

NZRicky commented Jul 2, 2012

thanks for your reply, i have cleared the cache, but it still could not load the softdeleteable listener, I tried to remove


gedmo.listener.sluggable:
    class: Gedmo\Sluggable\SluggableListener
    tags:
        - { name: doctrine.event_subscriber, connection: default }
    calls:
        - [ setAnnotationReader, [ @annotation_reader ] ]

and debug it again, I found that the $listeners changed without sluggable, only have 3 items

Gedmo\Sortable\SortableListener
Gedmo\Timestampable\TimestampableListener
Gedmo\Tree\TreeListener

that means it generated all the events from doctrine_extensions.yml, but why it not load the softdeleteable listener? Did I make any mistake in define the listener?

thanks...

@l3pp4rd
Copy link
Contributor

l3pp4rd commented Jul 3, 2012

hard to believe it really :) you use latest extension version I guess? anyway symfony would through an exception maybe if class would not be found in DIC. @comfortablynumb any idea?

@comfortablynumb
Copy link
Contributor

Well, I can't think of anything besides what has been said already. Did you try to add the event subscriber manually and see what happens?

/**
 * @Route("/del", name="del_article")
 */
public function delAction() {
    $em = $this->getDoctrine()->getEntityManager();
    $em->addEventSubscriber(new \Gedmo\SoftDeleteable\SoftDeleteableListener());

    $article = $em->find('Article', 3);
    $em->remove($article);
    $em->flush();
}

If this works, you have a configuration problem.

BTW, did you try to use the extensions with this bundle?

https://github.com/stof/StofDoctrineExtensionsBundle

@NZRicky
Copy link
Author

NZRicky commented Jul 3, 2012

Thanks all you guys help, I very appreciated it...

I finally fixed this problem. Sorry about my carelessness....

@comfortablynumb , I tried to add:


$em = $this->getDoctrine()->getEntityManager();
$em->getEventManager()->addEventSubscriber(new \Gedmo\SoftDeleteable\SoftDeleteableListener());

and it works, that mean it's my configuration problem, then I checked it, I found that I have predefined the listener before at the bottom of my config.yml file


services:
    gedmo.listener.softdeleteable:
        class:        Gedmo\SoftDeleteable\SoftDeleteableListener

because of this, it overwrites my previous configuration and did not configure properly,

now it describes why I added softdeleteable listener to doctrine_extension.yml, which makes no sense, as it has been overwritten by a new one which did not configure properly...


gedmo.listener.softdeleteable:
    class: Gedmo\SoftDeleteable\SoftDeleteableListener
    tags:
        - { name: doctrine.event_subscriber, connection: default }
    calls:
        - [ setAnnotationReader, [ @annotation_reader ] ]

@NZRicky NZRicky closed this as completed Jul 3, 2012
@NZRicky NZRicky reopened this Jul 3, 2012
@NZRicky NZRicky closed this as completed Jul 3, 2012
@roberto910907
Copy link

roberto910907 commented Mar 25, 2018

For the record you have to enable the extension:

stof_doctrine_extensions:
    default_locale: es_ES
    orm:
        default:
            softdeleteable: true    # needed: listeners are not enabled by default

@etshy
Copy link

etshy commented Aug 16, 2018

Just for information, I had this problem with symfony 4.
The documentation was unclear on how to configure the softdeletable (or I misread something).
Here what I had to do (for mongodb though):

stof_doctrine_extensions:
  default_locale: fr_FR
  mongodb:
    default:
      softdeleteable: true
doctrine_mongodb:
    document_managers:
        default:
            filters:
                softdeleteable:
                    class: Gedmo\SoftDeleteable\Filter\ODM\SoftDeleteableFilter
                    enabled: true
gedmo.listener.softdeleteable:
      class: Gedmo\SoftDeleteable\SoftDeleteableListener
      tags:
        - { name: doctrine.event_subscriber, connection: default }

on the latest code, adding the calls options

calls:
        - [ setAnnotationReader, [ @annotation_reader ] ]

throw an error "not valid yaml"

@thiagocalheiros
Copy link

Just for information, I had this problem with symfony 4.
The documentation was unclear on how to configure the softdeletable (or I misread something).
Here what I had to do (for mongodb though):

stof_doctrine_extensions:
  default_locale: fr_FR
  mongodb:
    default:
      softdeleteable: true
doctrine_mongodb:
    document_managers:
        default:
            filters:
                softdeleteable:
                    class: Gedmo\SoftDeleteable\Filter\ODM\SoftDeleteableFilter
                    enabled: true
gedmo.listener.softdeleteable:
      class: Gedmo\SoftDeleteable\SoftDeleteableListener
      tags:
        - { name: doctrine.event_subscriber, connection: default }

on the latest code, adding the calls options

calls:
        - [ setAnnotationReader, [ @annotation_reader ] ]

throw an error "not valid yaml"

Works for me, thanks!

@ghost
Copy link

ghost commented Dec 11, 2019

@etshy @annotation_reader must be inside single/double quote, like so:

        - [ setAnnotationReader, [ '@annotation_reader'] ]

@colinpade
Copy link

Well, I can't think of anything besides what has been said already. Did you try to add the event subscriber manually and see what happens?

/**
 * @Route("/del", name="del_article")
 */
public function delAction() {
    $em = $this->getDoctrine()->getEntityManager();
    $em->addEventSubscriber(new \Gedmo\SoftDeleteable\SoftDeleteableListener());

    $article = $em->find('Article', 3);
    $em->remove($article);
    $em->flush();
}

If this works, you have a configuration problem.

BTW, did you try to use the extensions with this bundle?

https://github.com/stof/StofDoctrineExtensionsBundle

thank you for this idea @comfortablynumb, im now slightly closer to realizing I have a config issue and am still rather numb.

greg0ire pushed a commit to greg0ire/DoctrineExtensions that referenced this issue Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants