Skip to content

Commit

Permalink
save publish_at in the revision
Browse files Browse the repository at this point in the history
  • Loading branch information
edalzell committed Feb 27, 2025
1 parent f837723 commit f50f330
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
16 changes: 12 additions & 4 deletions resources/js/components/entries/PublishActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<div v-if="action">

<date-fieldtype
v-if="action == 'publish_later'"
v-if="action == 'publishLater'"
class="mb-6"
:config="config"
handle="publishLaterDateTime"
Expand Down Expand Up @@ -108,7 +108,7 @@ export default {
if (this.canManagePublishState) {
options.push({ value: 'publish', label: __('Publish Now') });
options.push({ value: 'publish_later', label: __('Publish Later') });
options.push({ value: 'publishLater', label: __('Publish Later') });
if (this.published) {
options.push({ value: 'unpublish', label: __('Unpublish') });
Expand All @@ -130,7 +130,7 @@ export default {
return __('messages.publish_actions_unpublish');
case 'revision':
return __('messages.publish_actions_create_revision');
case 'publish_later':
case 'publishLater':
return __('messages.publish_actions_schedule_revision');
}
},
Expand Down Expand Up @@ -221,9 +221,17 @@ export default {
}).catch(e => this.handleAxiosError(e));
},
submitRevision() {
submitPublishLater() {
this.submitRevision(this.publishRevisionAt);
},
submitRevision(publishRevisionAt) {
const payload = { message: this.revisionMessage };
if (publishRevisionAt) {
payload.publish_at = publishRevisionAt;
}
this.$axios.post(this.actions.createRevision, payload).then(response => {
this.$toast.success(__('Revision created'));
this.revisionMessage = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function store(Request $request, $collection, $entry)
{
$entry->createRevision([
'message' => $request->message,
'publish_at' => $request->publish_at,
'user' => User::fromUser($request->user()),
]);

Expand Down
1 change: 1 addition & 0 deletions src/Revisions/Revisable.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public function createRevision($options = [])
->makeRevision()
->user($options['user'] ?? false)
->message($options['message'] ?? false)
->publishAt($options['publish_at'] ?? null)
->save();
}

Expand Down
15 changes: 15 additions & 0 deletions src/Revisions/Revision.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Statamic\Revisions;

use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Carbon;
use Statamic\Contracts\Auth\User;
use Statamic\Contracts\Revisions\Revision as Contract;
use Statamic\Data\ExistsAsFile;
Expand All @@ -23,6 +24,7 @@ class Revision implements Arrayable, Contract
protected $user;
protected $userId;
protected $message;
protected $publishAt;
protected $action = 'revision';
protected $attributes = [];

Expand Down Expand Up @@ -61,6 +63,17 @@ public function message($message = null)
return $this->fluentlyGetOrSet('message')->value($message);
}

public function publishAt($dateTime = null)
{
if (is_null($dateTime)) {
return $this;
}

$carbon = new Carbon($dateTime['date'].' '.$dateTime['time'] ?? '00:00');

return $this->fluentlyGetOrSet('publishAt')->value($carbon->timestamp);
}

public function attributes($attributes = null)
{
return $this->fluentlyGetOrSet('attributes')->value($attributes);
Expand Down Expand Up @@ -103,6 +116,7 @@ public function fileData()
'date' => $this->date->timestamp,
'user' => $this->userId ?: null,
'message' => $this->message ?: null,
'publish_at' => $this->publishAt ?: null,
'attributes' => $this->attributes,
];
}
Expand All @@ -125,6 +139,7 @@ public function toArray()
'date' => $this->date()->timestamp,
'user' => $user,
'message' => $this->message,
'publish_at' => $this->publishAt,
'attributes' => $this->attributes,
];
}
Expand Down

0 comments on commit f50f330

Please sign in to comment.