eloquent-driver
eloquent-driver copied to clipboard
Editing parents of mounted entries don't always update child entry uris
- When editing the slug of a parent to a set of mounted entries, child uris are not updated
- When editing the tree nesting of a parent to a set of mounted entries, child uris are not updated
This is because eloquent is much more heavy-handed about filtering ids for performance reasons, etc. See https://github.com/statamic/eloquent-driver/blob/master/src/Entries/CollectionRepository.php#L13-L15...
if ($ids) {
$query->whereIn('id', $ids);
}
Though I created the issue here, I'm wondering if the best fix might be in Statamic core; Maybe we could pass a smarter list of $ids into this function, taking mounted entries into account.
I found a possible solution to this in Statamic core
In statamic/cms/src/Entries/Entry.php
public function save()
{
$isNew = is_null(Facades\Entry::find($this->id()));
$afterSaveCallbacks = $this->afterSaveCallbacks;
$this->afterSaveCallbacks = [];
if ($this->withEvents) {
if (EntrySaving::dispatch($this) === false) {
return false;
}
}
Facades\Entry::save($this);
if ($this->id()) {
Blink::store('structure-uris')->forget($this->id());
Blink::store('structure-entries')->forget($this->id());
}
$this->taxonomize();
+ optional(Collection::findByHandle($this->collection))->updateEntryUris();
optional(Collection::findByMount($this))->updateEntryUris();
foreach ($afterSaveCallbacks as $callback) {
$callback($this);
}
if ($this->withEvents) {
if ($isNew) {
EntryCreated::dispatch($this);
}
EntrySaved::dispatch($this);
}
if ($isNew && ! $this->hasOrigin() && $this->collection()->propagate()) {
$this->collection()->sites()
->reject($this->site()->handle())
->each(function ($siteHandle) {
$this->makeLocalization($siteHandle)->save();
});
}
return true;
}
Although this works as expected in my opinion it would be nice if we could check if:
- we could check if the slug has changed, indicating a need for an URI change
- we could narrow down the IDs to current entry and children (now it runs
updateEntryUrisfor every entry in the collection)
What do you think?
+1 for the above, this has fixed the issue for me. As a temporary fix I've added a listener which calls ->updateEntryUris() on EntrySaved
'Ello, Just a small update on this in case anyone follows the temporary solution, I've got a multisite instance approaching 2000 entries and the solution of calling updateEntryUris() on every saved event is having some performance implications (i.e. the page doesn't respond for a few seconds after the entry change is made).
A couple of ideas which may solve this:
[Statamic Core] Allow us to update the uris for collection entries per site
Allow passing a site handle into updateEntryUris() so that only entries in the affected site are updated. I'm not immediately sure this is possible with how the stache works though.
[Statamic Core] Attach the original data to ContentSaved events
There's an open FR for this in statamic/ideas (#7), this would allow us to check the slug and only update the entry URIs if it has changed.
Edit:
Maybe we could pass a smarter list of $ids into this function, taking mounted entries into account.
Just noting that this would probably be the ideal solution, my proposals are simply for fixing the issues i'm seeing with the Listener method 😄
@jesseleite how we should proceed with this one? I'm guessing we should open up an issue at Statamic Core, however I'm not positive of which part of this issue should be handled in Core and which part in this driver.
No need to open a separate issue. We'll tackle both sides.
This issue seems stale to me at this point - entry uris are definitely updating for me in 2.1.0 and Statamic 4. I'm going to close this, but feel free to re-open if its still an issue.