Skip to content

Commit

Permalink
is this better?
Browse files Browse the repository at this point in the history
  • Loading branch information
edalzell committed Feb 28, 2025
1 parent d6b7dc4 commit b039f5c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/Contracts/Revisions/Revision.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

namespace Statamic\Contracts\Revisions;

use Statamic\Revisions\Revisable;

interface Revision
{
public function currentContent(): Revisable;

public function id($id = null);

public function message($message = null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Support\Collection;
use Statamic\Facades\Entry as EntryFacade;

class MinuteScheduledRevisionEntries
class MinuteScheduledRevisions
{
public function __construct(private readonly CarbonInterface $minute)
{
Expand Down
15 changes: 9 additions & 6 deletions src/Jobs/HandleRevisionSchedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,32 @@
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Collection;
use Statamic\Entries\Entry;
use Statamic\Entries\MinuteScheduledRevisionEntries;
use Statamic\Entries\MinuteScheduledRevisions;
use Statamic\Events\EntryScheduleReached;
use Statamic\Revisions\Revision;

class HandleRevisionSchedule implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable;

public function handle()
{
$this->entries()->each(function (Entry $entry) {
$updatedEntry = tap($entry->makeFromRevision($entry->latestRevision()))->save();
EntryScheduleReached::dispatch($updatedEntry);
$this->revisions()->each(function (Revision $revision) {
$existingContent = $revision->currentContent();

$updatedContent = tap($existingContent->makeFromRevision($revision))->save();
// EntryScheduleReached::dispatch($updatedEntry);
});
}

private function entries(): Collection
private function revisions(): Collection
{
// We want to target the PREVIOUS minute because we can be sure that any entries that
// were scheduled for then would now be considered published. If we were targeting
// the current minute and the entry has defined a time with seconds later in the
// same minute, it may still be considered scheduled when it gets dispatched.
$minute = now()->subMinute();

return (new MinuteScheduledRevisionEntries($minute))();
return (new MinuteScheduledRevisions($minute))();
}
}
14 changes: 14 additions & 0 deletions src/Revisions/Revision.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Statamic\Events\RevisionSaved;
use Statamic\Events\RevisionSaving;
use Statamic\Facades;
use Statamic\Facades\Data;
use Statamic\Facades\Revision as Revisions;
use Statamic\Support\Traits\FluentlyGetsAndSets;

Expand All @@ -18,15 +19,28 @@ class Revision implements Arrayable, Contract
use ExistsAsFile, FluentlyGetsAndSets;

protected $id;

protected $key;

protected $date;

protected $user;

protected $userId;

protected $message;

protected $publishAt;

protected $action = 'revision';

protected $attributes = [];

public function currentContent(): Revisable
{
return Data::find($this->attribute('id'));
}

public function id($id = null)
{
return $this->fluentlyGetOrSet('id')->value($id);
Expand Down

0 comments on commit b039f5c

Please sign in to comment.