diff --git a/app/Http/Requests/Api/Client/Servers/Schedules/StoreTaskRequest.php b/app/Http/Requests/Api/Client/Servers/Schedules/StoreTaskRequest.php index 5ceb7c8e06..95c1f1485b 100644 --- a/app/Http/Requests/Api/Client/Servers/Schedules/StoreTaskRequest.php +++ b/app/Http/Requests/Api/Client/Servers/Schedules/StoreTaskRequest.php @@ -19,7 +19,7 @@ public function permission(): string public function rules(): array { return [ - 'action' => 'required|in:command,power,backup', + 'action' => 'required|in:command,power,backup,delete-files', 'payload' => 'required_unless:action,backup|string|nullable', 'time_offset' => 'required|numeric|min:0|max:900', 'sequence_id' => 'sometimes|required|numeric|min:1', diff --git a/app/Jobs/Schedule/RunTaskJob.php b/app/Jobs/Schedule/RunTaskJob.php index 6aded8621a..8d825b3b90 100644 --- a/app/Jobs/Schedule/RunTaskJob.php +++ b/app/Jobs/Schedule/RunTaskJob.php @@ -14,6 +14,7 @@ use Pterodactyl\Repositories\Wings\DaemonPowerRepository; use Pterodactyl\Repositories\Wings\DaemonCommandRepository; use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException; +use Pterodactyl\Repositories\Wings\DaemonFileRepository; class RunTaskJob extends Job implements ShouldQueue { @@ -38,6 +39,7 @@ public function handle( DaemonCommandRepository $commandRepository, InitiateBackupService $backupService, DaemonPowerRepository $powerRepository, + DaemonFileRepository $fileRepository ) { // Do not process a task that is not set to active, unless it's been manually triggered. if (!$this->task->schedule->is_active && !$this->manualRun) { @@ -61,7 +63,7 @@ public function handle( // Perform the provided task against the daemon. try { switch ($this->task->action) { - case Task::ACTION_POWER: + case Task::ACTION_POWER: $powerRepository->setServer($server)->send($this->task->payload); break; case Task::ACTION_COMMAND: @@ -70,6 +72,9 @@ public function handle( case Task::ACTION_BACKUP: $backupService->setIgnoredFiles(explode(PHP_EOL, $this->task->payload))->handle($server, null, true); break; + case Task::ACTION_DELETE_FILES: + $fileRepository->setServer($server)->deleteFiles('/', explode(PHP_EOL, $this->task->payload)); + break; default: throw new \InvalidArgumentException('Invalid task action provided: ' . $this->task->action); } @@ -88,7 +93,7 @@ public function handle( /** * Handle a failure while sending the action to the daemon or otherwise processing the job. */ - public function failed(?\Exception $exception = null) + public function failed(\Exception $exception = null) { $this->markTaskNotQueued(); $this->markScheduleComplete(); @@ -99,7 +104,7 @@ public function failed(?\Exception $exception = null) */ private function queueNextTask() { - /** @var Task|null $nextTask */ + /** @var \Pterodactyl\Models\Task|null $nextTask */ $nextTask = Task::query()->where('schedule_id', $this->task->schedule_id) ->orderBy('sequence_id', 'asc') ->where('sequence_id', '>', $this->task->sequence_id) diff --git a/app/Models/Task.php b/app/Models/Task.php index 15d699473e..42786e0db2 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -41,6 +41,7 @@ class Task extends Model public const ACTION_POWER = 'power'; public const ACTION_COMMAND = 'command'; public const ACTION_BACKUP = 'backup'; + public const ACTION_DELETE_FILES = 'delete-files'; /** * The table associated with the model. diff --git a/resources/scripts/components/server/schedules/ScheduleTaskRow.tsx b/resources/scripts/components/server/schedules/ScheduleTaskRow.tsx index f950b94f82..be738a0cbd 100644 --- a/resources/scripts/components/server/schedules/ScheduleTaskRow.tsx +++ b/resources/scripts/components/server/schedules/ScheduleTaskRow.tsx @@ -34,6 +34,8 @@ const getActionDetails = (action: string): [string, any] => { return ['Send Power Action', faToggleOn]; case 'backup': return ['Create Backup', faFileArchive]; + case 'delete-files': + return ['Delete Files', faTrashAlt]; default: return ['Unknown Action', faCode]; } @@ -67,7 +69,7 @@ export default ({ schedule, task }: Props) => { const [title, icon] = getActionDetails(task.action); return ( -
{title}
+{title}
{task.payload && ( -Ignoring files & folders:
+Ignoring files & folders:
)}