neo4j-php-ogm icon indicating copy to clipboard operation
neo4j-php-ogm copied to clipboard

Add events to UnitOfWork

Open AndrolGenhald opened this issue 8 years ago • 11 comments

Implement lifecycle events similar to doctrine-orm: http://doctrine-orm.readthedocs.io/projects/doctrine-orm/en/latest/reference/events.html

Since much of the implementation resides in doctrine/common, I'm hoping I'll be able to get at least some of the events implemented this weekend without too much trouble.

AndrolGenhald avatar Jul 29 '16 03:07 AndrolGenhald

Thanks, yeah this is planned of course but not really in the priorities for now, if you come up with a PR that would be wonderful.

ikwattro avatar Jul 29 '16 09:07 ikwattro

@AndrolGenhald Do you have any progress on this, if yes please open a PR so I can contribute and make some improvements for this implementation.

ikwattro avatar Jul 29 '16 19:07 ikwattro

I haven't started anything yet, I spent last night looking through doctrine-orm's implementation of lifecycle events. I was planning working on it over the weekend.

AndrolGenhald avatar Jul 29 '16 19:07 AndrolGenhald

Right, I'll check also and maybe prepare some entry points for it. Thanks !

ikwattro avatar Jul 29 '16 19:07 ikwattro

What is your actual use case for doctrine events ?

ikwattro avatar Jul 29 '16 19:07 ikwattro

Ha yeah, DoctrineModule Form element

ikwattro avatar Jul 29 '16 19:07 ikwattro

I'm mainly looking to subscribe to the onFlush event to create historical copies of entities when they are changed, right now I'm handling it everywhere I call flush.

AndrolGenhald avatar Jul 29 '16 20:07 AndrolGenhald

Interesting ! Do you have a screenshot of what your graph looks like after the historic is created ? You can even share privately if you want : christophe at graphaware dot com

ikwattro avatar Jul 29 '16 20:07 ikwattro

Sequence of events:

  • Add 'Entity'
  • Add 'attribute 1'
  • Add 'attribute 2'
  • Rename 'Entity' -> 'Entity (changed)'
  • Add 'attribute 3'
  • Rename 'attribute 1' -> 'attribute 1 (changed)'
  • Rename 'Entity (changed)' -> 'Entity (changed again)' screenshot

AndrolGenhald avatar Jul 29 '16 21:07 AndrolGenhald

Very cool !

ikwattro avatar Jul 29 '16 21:07 ikwattro

There seems to be no recomputeSingleEntityChangeSet($meta, $entity); in unit of work. Wanted to create an event listener for onFlush so User::updatedAt field is set to current timestamp on node update.

AzeemMichael avatar Jun 03 '17 18:06 AzeemMichael