stof / StofDoctrineExtensionsBundle

Integration bundle for DoctrineExtensions by l3pp4rd in Symfony
https://symfony.com/bundles/StofDoctrineExtensionsBundle/current/index.html
MIT License
1.89k stars 379 forks source link

Loggable with softdeleteable and uploadable #256

Open gzbucki opened 10 years ago

gzbucki commented 10 years ago

Hi,

I'm trying to use this three extensions together, but i have some issues. First of all, i tried updating report entity which params: path and size are versioned, but no changes are logged. After creating new entity, there is create action logged, but path and size params are logged as nulls.

I tried messing around with listener priorities. I changed uploadable priority which fixed the update action versioning, but screwed up soft delete logging (remove). Tried to change softdeleteable priority, but it doesn't change anything apart from totally screwing up softdelete (the file is being deleted)

Just can't get these three to work with each other

mohamedaymenkarmous commented 6 years ago

Hi, Did you try switching priorities ? I have not already tested Softdeleteable with Loggable and Uploadable. But I tested Loggable and Uploadable together. I'm using SYmfony 4.1. And in this release I got this results:

For Uploadable:


# php bin/console debug:container stof_doctrine_extensions.listener.uploadable

Information for Service "stof_doctrine_extensions.listener.uploadable"
======================================================================

 ---------------- ---------------------------------------------------------------
  Option           Value
 ---------------- ---------------------------------------------------------------
  Service ID       stof_doctrine_extensions.listener.uploadable
  Class            Gedmo\Uploadable\UploadableListener
  Tags             doctrine.event_subscriber (connection: default, priority: -5)
  Calls            setAnnotationReader, setDefaultFileInfoClass
  Public           no
  Synthetic        no
  Lazy             no
  Shared           yes
  Abstract         no
  Autowired        no
  Autoconfigured   no
 ---------------- ---------------------------------------------------------------

And for Loggable:

# php bin/console debug:container stof_doctrine_extensions.listener.loggable

Information for Service "stof_doctrine_extensions.listener.loggable"
====================================================================

 ---------------- --------------------------------------------------------------
  Option           Value
 ---------------- --------------------------------------------------------------
  Service ID       stof_doctrine_extensions.listener.loggable
  Class            Gedmo\Loggable\LoggableListener
  Tags             doctrine.event_subscriber (connection: default, priority: 5)
  Calls            setAnnotationReader
  Public           no
  Synthetic        no
  Lazy             no
  Shared           yes
  Abstract         no
  Autowired        no
  Autoconfigured   no
 ---------------- --------------------------------------------------------------

After seeing this, I was surprised why Loggable have a higher priority than Uploadable (5 >> -5).

So I was forced to switch priorities.

I'm not sure about choosing the right priorities but I think that It's prefereable for me to keep priorities under the default (default=0) because most listeners have a default priorities even the kernel.controller event-dispatcher. Just keep a look at this command to understand:

php bin/console debug:event-dispatcher

So I just set the Uploadable priority to -5 and the Loggable priority to -7 (it's a choice). And after uploading a file, I found the file info in the "ext_log_entries" table.

To do set these priorities, I overrited the listeners in the config/services.yaml (for Symfony 4). And I set:

services:
    stof_doctrine_extensions.listener.uploadable:
        class: Gedmo\Uploadable\UploadableListener
        tags:
            - { name: doctrine.event_subscriber, priority: -5 }
    stof_doctrine_extensions.listener.loggable:
        class: Gedmo\Loggable\LoggableListener
        tags:
            - { name: doctrine.event_subscriber, priority: -7 }

I hope this can help anyone that found this problem like me.

And please if I said wrong concepts or any thing that should be corrected, don't hesitate to keep me informed.

Best regards