statamic / v2-hub

Statamic 2 - Feature Requests and Bug Reports
https://statamic.com
95 stars 5 forks source link

Content saved events have wrong order #2399

Closed goellner closed 5 years ago

goellner commented 5 years ago

Describe the bug The order of the saved events is wrong in core/Data/Content/Content.php.

To Fix

Change

event(new $eventClass($this, $original, $oldPath));
event('content.saved', [$this, $original]); // Deprecated! Please listen on ContentSaved event instead!
event(new ContentSaved($this, $original, $oldPath));

to

event('content.saved', [$this, $original]); // Deprecated! Please listen on ContentSaved event instead!
event(new $eventClass($this, $original, $oldPath));       
 event(new ContentSaved($this, $original, $oldPath));
jasonvarga commented 5 years ago

What does the order affect?

peda commented 5 years ago

@jasonvarga the cache is updated with the content.saved event - so when you are listening for the EntrySaved event the entry can't be found because the cache has not been updated.

When listening for the ContentSaved event the Entry can be found because the cache has already been updated. In my opinion EntrySaved and ContentSaved should behave exactly the same with the only difference being that ContentSaved is triggered for all content items wheras EntrySaved is only triggered for entries.