forked from Alex/Pterodactyl-Panel
Fix bindings for schedule tasks
This commit is contained in:
parent
3a83a2d5ac
commit
5a1cceb9d2
@ -6,16 +6,15 @@ use Pterodactyl\Models\Task;
|
||||
use Illuminate\Http\Response;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Models\Schedule;
|
||||
use Pterodactyl\Models\Permission;
|
||||
use Pterodactyl\Repositories\Eloquent\TaskRepository;
|
||||
use Pterodactyl\Exceptions\Http\HttpForbiddenException;
|
||||
use Pterodactyl\Transformers\Api\Client\TaskTransformer;
|
||||
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
|
||||
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
||||
use Pterodactyl\Exceptions\Service\ServiceLimitExceededException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Pterodactyl\Http\Requests\Api\Client\Servers\Schedules\StoreTaskRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Client\Servers\Schedules\UpdateScheduleRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Client\Servers\Schedules\DeleteScheduleRequest;
|
||||
|
||||
class ScheduleTaskController extends ClientApiController
|
||||
{
|
||||
@ -108,12 +107,8 @@ class ScheduleTaskController extends ClientApiController
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete(UpdateScheduleRequest $request, Server $server, Schedule $schedule, Task $task): Response
|
||||
public function delete(DeleteScheduleRequest $request, Server $server, Schedule $schedule, Task $task): Response
|
||||
{
|
||||
if ($task->schedule_id !== $schedule->id || $schedule->server_id !== $server->id) {
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
|
||||
$schedule->tasks()->where('sequence_id', '>', $task->sequence_id)->update([
|
||||
'sequence_id' => $schedule->tasks()->getConnection()->raw('(sequence_id - 1)'),
|
||||
]);
|
||||
|
@ -4,9 +4,11 @@ namespace Pterodactyl\Http\Middleware\Api\Client;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\Str;
|
||||
use Pterodactyl\Models\Task;
|
||||
use Illuminate\Routing\Route;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Database\Query\JoinClause;
|
||||
use Illuminate\Contracts\Routing\Registrar;
|
||||
use Pterodactyl\Contracts\Extensions\HashidsInterface;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
@ -41,6 +43,18 @@ class SubstituteClientApiBindings
|
||||
return $this->server($route)->schedule()->where('id', $value)->firstOrFail();
|
||||
});
|
||||
|
||||
$this->router->bind('task', function ($value, $route) {
|
||||
return Task::query()
|
||||
->select('tasks.*')
|
||||
->join('schedules', function (JoinClause $join) use ($route) {
|
||||
$join->on('schedules.id', 'tasks.schedule_id')
|
||||
->where('schedules.server_id', $route->parameter('server')->id);
|
||||
})
|
||||
->where('schedules.id', $route->parameter('schedule')->id)
|
||||
->where('tasks.id', $value)
|
||||
->firstOrFail();
|
||||
});
|
||||
|
||||
$this->router->bind('database', function ($value, $route) {
|
||||
$id = Container::getInstance()->make(HashidsInterface::class)->decodeFirst($value);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user