Skip to content

Commit 2ac90b5

Browse files
committed
Begin refactoring Tasks to be apart of the Scheduler system
1 parent 07965d0 commit 2ac90b5

File tree

28 files changed

+889
-455
lines changed

28 files changed

+889
-455
lines changed

app/Console/Commands/MakeUser.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
namespace Pterodactyl\Console\Commands;
2626

2727
use Illuminate\Console\Command;
28-
use Pterodactyl\Repositories\UserRepository;
2928
use Pterodactyl\Services\Users\UserCreationService;
3029

3130
class MakeUser extends Command
@@ -60,8 +59,7 @@ class MakeUser extends Command
6059
*/
6160
public function __construct(
6261
UserCreationService $creationService
63-
)
64-
{
62+
) {
6563
parent::__construct();
6664
$this->creationService = $creationService;
6765
}
@@ -87,7 +85,6 @@ public function handle()
8785
$data['root_admin'] = is_null($this->option('admin')) ? $this->confirm('Is this user a root administrator?') : $this->option('admin');
8886

8987
try {
90-
9188
$this->creationService->handle($data);
9289

9390
return $this->info('User successfully created.');

app/Services/Tasks/TaskUpdateService.php renamed to app/Contracts/Repository/ScheduleRepositoryInterface.php

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,23 @@
2222
* SOFTWARE.
2323
*/
2424

25-
namespace Pterodactyl\Services\Tasks;
25+
namespace Pterodactyl\Contracts\Repository;
2626

27-
use Pterodactyl\Contracts\Repository\TaskRepositoryInterface;
28-
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
29-
30-
class TaskUpdateService
27+
interface ScheduleRepositoryInterface extends RepositoryInterface
3128
{
32-
protected $repository;
33-
34-
protected $serverRepository;
35-
36-
public function __construct(
37-
ServerRepositoryInterface $serverRepository,
38-
TaskRepositoryInterface $repository
39-
) {
40-
$this->repository = $repository;
41-
$this->serverRepository = $serverRepository;
42-
}
29+
/**
30+
* Return all of the schedules for a given server.
31+
*
32+
* @param int $server
33+
* @return \Illuminate\Database\Eloquent\Collection
34+
*/
35+
public function getServerSchedules($server);
4336

44-
public function handle($server, array $data, array $chain = null)
45-
{
46-
}
37+
/**
38+
* Return a schedule model with all of the associated tasks as a relationship.
39+
*
40+
* @param int $schedule
41+
* @return \Illuminate\Support\Collection
42+
*/
43+
public function getScheduleWithTasks($schedule);
4744
}

app/Contracts/Repository/TaskRepositoryInterface.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,4 @@
2626

2727
interface TaskRepositoryInterface extends RepositoryInterface
2828
{
29-
/**
30-
* Return the parent tasks and the count of children attached to that task.
31-
*
32-
* @param int $server
33-
* @return mixed
34-
*/
35-
public function getParentTasksWithChainCount($server);
36-
37-
/**
38-
* Return a single task for a given server including all of the chained tasks.
39-
*
40-
* @param int $task
41-
* @param int $server
42-
* @return mixed
43-
*
44-
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
45-
*/
46-
public function getTaskForServer($task, $server);
4729
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/*
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Exceptions\Service\Schedule\Task;
26+
27+
use Pterodactyl\Exceptions\DisplayException;
28+
29+
class TaskIntervalTooLongException extends DisplayException
30+
{
31+
}

app/Http/Controllers/Server/Tasks/TaskManagementController.php

Lines changed: 77 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,27 @@
2424

2525
namespace Pterodactyl\Http\Controllers\Server\Tasks;
2626

27+
use Prologue\Alerts\AlertsMessageBag;
28+
use Pterodactyl\Http\Requests\Request;
2729
use Illuminate\Contracts\Session\Session;
2830
use Pterodactyl\Http\Controllers\Controller;
29-
use Pterodactyl\Services\Tasks\TaskCreationService;
3031
use Pterodactyl\Contracts\Extensions\HashidsInterface;
3132
use Pterodactyl\Traits\Controllers\JavascriptInjection;
32-
use Pterodactyl\Contracts\Repository\TaskRepositoryInterface;
33-
use Pterodactyl\Http\Requests\Server\TaskCreationFormRequest;
33+
use Pterodactyl\Services\Schedules\ScheduleCreationService;
34+
use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface;
35+
use Pterodactyl\Http\Requests\Server\ScheduleCreationFormRequest;
3436

3537
class TaskManagementController extends Controller
3638
{
3739
use JavascriptInjection;
3840

3941
/**
40-
* @var \Pterodactyl\Services\Tasks\TaskCreationService
42+
* @var \Prologue\Alerts\AlertsMessageBag
43+
*/
44+
protected $alert;
45+
46+
/**
47+
* @var \Pterodactyl\Services\Schedules\ScheduleCreationService
4148
*/
4249
protected $creationService;
4350

@@ -47,7 +54,7 @@ class TaskManagementController extends Controller
4754
protected $hashids;
4855

4956
/**
50-
* @var \Pterodactyl\Contracts\Repository\TaskRepositoryInterface
57+
* @var \Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface
5158
*/
5259
protected $repository;
5360

@@ -59,17 +66,20 @@ class TaskManagementController extends Controller
5966
/**
6067
* TaskManagementController constructor.
6168
*
62-
* @param \Pterodactyl\Contracts\Extensions\HashidsInterface $hashids
63-
* @param \Illuminate\Contracts\Session\Session $session
64-
* @param \Pterodactyl\Services\Tasks\TaskCreationService $creationService
65-
* @param \Pterodactyl\Contracts\Repository\TaskRepositoryInterface $repository
69+
* @param \Prologue\Alerts\AlertsMessageBag $alert
70+
* @param \Pterodactyl\Contracts\Extensions\HashidsInterface $hashids
71+
* @param \Illuminate\Contracts\Session\Session $session
72+
* @param \Pterodactyl\Services\Schedules\ScheduleCreationService $creationService
73+
* @param \Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface $repository
6674
*/
6775
public function __construct(
76+
AlertsMessageBag $alert,
6877
HashidsInterface $hashids,
6978
Session $session,
70-
TaskCreationService $creationService,
71-
TaskRepositoryInterface $repository
79+
ScheduleCreationService $creationService,
80+
ScheduleRepositoryInterface $repository
7281
) {
82+
$this->alert = $alert;
7383
$this->creationService = $creationService;
7484
$this->hashids = $hashids;
7585
$this->repository = $repository;
@@ -86,11 +96,11 @@ public function __construct(
8696
public function index()
8797
{
8898
$server = $this->session->get('server_data.model');
89-
$this->authorize('list-tasks', $server);
99+
$this->authorize('list-schedules', $server);
90100
$this->injectJavascript();
91101

92102
return view('server.tasks.index', [
93-
'tasks' => $this->repository->getParentTasksWithChainCount($server->id),
103+
'schedules' => $this->repository->getServerSchedules($server->id),
94104
'actions' => [
95105
'command' => trans('server.tasks.actions.command'),
96106
'power' => trans('server.tasks.actions.power'),
@@ -108,64 +118,95 @@ public function index()
108118
public function create()
109119
{
110120
$server = $this->session->get('server_data.model');
111-
$this->authorize('create-task', $server);
121+
$this->authorize('create-schedule', $server);
112122
$this->injectJavascript();
113123

114124
return view('server.tasks.new');
115125
}
116126

117127
/**
118-
* @param \Pterodactyl\Http\Requests\Server\TaskCreationFormRequest $request
119-
*
128+
* @param \Pterodactyl\Http\Requests\Server\ScheduleCreationFormRequest $request
120129
* @return \Illuminate\Http\RedirectResponse
121130
*
122-
* @throws \Exception
123131
* @throws \Illuminate\Auth\Access\AuthorizationException
124132
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
125-
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
133+
* @throws \Pterodactyl\Exceptions\Service\Schedule\Task\TaskIntervalTooLongException
126134
*/
127-
public function store(TaskCreationFormRequest $request)
135+
public function store(ScheduleCreationFormRequest $request)
128136
{
129137
$server = $this->session->get('server_data.model');
130-
$this->authorize('create-task', $server);
138+
$this->authorize('create-schedule', $server);
131139

132-
$task = $this->creationService->handle($server, $request->normalize(), $request->getChainedTasks());
140+
$schedule = $this->creationService->handle($server, $request->normalize(), $request->getTasks());
141+
$this->alert->success(trans('server.tasks.task_created'))->flash();
133142

134143
return redirect()->route('server.tasks.view', [
135144
'server' => $server->uuidShort,
136-
'task' => $task->id,
145+
'task' => $schedule->hashid,
137146
]);
138147
}
139148

140149
/**
141-
* Return a view to modify task settings.
150+
* Return a view to modify a schedule.
142151
*
143-
* @param string $uuid
144-
* @param string $task
152+
* @param \Pterodactyl\Http\Requests\Request $request
145153
* @return \Illuminate\View\View
146-
*
147154
* @throws \Illuminate\Auth\Access\AuthorizationException
148-
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
149155
*/
150-
public function view($uuid, $task)
156+
public function view(Request $request)
151157
{
152158
$server = $this->session->get('server_data.model');
153-
$this->authorize('edit-task', $server);
154-
$task = $this->repository->getTaskForServer($this->hashids->decodeFirst($task, 0), $server->id);
159+
$schedule = $request->attributes->get('schedule');
160+
$this->authorize('view-schedule', $server);
155161

156162
$this->injectJavascript([
157-
'chained' => $task->chained->map(function ($chain) {
158-
return collect($chain->toArray())->only('action', 'chain_delay', 'data')->all();
163+
'tasks' => $schedule->tasks->map(function ($schedule) {
164+
return collect($schedule->toArray())->only('action', 'time_offset', 'payload')->all();
159165
}),
160166
]);
161167

162-
return view('server.tasks.view', ['task' => $task]);
168+
return view('server.tasks.view', ['schedule' => $schedule]);
169+
}
170+
171+
/**
172+
* Update a specific parent task on the system.
173+
*
174+
* @param \Pterodactyl\Http\Requests\Server\ScheduleCreationFormRequest $request
175+
* @return \Illuminate\Http\RedirectResponse
176+
*
177+
* @throws \Illuminate\Auth\Access\AuthorizationException
178+
*/
179+
public function update(ScheduleCreationFormRequest $request)
180+
{
181+
$server = $this->session->get('server_data.model');
182+
$schedule = $request->attributes->get('schedule');
183+
$this->authorize('edit-schedule', $server);
184+
185+
// $this->updateService->handle($task, $request->normalize(), $request->getChainedTasks());
186+
$this->alert->success(trans('server.tasks.task_updated'))->flash();
187+
188+
return redirect()->route('server.tasks.view', [
189+
'server' => $server->uuidShort,
190+
'task' => $schedule->hashid,
191+
]);
163192
}
164193

165-
public function update(TaskCreationFormRequest $request, $uuid, $task)
194+
/**
195+
* Delete a parent task from the Panel.
196+
*
197+
* @param \Pterodactyl\Http\Requests\Request $request
198+
* @return \Illuminate\Http\RedirectResponse
199+
*
200+
* @throws \Illuminate\Auth\Access\AuthorizationException
201+
*/
202+
public function delete(Request $request)
166203
{
167204
$server = $this->session->get('server_data.model');
168-
$this->authorize('edit-task', $server);
169-
$task = $this->repository->getTaskForServer($this->hashids->decodeFirst($task, 0), $server->id);
205+
$schedule = $request->attributes->get('schedule');
206+
$this->authorize('delete-schedule', $server);
207+
208+
$this->repository->delete($task->id);
209+
210+
return response('', 204);
170211
}
171212
}

0 commit comments

Comments
 (0)