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

Published_at does not update when publish draft #15

Open
UshurbakiyevDavlat opened this issue Jan 15, 2024 · 1 comment
Open

Published_at does not update when publish draft #15

UshurbakiyevDavlat opened this issue Jan 15, 2024 · 1 comment

Comments

@UshurbakiyevDavlat
Copy link

So field published_at does not update after I published draft record, if I am publishing within creation it updates but in case when record exist and it draft it doesn't

@marvinosswald
Copy link

This seems to be because the Draftable Trait for Edit Pages doesn't trigger the publish method.

by inserting $record->publish(); on line 56 in the Trait this works as expected.

protected function handleRecordUpdate(Model $record, array $data): Model
    {
        if ($record->isPublished() && $this->shouldSaveAsDraft) {
            $record->updateAsDraft($data);
        } elseif ($record->isPublished() && !$this->shouldSaveAsDraft) {
            $record->update($data);
        } elseif (!$record->is_current && $this->shouldSaveAsDraft) {
            $record->updateAsDraft($data);
        } else {
            // Unpublish all other revisions
            if (!$this->shouldSaveAsDraft) {
                /** @var HasMany $revisions */
                $record::withoutTimestamps(fn() => $record->revisions()
                    ->where('is_published', true)
                    ->update(['is_published' => false]));
                $record->publish();
            }
            $record->update([
                ...$data,
                'is_published' => !$this->shouldSaveAsDraft,
            ]);
        }

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

No branches or pull requests

2 participants