Fix bindings for schedule tasks

This commit is contained in:
Dane Everitt 2021-08-07 15:45:36 -07:00
parent 3a83a2d5ac
commit 5a1cceb9d2
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
2 changed files with 16 additions and 7 deletions

View file

@ -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);