Skip to content
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

Multisite: Propagate date change to descendants #6634

Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions src/Http/Controllers/CP/Collections/EntriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ public function update(Request $request, $collection, $entry)
}

if ($entry->collection()->dated()) {
$entry->date($this->toCarbonInstanceForSaving($request->date));
$date = $this->formatDateForSaving($request->date);

$entry->date($date);

$entry->descendants()->each(fn ($entry) => $this->saveUpdatedEntry($entry->date($date)));
}

$entry->slug($this->resolveSlug($request));
Expand All @@ -227,18 +231,7 @@ public function update(Request $request, $collection, $entry)

$this->validateUniqueUri($entry, $tree ?? null, $parent ?? null);

if ($entry->revisionsEnabled() && $entry->published()) {
$entry
->makeWorkingCopy()
->user(User::current())
->save();
} else {
if (! $entry->revisionsEnabled() && User::current()->can('publish', $entry)) {
$entry->published($request->published);
}

$entry->updateLastModified(User::current())->save();
}
$this->saveUpdatedEntry($entry, $request->published);

return new EntryResource($entry->fresh());
}
Expand Down Expand Up @@ -460,6 +453,22 @@ protected function extractAssetsFromValues($values)
->values();
}

protected function saveUpdatedEntry($entry, $published = null)
{
if ($entry->revisionsEnabled() && $entry->published()) {
$entry
->makeWorkingCopy()
->user(User::current())
->save();
} else {
if (! is_null($published) && ! $entry->revisionsEnabled() && User::current()->can('publish', $entry)) {
$entry->published($published);
}

$entry->updateLastModified(User::current())->save();
}
}

protected function toCarbonInstanceForSaving($date): Carbon
{
// Since assume `Y-m-d ...` format, we can use `parse` here.
Expand Down