Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Collect recorded messages on all managed entities even not dirty ones #4

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

Merged
merged 4 commits into from
Aug 28, 2017

Conversation

GeoffroyR
Copy link

No description provided.

@GeoffroyR
Copy link
Author

GeoffroyR commented Dec 19, 2016

It seems that the identity map in v2.2 and 2.3 of doctrine was missing the not dirty entities.

@cmodijk
Copy link
Member

cmodijk commented Dec 30, 2016

It seems that the identity map in v2.2 and 2.3 of doctrine was missing the not dirty entities.

Could you explain this a bit more i'm not sure why the tests are failing know.

…riggered in Doctrine 2.2 & 2.3 when nothing need to be committed
@GeoffroyR
Copy link
Author

GeoffroyR commented Jan 4, 2017

I added a new test to cover the new feature to collect events of "not dirty" entities.
But this test is failing in odler versions 2.2 & 2.3.
After checking out the tests in these version, it's because Doctrine only triggers the PreFlush event when nothing needs to be committed to the db. In later versions this has been fixed and the OnFlush and PostFlush are triggered in any case.

I moved all recording calls in the PreFlush event to fix this.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 70f098a on GeoffroyR:master into 3e93d5d on SimpleBus:master.

@cmodijk
Copy link
Member

cmodijk commented Feb 2, 2017

@GeoffroyR So if i'm correct this is ready to be merged. I only think we should create a major release for this to not break old implementations. What do you think?

@docteurklein
Copy link

docteurklein commented Apr 12, 2017

why not listening "postFlush" ? (just curious)

@docteurklein
Copy link

@cmodijk should it be considered a major release? It might break existing implementations, but only because they didn't work in the first place. I think this is more a bugfix than a major, but heh, that's only my opinion :)
Anyway, I'm looking forward seeing this merged, as I'm currently facing this exact same issue.
Thanks for this!

@GeoffroyR
Copy link
Author

GeoffroyR commented Apr 12, 2017

Sorry but this still needs some more testing.

  • I had an issue with some entities not being in the UOW in the preflush but only in the postflush so we should also subscribe to the postflush event and collect the event form the UOW entities.
  • I think collections should also be checked and see if we collect the events of these correctly.

I have no time right now but will try to find some time next month to add a series of tests.

@docteurklein "postFlush" is not called if nothing is committed in previous versions of Doctrine 2.2 & 2.3

@patrickjahns
Copy link

I have another issue related to this PR:
it will trigger Lazy Loading to check if an Entity contains recorded messages - or require all Entities in an object graph to be hydrated beforehand.

Scenario:
Entity1 (E1) and Entity2 (E2) are both instances of ContainsRecordedMessages - E1 has a ManyToOne relation to E2.

I fetch the E1 from the repository (E2 is not hydrated for the current task), change something on the E1 and record an Event. E2 is still just a Doctrine Proxy object and can per se not contain any messages.

The check at collectEventsFromEntity will no iterate over the managed entities, see E2 and try to fetch the messages from the Entity. This will trigger Doctrine Lazy Loading - which is not required since a uninitialised proxy object will not be able to contain any messages.

Suggestion:

  • check if the object is a proxy or not
  • verify that it is initialised if it is a proxy object
private function collectEventsFromEntity($entity)
{
   if ($entity instanceof ContainsRecordedMessages
        && ( !$entity instanceof Proxy 
             || ($entity instanceof Proxy && $entity->__isInitialized__)
       )
   ) {
      foreach ($entity->recordedMessages() as $event) {
          $this->collectedEvents[] = $event;
      }
      $entity->eraseMessages();
   }
}

@cmodijk
Copy link
Member

cmodijk commented May 2, 2017

@cmodijk should it be considered a major release? It might break existing implementations, but only because they didn't work in the first place. I think this is more a bugfix than a major, but heh, that's only my opinion :)

@docteurklein You are right but that also means that if someone already implemented a workaround this (like i did myself) is going to be surprised if it is fixed without a major bump i think. And i'm working on the next major versions of al packages to drop support for php 5.4 and 5.5 and I hope i can use this in that.

I had an issue with some entities not being in the UOW in the preflush but only in the postflush so we should also subscribe to the postflush event and collect the event form the UOW entities.

Do you know why these entities where not in the preflush ?

I think collections should also be checked and see if we collect the events of these correctly.

I'm not sure but about this do you have a test case for this?

check if the object is a proxy or not verify that it is initialised if it is a proxy object

@patrickjahns tnx for the suggestion.

@GeoffroyR Are you able to finish this or should i try to make the final changes in the coming weeks?

@codecov
Copy link

codecov bot commented May 8, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@3e93d5d). Click here to learn what that means.
The diff coverage is 95.45%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master       #4   +/-   ##
=========================================
  Coverage          ?   97.56%           
=========================================
  Files             ?        2           
  Lines             ?       41           
  Branches          ?        0           
=========================================
  Hits              ?       40           
  Misses            ?        1           
  Partials          ?        0
Impacted Files Coverage Δ
src/EventListener/CollectsEventsFromEntities.php 96.66% <95.45%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3e93d5d...96fc781. Read the comment docs.

@GeoffroyR
Copy link
Author

GeoffroyR commented May 8, 2017

@cmodijk

Do you know why these entities where not in the preflush ?

I checked back why I had to add the PostFlush and it is related to the lifecycle events. I recorderded some events based on lifecycle events and these were not collected on preFlush.

About the collections, I was a bit concerned about cascade events but I did some tests and could not find any caveat.

@matthiasnoback
Copy link

Hey everyone, great that this issue receives attention! I do think it requires a major version bump, since otherwise the behavior will be too subtle for people simply upgrading. It's something that needs to be documented well too.
With regard to collections: I assumed that entities in collections are themselves registered in the identity map by their ID.
Lazy loading is an interesting case, I don't have anything to add really.

@docteurklein
Copy link

I agree with @matthiasnoback regarding collections: I don't think you have anything to check manually.

@cmodijk
Copy link
Member

cmodijk commented Jun 12, 2017

I checked back why I had to add the PostFlush and it is related to the lifecycle events. I recorderded some events based on lifecycle events and these were not collected on preFlush.

Oke, but I think the pull request is fine then right? I should be able to merge this now?

@cmodijk cmodijk closed this Jun 12, 2017
@cmodijk cmodijk reopened this Jun 12, 2017
@cmodijk
Copy link
Member

cmodijk commented Jun 12, 2017

Sorry, wrong button.

@docteurklein
Copy link

docteurklein commented Jun 12, 2017

I might be wrong (I didn't make the test but I looked at a generated doctrine proxy) and I don't think checking on initialized proxy has any effect because proxies only initialize if you call methods that touch persisted properties.

Can you confirm this behavior?
Anyway, I would personnally be OK with merging this as it provides a correct and useful behavior.

@patrickjahns
Copy link

I might be wrong (I didn't make the test but I looket at a generated doctrine proxy) and I don't think checking on initialized proxy has any effect because proxies only initialize if you call methods that touch persisted properties.

From my testing, any method invocation on a unitiliazed proxy object will trigger initialization. (Anything otherwise would cause problems / inconsistencies)

@cmodijk
Copy link
Member

cmodijk commented Jun 12, 2017

@docteurklein When you retrieve a Entity with a reference to a other Entity but only fetch the date of the first one the second one still gets a instance with a proxy implementation. When we then in our listener call the recordedMessages() on the method these proxy objects they get loaded but we did not do any work on them so that is unnecessary and could resolve into other problems.

@docteurklein
Copy link

ha ok thanks for the explanations!

@cmodijk
Copy link
Member

cmodijk commented Jun 12, 2017

@docteurklein No problem :-)

@cmodijk
Copy link
Member

cmodijk commented Jul 5, 2017

Ping @GeoffroyR i think this can get merged right?

@cmodijk
Copy link
Member

cmodijk commented Aug 28, 2017

I tested the basic concept today i'm merging this now and releasing in a bit later today.

@cmodijk cmodijk merged commit 1148d92 into SimpleBus:master Aug 28, 2017
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

Successfully merging this pull request may close these issues.

6 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.