Files

52 lines
1.6 KiB
PHP
Raw Permalink Normal View History

2026-10-05 18:10:18 -04:00
<?php
declare(strict_types=1);
namespace Pterodactyl\Actions\Schedules;
2026-10-11 23:41:04 -04:00
use Illuminate\Support\Facades\Validator;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Contracts\Schedules\UpdatesSchedules;
use Pterodactyl\Exceptions\DisplayException;
2026-10-11 06:11:40 -04:00
use Pterodactyl\Facades\Activity;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Models\Schedule;
2026-10-11 23:41:04 -04:00
use Throwable;
2026-10-05 18:10:18 -04:00
final class UpdateSchedule implements UpdatesSchedules
{
2026-10-11 06:11:40 -04:00
public function update(Schedule $schedule, array $input): Schedule
2026-10-05 18:10:18 -04:00
{
2026-10-11 23:41:04 -04:00
$validated = Validator::validate($input, CreateSchedule::rules());
$schedule->fill([
'name' => $validated['name'],
'cron_minute' => $validated['minute'],
'cron_hour' => $validated['hour'],
'cron_day_of_month' => $validated['day_of_month'],
'cron_month' => $validated['month'],
'cron_day_of_week' => $validated['day_of_week'],
'is_active' => $validated['is_active'] ?? false,
'only_when_online' => $validated['only_when_online'] ?? false,
]);
try {
$schedule->next_run_at = $schedule->getNextRunDate();
} catch (Throwable) {
throw new DisplayException('The cron data provided does not evaluate to a valid expression.');
}
2026-10-05 18:10:18 -04:00
2026-10-11 06:11:40 -04:00
// A schedule switched on or off is no longer mid-run.
2026-10-11 23:41:04 -04:00
if ($schedule->isDirty('is_active')) {
$schedule->is_processing = false;
2026-10-05 18:10:18 -04:00
}
2026-10-11 23:41:04 -04:00
$schedule->save();
2026-10-05 18:10:18 -04:00
2026-10-11 06:11:40 -04:00
Activity::event('server:schedule.update')
2026-10-11 14:07:14 -04:00
->subject($schedule->server, $schedule)
2026-10-11 06:11:40 -04:00
->property(['name' => $schedule->name, 'active' => $schedule->is_active])
->log();
2026-10-08 17:40:00 -04:00
return $schedule;
2026-10-05 18:10:18 -04:00
}
}