Skip to content

Commit

Permalink
tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
edalzell committed Feb 28, 2025
1 parent f70b8cb commit 36b4df6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/Contracts/Revisions/Revision.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace Statamic\Contracts\Revisions;

use Statamic\Entries\Entry;

interface Revision
{
public function currentContent();
public function entry(): Entry;

public function id($id = null);

Expand Down
16 changes: 7 additions & 9 deletions src/Jobs/HandleRevisionSchedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Collection;
use Statamic\Entries\Entry;
use Statamic\Entries\MinuteScheduledRevisions;
use Statamic\Entries\MinuteRevisions;
use Statamic\Events\EntryScheduleReached;
use Statamic\Revisions\Revision;

Expand All @@ -18,12 +17,11 @@ class HandleRevisionSchedule implements ShouldQueue

public function handle()
{
$this->revisions()->each(function (Revision $revision) {
$existingContent = $revision->currentContent();

$updatedContent = tap($existingContent->makeFromRevision($revision))->save();
// EntryScheduleReached::dispatch($updatedEntry);
});
$this
->revisions()
->each(fn (Revision $revision) => EntryScheduleReached::dispatch(
tap($revision->entry()->makeFromRevision($revision))->save()
));
}

private function revisions(): Collection
Expand All @@ -34,6 +32,6 @@ private function revisions(): Collection
// same minute, it may still be considered scheduled when it gets dispatched.
$minute = now()->subMinute();

return (new MinuteScheduledRevisions($minute))();
return (new MinuteRevisions($minute))();
}
}
6 changes: 5 additions & 1 deletion src/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Statamic\Facades\Token;
use Statamic\Fields\FieldsetRecursionStack;
use Statamic\Jobs\HandleEntrySchedule;
use Statamic\Jobs\HandleRevisionSchedule;
use Statamic\Sites\Sites;
use Statamic\Statamic;
use Statamic\Tokens\Handlers\LivePreview;
Expand Down Expand Up @@ -104,7 +105,10 @@ public function boot()

$this->addAboutCommandInfo();

$this->app->make(Schedule::class)->job(new HandleEntrySchedule)->everyMinute();
tap($this->app->make(Schedule::class), function (Schedule $scheduler) {
$scheduler->job(new HandleEntrySchedule)->everyMinute();
$scheduler->job(new HandleRevisionSchedule)->everyMinute();
});
}

public function register()
Expand Down
7 changes: 4 additions & 3 deletions src/Revisions/Revision.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
use Statamic\Contracts\Auth\User;
use Statamic\Contracts\Revisions\Revision as Contract;
use Statamic\Data\ExistsAsFile;
use Statamic\Entries\Entry;
use Statamic\Events\RevisionDeleted;
use Statamic\Events\RevisionSaved;
use Statamic\Events\RevisionSaving;
use Statamic\Facades;
use Statamic\Facades\Entry;
use Statamic\Facades\Entry as EntryFacade;
use Statamic\Facades\Revision as Revisions;
use Statamic\Support\Traits\FluentlyGetsAndSets;

Expand All @@ -36,9 +37,9 @@ class Revision implements Arrayable, Contract

protected $attributes = [];

public function currentContent()
public function entry(): Entry
{
return Entry::find($this->attribute('id'));
return EntryFacade::find($this->attribute('id'));
}

public function id($id = null)
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/Revisions/RevisionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function can_get_its_entry()
$entry->save();
$revision = $entry->makeRevision();

$this->assertEquals($entry->id(), $revision->currentContent()->id());
$this->assertEquals($entry->id(), $revision->entry()->id());
}

#[Test]
Expand Down

0 comments on commit 36b4df6

Please sign in to comment.