Skip to content

Commit

Permalink
Update to Laravel 8
Browse files Browse the repository at this point in the history
Co-authored-by: Matthew Penner <[email protected]>
  • Loading branch information
DaneEveritt and matthewpi committed Jan 23, 2021
1 parent 028921b commit a043071
Show file tree
Hide file tree
Showing 211 changed files with 4,341 additions and 2,880 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ jobs:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
strategy:
fail-fast: true
fail-fast: false
matrix:
php: [7.3, 7.4]
php: [7.4, 8.0]
name: PHP ${{ matrix.php }}
steps:
- name: checkout
Expand All @@ -44,7 +44,7 @@ jobs:
with:
php-version: ${{ matrix.php }}
extensions: cli, openssl, gd, mysql, pdo, mbstring, tokenizer, bcmath, xml, curl, zip
tools: composer:v1
tools: composer:v2
coverage: none
- name: configure
run: cp .env.ci .env
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/vendor
*.DS_Store*
.env
!.env.ci
!.env.dusk
!.env.example
.env*
.vagrant/*
.vscode/*
storage/framework/*
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/Overrides/SeedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SeedCommand extends BaseSeedCommand
*/
public function handle()
{
if (!$this->hasCompletedMigrations()) {
if (! $this->hasCompletedMigrations()) {
return $this->showMigrationWarning();
}

Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/Overrides/UpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class UpCommand extends BaseUpCommand
*/
public function handle()
{
if (!$this->hasCompletedMigrations()) {
if (! $this->hasCompletedMigrations()) {
return $this->showMigrationWarning();
}

Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/Schedule/ProcessRunnableCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Pterodactyl\Console\Commands\Schedule;

use Throwable;
use Exception;
use Throwable;
use Illuminate\Console\Command;
use Pterodactyl\Models\Schedule;
use Illuminate\Support\Facades\Log;
Expand Down
4 changes: 2 additions & 2 deletions app/Console/Commands/Server/BulkPowerActionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ protected function getQueryBuilder(array $servers, array $nodes)

if (! empty($nodes) && ! empty($servers)) {
$instance->whereIn('id', $servers)->orWhereIn('node_id', $nodes);
} else if (empty($nodes) && ! empty($servers)) {
} elseif (empty($nodes) && ! empty($servers)) {
$instance->whereIn('id', $servers);
} else if (! empty($nodes) && empty($servers)) {
} elseif (! empty($nodes) && empty($servers)) {
$instance->whereIn('node_id', $nodes);
}

Expand Down
8 changes: 3 additions & 5 deletions app/Console/Commands/User/DeleteUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@

namespace Pterodactyl\Console\Commands\User;

use Webmozart\Assert\Assert;
use Pterodactyl\Models\User;
use Webmozart\Assert\Assert;
use Illuminate\Console\Command;
use Pterodactyl\Services\Users\UserDeletionService;
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;

class DeleteUserCommand extends Command
{
Expand Down Expand Up @@ -42,7 +41,8 @@ class DeleteUserCommand extends Command
*
* @param \Pterodactyl\Services\Users\UserDeletionService $deletionService
*/
public function __construct(UserDeletionService $deletionService) {
public function __construct(UserDeletionService $deletionService)
{
parent::__construct();

$this->deletionService = $deletionService;
Expand Down Expand Up @@ -96,7 +96,5 @@ public function handle()
$this->deletionService->handle($deleteUser);
$this->info(trans('command/messages.user.deleted'));
}

return;
}
}
6 changes: 3 additions & 3 deletions app/Console/RequiresDatabaseMigrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function hasCompletedMigrations(): bool
*/
protected function showMigrationWarning(): int
{
$this->getOutput()->writeln("<options=bold>
$this->getOutput()->writeln('<options=bold>
| @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
| |
| Your database has not been properly migrated! |
Expand All @@ -52,9 +52,9 @@ protected function showMigrationWarning(): int
You will not be able to use Pterodactyl Panel as expected without fixing your
database state by running the command above.
");
');

$this->getOutput()->error("You must correct the error above before continuing.");
$this->getOutput()->error('You must correct the error above before continuing.');

return 1;
}
Expand Down
2 changes: 0 additions & 2 deletions app/Contracts/Repository/AllocationRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Pterodactyl\Contracts\Repository;

use Illuminate\Support\Collection;

interface AllocationRepositoryInterface extends RepositoryInterface
{
/**
Expand Down
3 changes: 0 additions & 3 deletions app/Contracts/Repository/NodeRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

use Pterodactyl\Models\Node;
use Illuminate\Support\Collection;
use Illuminate\Support\LazyCollection;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Pterodactyl\Contracts\Repository\Attributes\SearchableInterface;

interface NodeRepositoryInterface extends RepositoryInterface
{
Expand Down
91 changes: 34 additions & 57 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
use Exception;
use Throwable;
use PDOException;
use Psr\Log\LoggerInterface;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Swift_TransportException;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Collection;
use Illuminate\Container\Container;
use Illuminate\Database\Connection;
use Illuminate\Foundation\Application;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Session\TokenMismatchException;
use Illuminate\Validation\ValidationException;
Expand Down Expand Up @@ -43,17 +47,6 @@ class Handler extends ExceptionHandler
ValidationException::class,
];

/**
* A list of exceptions that should be logged with cleaned stack
* traces to avoid exposing credentials or other sensitive information.
*
* @var array
*/
protected $cleanStacks = [
PDOException::class,
Swift_TransportException::class,
];

/**
* A list of the inputs that are never flashed for validation exceptions.
*
Expand All @@ -67,56 +60,40 @@ class Handler extends ExceptionHandler
];

/**
* Report or log an exception. Skips Laravel's internal reporter since we
* don't need or want the user information in our logs by default.
*
* If you want to implement logging in a different format to integrate with
* services such as AWS Cloudwatch or other monitoring you can replace the
* contents of this function with a call to the parent reporter.
*
* @param \Throwable $exception
* @return mixed
* Registers the exception handling callbacks for the application. This
* will capture specific exception types that we do not want to include
* the detailed stack traces for since they could reveal credentials to
* whoever can read the logs.
*
* @throws \Throwable
* @noinspection PhpUnusedLocalVariableInspection
*/
public function report(Throwable $exception)
public function register()
{
if (! config('app.exceptions.report_all', false) && $this->shouldntReport($exception)) {
return null;
}

if (method_exists($exception, 'report')) {
return $exception->report();
if (config('app.exceptions.report_all', false)) {
$this->dontReport = [];
}

try {
$logger = $this->container->make(LoggerInterface::class);
} catch (Exception $ex) {
throw $exception;
}

foreach ($this->cleanStacks as $class) {
if ($exception instanceof $class) {
$exception = $this->generateCleanedExceptionStack($exception);
break;
}
}
$this->reportable(function (PDOException $ex) {
$ex = $this->generateCleanedExceptionStack($ex);
});

return $logger->error($exception);
$this->reportable(function (Swift_TransportException $ex) {
$ex = $this->generateCleanedExceptionStack($ex);
});
}

private function generateCleanedExceptionStack(Throwable $exception)
private function generateCleanedExceptionStack(Throwable $exception): string
{
$cleanedStack = '';
foreach ($exception->getTrace() as $index => $item) {
$cleanedStack .= sprintf(
"#%d %s(%d): %s%s%s\n",
$index,
array_get($item, 'file'),
array_get($item, 'line'),
array_get($item, 'class'),
array_get($item, 'type'),
array_get($item, 'function')
Arr::get($item, 'file'),
Arr::get($item, 'line'),
Arr::get($item, 'class'),
Arr::get($item, 'type'),
Arr::get($item, 'function')
);
}

Expand All @@ -142,7 +119,7 @@ class_basename($exception),
*/
public function render($request, Throwable $exception)
{
$connections = Container::getInstance()->make(Connection::class);
$connections = $this->container->make(Connection::class);

// If we are currently wrapped up inside a transaction, we will roll all the way
// back to the beginning. This needs to happen, otherwise session data does not
Expand Down Expand Up @@ -170,21 +147,21 @@ public function render($request, Throwable $exception)
*/
public function invalidJson($request, ValidationException $exception)
{
$codes = collect($exception->validator->failed())->mapWithKeys(function ($reasons, $field) {
$codes = Collection::make($exception->validator->failed())->mapWithKeys(function ($reasons, $field) {
$cleaned = [];
foreach ($reasons as $reason => $attrs) {
$cleaned[] = snake_case($reason);
$cleaned[] = Str::snake($reason);
}

return [str_replace('.', '_', $field) => $cleaned];
})->toArray();

$errors = collect($exception->errors())->map(function ($errors, $field) use ($codes, $exception) {
$errors = Collection::make($exception->errors())->map(function ($errors, $field) use ($codes, $exception) {
$response = [];
foreach ($errors as $key => $error) {
$meta = [
'source_field' => $field,
'rule' => str_replace(self::PTERODACTYL_RULE_STRING, 'p_', array_get(
'rule' => str_replace(self::PTERODACTYL_RULE_STRING, 'p_', Arr::get(
$codes, str_replace('.', '_', $field) . '.' . $key
)),
];
Expand Down Expand Up @@ -235,7 +212,7 @@ public static function convertToArray(Throwable $exception, array $override = []
'detail' => $exception->getMessage(),
'source' => [
'line' => $exception->getLine(),
'file' => str_replace(base_path(), '', $exception->getFile()),
'file' => str_replace(Application::getInstance()->basePath(), '', $exception->getFile()),
],
'meta' => [
'trace' => explode("\n", $exception->getTraceAsString()),
Expand All @@ -262,15 +239,15 @@ public static function isReportable(Exception $exception): bool
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Auth\AuthenticationException $exception
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
*/
protected function unauthenticated($request, AuthenticationException $exception)
{
if ($request->expectsJson()) {
return response()->json(self::convertToArray($exception), 401);
return new JsonResponse(self::convertToArray($exception), JsonResponse::HTTP_UNAUTHORIZED);
}

return redirect()->guest(route('auth.login'));
return $this->container->make('redirect')->guest('/auth/login');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(GuzzleException $previous, bool $useStatusCode = tru
$body = $response->getBody();
if (is_string($body) || (is_object($body) && method_exists($body, '__toString'))) {
$body = json_decode(is_string($body) ? $body : $body->__toString(), true);
$message = "[Wings Error]: " . Arr::get($body, 'error', $message);
$message = '[Wings Error]: ' . Arr::get($body, 'error', $message);
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/Exceptions/Http/TwoFactorAuthRequiredException.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ class TwoFactorAuthRequiredException extends HttpException implements HttpExcept
*/
public function __construct(Throwable $previous = null)
{
parent::__construct(Response::HTTP_BAD_REQUEST, "Two-factor authentication is required on this account in order to access this endpoint.", $previous);
parent::__construct(Response::HTTP_BAD_REQUEST, 'Two-factor authentication is required on this account in order to access this endpoint.', $previous);
}
}
2 changes: 1 addition & 1 deletion app/Extensions/Backups/BackupManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use Illuminate\Support\Str;
use Webmozart\Assert\Assert;
use InvalidArgumentException;
use League\Flysystem\AdapterInterface;
use Illuminate\Foundation\Application;
use League\Flysystem\AdapterInterface;
use League\Flysystem\AwsS3v3\AwsS3Adapter;
use League\Flysystem\Memory\MemoryAdapter;
use Illuminate\Contracts\Config\Repository;
Expand Down
33 changes: 33 additions & 0 deletions app/Extensions/Lcobucci/JWT/Encoding/TimestampDates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Pterodactyl\Extensions\Lcobucci\JWT\Encoding;

use DateTimeImmutable;
use Lcobucci\JWT\ClaimsFormatter;
use Lcobucci\JWT\Token\RegisteredClaims;

final class TimestampDates implements ClaimsFormatter
{
/**
* The default time encoder for JWTs using this library is not supported correctly
* by Wings and will cause a flood of errors and panic conditions because the times
* cannot be parsed correctly. The default is time with microseconds, we just need
* to use the normal unix timestamp here.
*
* @param array $claims
* @return array
*/
public function formatClaims(array $claims): array
{
foreach (RegisteredClaims::DATE_CLAIMS as $claim) {
if (! array_key_exists($claim, $claims)) {
continue;
}

assert($claims[$claim] instanceof DateTimeImmutable);
$claims[$claim] = $claims[$claim]->getTimestamp();
}

return $claims;
}
}
4 changes: 0 additions & 4 deletions app/Http/Controllers/Admin/MountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
namespace Pterodactyl\Http\Controllers\Admin;

use Ramsey\Uuid\Uuid;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Pterodactyl\Models\Nest;
use Pterodactyl\Models\Mount;
use Pterodactyl\Models\Location;
use Prologue\Alerts\AlertsMessageBag;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Services\Mounts\MountUpdateService;
use Pterodactyl\Http\Requests\Admin\MountFormRequest;
use Pterodactyl\Services\Mounts\MountCreationService;
use Pterodactyl\Services\Mounts\MountDeletionService;
use Pterodactyl\Repositories\Eloquent\MountRepository;
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
Expand Down
Loading

0 comments on commit a043071

Please sign in to comment.