mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-28 09:14:44 +02:00
Schedules: Update next_run_at
when editing & show notification if cron is invalid (#1141)
* update `next_run_at` when editing & show notification if cron is invalid * move getNextRun to resource
This commit is contained in:
parent
5bea1ea80a
commit
61cbe5465f
@ -4,9 +4,12 @@ namespace App\Filament\Server\Resources;
|
||||
|
||||
use App\Filament\Server\Resources\ScheduleResource\Pages;
|
||||
use App\Filament\Server\Resources\ScheduleResource\RelationManagers\TasksRelationManager;
|
||||
use App\Helpers\Utilities;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Schedule;
|
||||
use App\Models\Server;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms\Components\Actions;
|
||||
use Filament\Forms\Components\Actions\Action;
|
||||
@ -17,7 +20,9 @@ use Filament\Forms\Components\Toggle;
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Set;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Support\Exceptions\Halt;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ScheduleResource extends Resource
|
||||
@ -314,4 +319,18 @@ class ScheduleResource extends Resource
|
||||
'edit' => Pages\EditSchedule::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getNextRun(string $minute, string $hour, string $dayOfMonth, string $month, string $dayOfWeek): Carbon
|
||||
{
|
||||
try {
|
||||
return Utilities::getScheduleNextRunDate($minute, $hour, $dayOfMonth, $month, $dayOfWeek);
|
||||
} catch (Exception) {
|
||||
Notification::make()
|
||||
->title('The cron data provided does not evaluate to a valid expression')
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
throw new Halt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,14 +2,10 @@
|
||||
|
||||
namespace App\Filament\Server\Resources\ScheduleResource\Pages;
|
||||
|
||||
use App\Exceptions\DisplayException;
|
||||
use App\Facades\Activity;
|
||||
use App\Filament\Server\Resources\ScheduleResource;
|
||||
use App\Helpers\Utilities;
|
||||
use App\Models\Schedule;
|
||||
use App\Models\Server;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
@ -39,27 +35,18 @@ class CreateSchedule extends CreateRecord
|
||||
}
|
||||
|
||||
if (!isset($data['next_run_at'])) {
|
||||
$data['next_run_at'] = $this->getNextRunAt($data['cron_minute'], $data['cron_hour'], $data['cron_day_of_month'], $data['cron_month'], $data['cron_day_of_week']);
|
||||
$data['next_run_at'] = ScheduleResource::getNextRun(
|
||||
$data['cron_minute'],
|
||||
$data['cron_hour'],
|
||||
$data['cron_day_of_month'],
|
||||
$data['cron_month'],
|
||||
$data['cron_day_of_week']
|
||||
);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getNextRunAt(string $minute, string $hour, string $dayOfMonth, string $month, string $dayOfWeek): Carbon
|
||||
{
|
||||
try {
|
||||
return Utilities::getScheduleNextRunDate(
|
||||
$minute,
|
||||
$hour,
|
||||
$dayOfMonth,
|
||||
$month,
|
||||
$dayOfWeek
|
||||
);
|
||||
} catch (Exception) {
|
||||
throw new DisplayException('The cron data provided does not evaluate to a valid expression.');
|
||||
}
|
||||
}
|
||||
|
||||
public function getBreadcrumbs(): array
|
||||
{
|
||||
return [];
|
||||
|
@ -22,6 +22,19 @@ class EditSchedule extends EditRecord
|
||||
->log();
|
||||
}
|
||||
|
||||
protected function mutateFormDataBeforeSave(array $data): array
|
||||
{
|
||||
$data['next_run_at'] = ScheduleResource::getNextRun(
|
||||
$data['cron_minute'],
|
||||
$data['cron_hour'],
|
||||
$data['cron_day_of_month'],
|
||||
$data['cron_month'],
|
||||
$data['cron_day_of_week']
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
|
Loading…
x
Reference in New Issue
Block a user