Skip to content

Commit 2b4998f

Browse files
committed
command - auto reset previously finished recurring actions
1 parent 631b84e commit 2b4998f

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

src/ActionableServiceProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Devsrv\ScheduledAction;
44

55
use Illuminate\Support\ServiceProvider;
6-
use Devsrv\ScheduledAction\Console\PollScheduledAction;
6+
use Devsrv\ScheduledAction\Console\{PollScheduledAction, ResetRecurringAction};
77

88
class ActionableServiceProvider extends ServiceProvider
99
{
@@ -28,6 +28,7 @@ public function boot()
2828

2929
$this->commands([
3030
PollScheduledAction::class,
31+
ResetRecurringAction::class,
3132
]);
3233
}
3334
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Devsrv\ScheduledAction\Console;
4+
use Illuminate\Console\Command;
5+
use Devsrv\ScheduledAction\Enums\Status;
6+
use Illuminate\Database\Eloquent\Builder;
7+
use Devsrv\ScheduledAction\Models\ModelAction;
8+
9+
class ResetRecurringAction extends Command
10+
{
11+
/**
12+
* The name and signature of the console command.
13+
*
14+
* @var string
15+
*/
16+
protected $signature = 'scheduledaction:reset';
17+
18+
/**
19+
* The console command description.
20+
*
21+
* @var string
22+
*/
23+
protected $description = 'Reset finished recurring scheduled model actions';
24+
25+
/**
26+
* Create a new command instance.
27+
*
28+
* @return void
29+
*/
30+
public function __construct()
31+
{
32+
parent::__construct();
33+
}
34+
35+
/**
36+
* Execute the console command.
37+
*
38+
* @return int
39+
*/
40+
public function handle()
41+
{
42+
ModelAction::query()
43+
->finished()
44+
->recurring()
45+
->whereHas('recurringDays', fn (Builder $query) => $query->where('day', strtoupper(now()->englishDayOfWeek)) )
46+
->update(['status' => Status::PENDING, 'finished_at' => null]);
47+
}
48+
}

0 commit comments

Comments
 (0)