Merge branch 'develop' into feature/vue-serverview
This commit is contained in:
commit
5ca13839cf
110 changed files with 7190 additions and 2093 deletions
|
@ -9,7 +9,7 @@
|
|||
|
||||
namespace Pterodactyl\Console\Commands\Schedule;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Cake\Chronos\Chronos;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Collection;
|
||||
use Pterodactyl\Services\Schedules\ProcessScheduleService;
|
||||
|
@ -17,11 +17,6 @@ use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface;
|
|||
|
||||
class ProcessRunnableCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var \Carbon\Carbon
|
||||
*/
|
||||
protected $carbon;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
@ -45,31 +40,28 @@ class ProcessRunnableCommand extends Command
|
|||
/**
|
||||
* ProcessRunnableCommand constructor.
|
||||
*
|
||||
* @param \Carbon\Carbon $carbon
|
||||
* @param \Pterodactyl\Services\Schedules\ProcessScheduleService $processScheduleService
|
||||
* @param \Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface $repository
|
||||
*/
|
||||
public function __construct(
|
||||
Carbon $carbon,
|
||||
ProcessScheduleService $processScheduleService,
|
||||
ScheduleRepositoryInterface $repository
|
||||
) {
|
||||
public function __construct(ProcessScheduleService $processScheduleService, ScheduleRepositoryInterface $repository)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->carbon = $carbon;
|
||||
$this->processScheduleService = $processScheduleService;
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle command execution.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$schedules = $this->repository->getSchedulesToProcess($this->carbon->now()->toAtomString());
|
||||
$schedules = $this->repository->getSchedulesToProcess(Chronos::now()->toAtomString());
|
||||
if ($schedules->count() < 1) {
|
||||
$this->line('There are no scheduled tasks for servers that need to be run.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$bar = $this->output->createProgressBar(count($schedules));
|
||||
$schedules->each(function ($schedule) use ($bar) {
|
||||
|
|
|
@ -11,6 +11,7 @@ use Pterodactyl\Services\Locations\LocationDeletionService;
|
|||
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
|
||||
use Pterodactyl\Transformers\Api\Application\LocationTransformer;
|
||||
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Locations\GetLocationRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Locations\GetLocationsRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Locations\DeleteLocationRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Locations\UpdateLocationRequest;
|
||||
|
@ -77,7 +78,7 @@ class LocationController extends ApplicationApiController
|
|||
/**
|
||||
* Return a single location.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Controllers\Api\Application\Locations\GetLocationRequest $request
|
||||
* @param \Pterodactyl\Http\Requests\Api\Application\Locations\GetLocationRequest $request
|
||||
* @return array
|
||||
*/
|
||||
public function view(GetLocationRequest $request): array
|
||||
|
|
|
@ -124,7 +124,7 @@ class NodeController extends ApplicationApiController
|
|||
*/
|
||||
public function update(UpdateNodeRequest $request): array
|
||||
{
|
||||
$node = $this->updateService->returnUpdatedModel()->handle(
|
||||
$node = $this->updateService->handle(
|
||||
$request->getModel(Node::class), $request->validated()
|
||||
);
|
||||
|
||||
|
|
0
app/Http/Controllers/Base/AccountController.php
Normal file
0
app/Http/Controllers/Base/AccountController.php
Normal file
0
app/Http/Controllers/Server/Tasks/ActionController.php
Normal file
0
app/Http/Controllers/Server/Tasks/ActionController.php
Normal file
|
@ -1,18 +1,10 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Contracts\Config\Repository;
|
||||
|
||||
class LanguageMiddleware
|
||||
{
|
||||
|
@ -21,25 +13,18 @@ class LanguageMiddleware
|
|||
*/
|
||||
private $app;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Config\Repository
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* LanguageMiddleware constructor.
|
||||
*
|
||||
* @param \Illuminate\Foundation\Application $app
|
||||
* @param \Illuminate\Contracts\Config\Repository $config
|
||||
* @param \Illuminate\Foundation\Application $app
|
||||
*/
|
||||
public function __construct(Application $app, Repository $config)
|
||||
public function __construct(Application $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
* Handle an incoming request and set the user's preferred language.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
|
@ -47,7 +32,7 @@ class LanguageMiddleware
|
|||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
$this->app->setLocale($this->config->get('app.locale', 'en'));
|
||||
$this->app->setLocale($request->user()->language ?? config('app.locale', 'en'));
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Http\Controllers\Api\Application\Locations;
|
||||
namespace Pterodactyl\Http\Requests\Api\Application\Locations;
|
||||
|
||||
use Pterodactyl\Models\Location;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Locations\GetLocationsRequest;
|
||||
|
||||
class GetLocationRequest extends GetLocationsRequest
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace Pterodactyl\Jobs\Schedule;
|
||||
|
||||
use Exception;
|
||||
use Carbon\Carbon;
|
||||
use Cake\Chronos\Chronos;
|
||||
use Pterodactyl\Jobs\Job;
|
||||
use InvalidArgumentException;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
@ -158,7 +158,7 @@ class RunTaskJob extends Job implements ShouldQueue
|
|||
$repository = app()->make(ScheduleRepositoryInterface::class);
|
||||
$repository->withoutFreshModel()->update($this->schedule, [
|
||||
'is_processing' => false,
|
||||
'last_run_at' => Carbon::now()->toDateTimeString(),
|
||||
'last_run_at' => Chronos::now()->toDateTimeString(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -113,6 +113,7 @@ class Node extends Model implements CleansAttributes, ValidableContract
|
|||
'daemonSFTP' => 'numeric|between:1024,65535',
|
||||
'daemonListen' => 'numeric|between:1024,65535',
|
||||
'maintenance_mode' => 'boolean',
|
||||
'upload_size' => 'int|between:1,1024',
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
@ -75,6 +75,7 @@ class ScheduleRepository extends EloquentRepository implements ScheduleRepositor
|
|||
{
|
||||
return $this->getBuilder()->with('tasks')
|
||||
->where('is_active', true)
|
||||
->where('is_processing', false)
|
||||
->where('next_run_at', '<=', $timestamp)
|
||||
->get($this->getColumns());
|
||||
}
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Services\Nodes;
|
||||
|
||||
|
@ -13,7 +6,6 @@ use Pterodactyl\Models\Node;
|
|||
use GuzzleHttp\Exception\ConnectException;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Pterodactyl\Traits\Services\ReturnsUpdatedModels;
|
||||
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
||||
use Pterodactyl\Exceptions\Service\Node\ConfigurationNotPersistedException;
|
||||
|
@ -21,8 +13,6 @@ use Pterodactyl\Contracts\Repository\Daemon\ConfigurationRepositoryInterface;
|
|||
|
||||
class NodeUpdateService
|
||||
{
|
||||
use ReturnsUpdatedModels;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\ConnectionInterface
|
||||
*/
|
||||
|
@ -60,7 +50,7 @@ class NodeUpdateService
|
|||
*
|
||||
* @param \Pterodactyl\Models\Node $node
|
||||
* @param array $data
|
||||
* @return \Pterodactyl\Models\Node|mixed
|
||||
* @return \Pterodactyl\Models\Node
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
|
@ -74,14 +64,10 @@ class NodeUpdateService
|
|||
}
|
||||
|
||||
$this->connection->beginTransaction();
|
||||
if ($this->getUpdatedModel()) {
|
||||
$response = $this->repository->update($node->id, $data);
|
||||
} else {
|
||||
$response = $this->repository->withoutFreshModel()->update($node->id, $data);
|
||||
}
|
||||
$updatedModel = $this->repository->update($node->id, $data);
|
||||
|
||||
try {
|
||||
$this->configRepository->setNode($node)->update();
|
||||
$this->configRepository->setNode($updatedModel)->update();
|
||||
$this->connection->commit();
|
||||
} catch (RequestException $exception) {
|
||||
// Failed to connect to the Daemon. Let's go ahead and save the configuration
|
||||
|
@ -95,6 +81,6 @@ class NodeUpdateService
|
|||
throw new DaemonConnectionException($exception);
|
||||
}
|
||||
|
||||
return $response;
|
||||
return $updatedModel;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,53 +2,45 @@
|
|||
|
||||
namespace Pterodactyl\Services\Schedules;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Cron\CronExpression;
|
||||
use Pterodactyl\Models\Schedule;
|
||||
use Pterodactyl\Services\Schedules\Tasks\RunTaskService;
|
||||
use Illuminate\Contracts\Bus\Dispatcher;
|
||||
use Pterodactyl\Jobs\Schedule\RunTaskJob;
|
||||
use Pterodactyl\Contracts\Repository\TaskRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface;
|
||||
|
||||
class ProcessScheduleService
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Bus\Dispatcher
|
||||
*/
|
||||
private $dispatcher;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface
|
||||
*/
|
||||
private $repository;
|
||||
private $scheduleRepository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Schedules\Tasks\RunTaskService
|
||||
* @var \Pterodactyl\Contracts\Repository\TaskRepositoryInterface
|
||||
*/
|
||||
private $runnerService;
|
||||
|
||||
/**
|
||||
* @var \Carbon\Carbon|null
|
||||
*/
|
||||
private $runTimeOverride;
|
||||
private $taskRepository;
|
||||
|
||||
/**
|
||||
* ProcessScheduleService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Services\Schedules\Tasks\RunTaskService $runnerService
|
||||
* @param \Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface $repository
|
||||
* @param \Illuminate\Contracts\Bus\Dispatcher $dispatcher
|
||||
* @param \Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface $scheduleRepository
|
||||
* @param \Pterodactyl\Contracts\Repository\TaskRepositoryInterface $taskRepository
|
||||
*/
|
||||
public function __construct(RunTaskService $runnerService, ScheduleRepositoryInterface $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
$this->runnerService = $runnerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the time that this schedule should be run at. This will override the time
|
||||
* defined on the schedule itself. Useful for triggering one-off task runs.
|
||||
*
|
||||
* @param \Carbon\Carbon $time
|
||||
* @return $this
|
||||
*/
|
||||
public function setRunTimeOverride(Carbon $time)
|
||||
{
|
||||
$this->runTimeOverride = $time;
|
||||
|
||||
return $this;
|
||||
public function __construct(
|
||||
Dispatcher $dispatcher,
|
||||
ScheduleRepositoryInterface $scheduleRepository,
|
||||
TaskRepositoryInterface $taskRepository
|
||||
) {
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->scheduleRepository = $scheduleRepository;
|
||||
$this->taskRepository = $taskRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -61,7 +53,10 @@ class ProcessScheduleService
|
|||
*/
|
||||
public function handle(Schedule $schedule)
|
||||
{
|
||||
$this->repository->loadTasks($schedule);
|
||||
$this->scheduleRepository->loadTasks($schedule);
|
||||
|
||||
/** @var \Pterodactyl\Models\Task $task */
|
||||
$task = $schedule->getRelation('tasks')->where('sequence_id', 1)->first();
|
||||
|
||||
$formattedCron = sprintf('%s %s %s * %s',
|
||||
$schedule->cron_minute,
|
||||
|
@ -70,27 +65,15 @@ class ProcessScheduleService
|
|||
$schedule->cron_day_of_week
|
||||
);
|
||||
|
||||
$this->repository->update($schedule->id, [
|
||||
$this->scheduleRepository->update($schedule->id, [
|
||||
'is_processing' => true,
|
||||
'next_run_at' => $this->getRunAtTime($formattedCron),
|
||||
'next_run_at' => CronExpression::factory($formattedCron)->getNextRunDate(),
|
||||
]);
|
||||
|
||||
$task = $schedule->getRelation('tasks')->where('sequence_id', 1)->first();
|
||||
$this->runnerService->handle($task);
|
||||
}
|
||||
$this->taskRepository->update($task->id, ['is_queued' => true]);
|
||||
|
||||
/**
|
||||
* Get the timestamp to store in the database as the next_run time for a schedule.
|
||||
*
|
||||
* @param string $formatted
|
||||
* @return \DateTime|string
|
||||
*/
|
||||
private function getRunAtTime(string $formatted)
|
||||
{
|
||||
if ($this->runTimeOverride instanceof Carbon) {
|
||||
return $this->runTimeOverride->toDateTimeString();
|
||||
}
|
||||
|
||||
return CronExpression::factory($formatted)->getNextRunDate();
|
||||
$this->dispatcher->dispatch(
|
||||
(new RunTaskJob($task->id, $schedule->id))->delay($task->time_offset)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Services\Schedules\Tasks;
|
||||
|
||||
use Pterodactyl\Models\Task;
|
||||
use Pterodactyl\Jobs\Schedule\RunTaskJob;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Pterodactyl\Contracts\Repository\TaskRepositoryInterface;
|
||||
|
||||
class RunTaskService
|
||||
{
|
||||
use DispatchesJobs;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\TaskRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* RunTaskService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Contracts\Repository\TaskRepositoryInterface $repository
|
||||
*/
|
||||
public function __construct(TaskRepositoryInterface $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a single task onto the queue.
|
||||
*
|
||||
* @param int|\Pterodactyl\Models\Task $task
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function handle($task)
|
||||
{
|
||||
if (! $task instanceof Task) {
|
||||
$task = $this->repository->find($task);
|
||||
}
|
||||
|
||||
$this->repository->update($task->id, ['is_queued' => true]);
|
||||
$this->dispatch((new RunTaskJob($task->id, $task->schedule_id))->delay($task->time_offset));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue