3

I've got a problem implementing the preSoftDelete Event from the L3pp4ard DoctrineExtensions Bundle for Symfony2. The softDelete function is working just fine, but I want to add an deletedBy (userid) next to the deletedAt (datetime). To do that, I want to listen to the event that is called (preSoftDelete), but I can't get it to work. `

The file that (should) calls the event can be found at github. I have confirmed that this script runs.

I have already added a service in my config.yml:

utwente.idbbundle.presoftdelete:
  class: Utwente\IdbBundle\EventListener\UtwenteIdbSoftDeleteListener
  tags: 
    - { name: gedmo.listener.softdeleteable, event: preSoftDelete, method: onPreSoftDelete }

and I have made the class/method that should do something. For now it echo's hello, and stops the script execution (for testing).

<?php    
namespace Utwente\IdbBundle\EventListener;

class UtwenteIdbSoftDeleteListener {
  public function onPreSoftDelete(LifecycleEventArgs $args){
    echo "Hoi";
    die();
  }
}
?>

But it doesn't work. Any ideas?

(It does work when I use name: kernel.event_listener, event: kernel.request, and leave LifecycleEventArgs $args out).

Bob Van de Vijver
  • 2,224
  • 2
  • 14
  • 11

1 Answers1

5

using

tags: 
      - { name: doctrine.event_listener, event: preSoftDelete, connection: default }

was the answer...

Bob Van de Vijver
  • 2,224
  • 2
  • 14
  • 11
  • And renaming the function to preSoftDelete :-) – totophe Sep 29 '14 at 14:06
  • Might be, but in the meantime I've moved to a more direct implementation which listens to the onFlush event and then does it's magic to remove the scheduled deletions and add an extra update to the required fields. – Bob Van de Vijver Sep 29 '14 at 17:34
  • Super weird that Symfony does not understand `method` here, and that the method should be renamed.... – zed Feb 21 '19 at 13:44