From fa9431c54d0786f4a00ae1da95d46908f64da9dd Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 23 Jan 2021 14:12:15 -0800 Subject: [PATCH] Slightly cleanup --- .../PruneOrphanedBackupsCommand.php | 8 +- .../Migration/CleanOrphanedApiKeysCommand.php | 57 --------- .../Commands/Overrides/KeyGenerateCommand.php | 6 +- .../Commands/Overrides/SeedCommand.php | 8 +- app/Console/Commands/Overrides/UpCommand.php | 5 +- .../Server/BulkReinstallActionCommand.php | 109 ------------------ app/Console/Kernel.php | 9 +- resources/lang/en/command/messages.php | 5 - 8 files changed, 16 insertions(+), 191 deletions(-) delete mode 100644 app/Console/Commands/Migration/CleanOrphanedApiKeysCommand.php delete mode 100644 app/Console/Commands/Server/BulkReinstallActionCommand.php diff --git a/app/Console/Commands/Maintenance/PruneOrphanedBackupsCommand.php b/app/Console/Commands/Maintenance/PruneOrphanedBackupsCommand.php index 77ad86ad..4aef591a 100644 --- a/app/Console/Commands/Maintenance/PruneOrphanedBackupsCommand.php +++ b/app/Console/Commands/Maintenance/PruneOrphanedBackupsCommand.php @@ -12,7 +12,7 @@ class PruneOrphanedBackupsCommand extends Command /** * @var string */ - protected $signature = 'p:maintenance:prune-backups {--since-minutes=30}'; + protected $signature = 'p:maintenance:prune-backups {--prune-age=}'; /** * @var string @@ -21,9 +21,9 @@ class PruneOrphanedBackupsCommand extends Command public function handle(BackupRepository $repository) { - $since = $this->option('since-minutes'); - if (!is_digit($since)) { - throw new InvalidArgumentException('The --since-minutes option must be a valid numeric digit.'); + $since = $this->option('prune-age') ?? config('backups.prune_age', 360); + if (!$since || !is_digit($since)) { + throw new InvalidArgumentException('The "--prune-age" argument must be a value greater than 0.'); } $query = $repository->getBuilder() diff --git a/app/Console/Commands/Migration/CleanOrphanedApiKeysCommand.php b/app/Console/Commands/Migration/CleanOrphanedApiKeysCommand.php deleted file mode 100644 index 7a7ff33a..00000000 --- a/app/Console/Commands/Migration/CleanOrphanedApiKeysCommand.php +++ /dev/null @@ -1,57 +0,0 @@ -repository = $repository; - } - - /** - * Delete all orphaned API keys from the database when upgrading from 0.6 to 0.7. - * - * @return void|null - */ - public function handle() - { - $count = $this->repository->findCountWhere([['key_type', '=', ApiKey::TYPE_NONE]]); - $continue = $this->confirm( - 'This action will remove ' . $count . ' keys from the database. Are you sure you wish to continue?', - false - ); - - if (!$continue) { - return null; - } - - $this->info('Deleting keys...'); - $this->repository->deleteWhere([['key_type', '=', ApiKey::TYPE_NONE]]); - $this->info('Keys were successfully deleted.'); - } -} diff --git a/app/Console/Commands/Overrides/KeyGenerateCommand.php b/app/Console/Commands/Overrides/KeyGenerateCommand.php index 8aa30a9e..bc8a4edb 100644 --- a/app/Console/Commands/Overrides/KeyGenerateCommand.php +++ b/app/Console/Commands/Overrides/KeyGenerateCommand.php @@ -13,12 +13,12 @@ class KeyGenerateCommand extends BaseKeyGenerateCommand public function handle() { if (!empty(config('app.key')) && $this->input->isInteractive()) { - $this->output->warning(trans('command/messages.key.warning')); - if (!$this->confirm(trans('command/messages.key.confirm'))) { + $this->output->warning('It appears you have already configured an application encryption key. Continuing with this process with overwrite that key and cause data corruption for any existing encrypted data. DO NOT CONTINUE UNLESS YOU KNOW WHAT YOU ARE DOING.'); + if (!$this->confirm('I understand the consequences of performing this command and accept all responsibility for the loss of encrypted data.')) { return; } - if (!$this->confirm(trans('command/messages.key.final_confirm'))) { + if (!$this->confirm('Are you sure you wish to continue? Changing the application encryption key WILL CAUSE DATA LOSS.')) { return; } } diff --git a/app/Console/Commands/Overrides/SeedCommand.php b/app/Console/Commands/Overrides/SeedCommand.php index 91b555d4..4dbad13e 100644 --- a/app/Console/Commands/Overrides/SeedCommand.php +++ b/app/Console/Commands/Overrides/SeedCommand.php @@ -10,12 +10,10 @@ class SeedCommand extends BaseSeedCommand use RequiresDatabaseMigrations; /** - * Block someone from running this seed command if they have not completed the migration - * process. - * - * @return int + * Block someone from running this seed command if they have not completed + * the migration process. */ - public function handle() + public function handle(): int { if (!$this->hasCompletedMigrations()) { return $this->showMigrationWarning(); diff --git a/app/Console/Commands/Overrides/UpCommand.php b/app/Console/Commands/Overrides/UpCommand.php index 3a5f3461..0be54319 100644 --- a/app/Console/Commands/Overrides/UpCommand.php +++ b/app/Console/Commands/Overrides/UpCommand.php @@ -10,9 +10,10 @@ class UpCommand extends BaseUpCommand use RequiresDatabaseMigrations; /** - * @return bool|int + * Block someone from running this up command if they have not completed + * the migration process. */ - public function handle() + public function handle(): int { if (!$this->hasCompletedMigrations()) { return $this->showMigrationWarning(); diff --git a/app/Console/Commands/Server/BulkReinstallActionCommand.php b/app/Console/Commands/Server/BulkReinstallActionCommand.php deleted file mode 100644 index e6250cc3..00000000 --- a/app/Console/Commands/Server/BulkReinstallActionCommand.php +++ /dev/null @@ -1,109 +0,0 @@ -. - * - * This software is licensed under the terms of the MIT license. - * https://opensource.org/licenses/MIT - */ - -namespace Pterodactyl\Console\Commands\Server; - -use Webmozart\Assert\Assert; -use Illuminate\Console\Command; -use GuzzleHttp\Exception\RequestException; -use Pterodactyl\Repositories\Eloquent\ServerRepository; -use Pterodactyl\Repositories\Wings\DaemonServerRepository; -use Pterodactyl\Services\Servers\ServerConfigurationStructureService; - -class BulkReinstallActionCommand extends Command -{ - /** - * @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService - */ - private $configurationStructureService; - - /** - * @var \Pterodactyl\Repositories\Wings\DaemonServerRepository - */ - private $daemonRepository; - - /** - * @var \Pterodactyl\Repositories\Eloquent\ServerRepository - */ - private $repository; - - /** - * @var string - */ - protected $description = 'Reinstall a single server, all servers on a node, or all servers on the panel.'; - - /** - * @var string - */ - protected $signature = 'p:server:reinstall - {server? : The ID of the server to reinstall.} - {--node= : ID of the node to reinstall all servers on. Ignored if server is passed.}'; - - /** - * BulkReinstallActionCommand constructor. - */ - public function __construct( - DaemonServerRepository $daemonRepository, - ServerConfigurationStructureService $configurationStructureService, - ServerRepository $repository - ) { - parent::__construct(); - - $this->configurationStructureService = $configurationStructureService; - $this->daemonRepository = $daemonRepository; - $this->repository = $repository; - } - - /** - * Handle command execution. - */ - public function handle() - { - $servers = $this->getServersToProcess(); - - if (!$this->confirm(trans('command/messages.server.reinstall.confirm')) && $this->input->isInteractive()) { - return; - } - - $bar = $this->output->createProgressBar(count($servers)); - - $servers->each(function ($server) use ($bar) { - $bar->clear(); - - try { - $this->daemonRepository->setServer($server)->reinstall(); - } catch (RequestException $exception) { - $this->output->error(trans('command/messages.server.reinstall.failed', [ - 'name' => $server->name, - 'id' => $server->id, - 'node' => $server->node->name, - 'message' => $exception->getMessage(), - ])); - } - - $bar->advance(); - $bar->display(); - }); - - $this->line(''); - } - - /** - * Return the servers to be reinstalled. - * - * @return \Illuminate\Support\Collection - */ - private function getServersToProcess() - { - Assert::nullOrIntegerish($this->argument('server'), 'Value passed in server argument must be null or an integer, received %s.'); - Assert::nullOrIntegerish($this->option('node'), 'Value passed in node option must be null or integer, received %s.'); - - return $this->repository->getDataForReinstall($this->argument('server'), $this->option('node')); - } -} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index b5f8067e..d5fa25ec 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -23,12 +23,9 @@ class Kernel extends ConsoleKernel // Execute scheduled commands for servers every minute, as if there was a normal cron running. $schedule->command('p:schedule:process')->everyMinute()->withoutOverlapping(); - // Every 30 minutes, run the backup pruning command so that any abandoned backups can be deleted. - $pruneAge = config('backups.prune_age', 360); // Defaults to 6 hours (time is in minuteS) - if ($pruneAge > 0) { - $schedule->command('p:maintenance:prune-backups', [ - '--since-minutes' => $pruneAge, - ])->everyThirtyMinutes(); + if (config('backups.prune_age')) { + // Every 30 minutes, run the backup pruning command so that any abandoned backups can be deleted. + $schedule->command('p:maintenance:prune-backups')->everyThirtyMinutes(); } // Every day cleanup any internal backups of service files. diff --git a/resources/lang/en/command/messages.php b/resources/lang/en/command/messages.php index 002c699b..e135a1ec 100644 --- a/resources/lang/en/command/messages.php +++ b/resources/lang/en/command/messages.php @@ -1,11 +1,6 @@ [ - 'warning' => 'It appears you have already configured an application encryption key. Continuing with this process with overwrite that key and cause data corruption for any existing encrypted data. DO NOT CONTINUE UNLESS YOU KNOW WHAT YOU ARE DOING.', - 'confirm' => 'I understand the consequences of performing this command and accept all responsibility for the loss of encrypted data.', - 'final_confirm' => 'Are you sure you wish to continue? Changing the application encryption key WILL CAUSE DATA LOSS.', - ], 'location' => [ 'no_location_found' => 'Could not locate a record matching the provided short code.', 'ask_short' => 'Location Short Code',