From 9cf74328358f01660ba205ba4e5def00d68a2541 Mon Sep 17 00:00:00 2001 From: Jamsheed Mistri Date: Sun, 2 Dec 2018 23:39:40 -0800 Subject: [PATCH 1/8] Adding bulk reinstall command --- .../Server/BulkReinstallActionCommand.php | 113 ++++++++++++++++++ .../Repository/ServerRepositoryInterface.php | 9 ++ .../Eloquent/ServerRepository.php | 20 ++++ resources/lang/en/command/messages.php | 4 + 4 files changed, 146 insertions(+) create mode 100644 app/Console/Commands/Server/BulkReinstallActionCommand.php diff --git a/app/Console/Commands/Server/BulkReinstallActionCommand.php b/app/Console/Commands/Server/BulkReinstallActionCommand.php new file mode 100644 index 00000000..86c40a9e --- /dev/null +++ b/app/Console/Commands/Server/BulkReinstallActionCommand.php @@ -0,0 +1,113 @@ +. + * + * 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\Contracts\Repository\ServerRepositoryInterface; +use Pterodactyl\Services\Servers\ServerConfigurationStructureService; +use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface as DaemonServerRepositoryInterface; + +class BulkReinstallActionCommand extends Command +{ + /** + * @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService + */ + protected $configurationStructureService; + + /** + * @var \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface + */ + protected $daemonRepository; + + /** + * @var string + */ + protected $description = 'Reinstall a single server, all servers on a node, or all servers on the panel.'; + + /** + * @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface + */ + protected $repository; + + /** + * @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. + * + * @param \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface $daemonRepository + * @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $configurationStructureService + * @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository + */ + public function __construct( + DaemonServerRepositoryInterface $daemonRepository, + ServerConfigurationStructureService $configurationStructureService, + ServerRepositoryInterface $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'))) { + 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\Database\Eloquent\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/Contracts/Repository/ServerRepositoryInterface.php b/app/Contracts/Repository/ServerRepositoryInterface.php index f00d29d8..f3ef7daa 100644 --- a/app/Contracts/Repository/ServerRepositoryInterface.php +++ b/app/Contracts/Repository/ServerRepositoryInterface.php @@ -36,6 +36,15 @@ interface ServerRepositoryInterface extends RepositoryInterface, SearchableInter */ public function getDataForRebuild(int $server = null, int $node = null): Collection; + /** + * Return a collection of servers with their associated data for reinstall operations. + * + * @param int|null $server + * @param int|null $node + * @return \Illuminate\Support\Collection + */ + public function getDataForReinstall(int $server = null, int $node = null): Collection; + /** * Return a server model and all variables associated with the server. * diff --git a/app/Repositories/Eloquent/ServerRepository.php b/app/Repositories/Eloquent/ServerRepository.php index 3c0248be..ccb69af5 100644 --- a/app/Repositories/Eloquent/ServerRepository.php +++ b/app/Repositories/Eloquent/ServerRepository.php @@ -75,6 +75,26 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt return $instance->get($this->getColumns()); } + /** + * Return a collection of servers with their associated data for reinstall operations. + * + * @param int|null $server + * @param int|null $node + * @return \Illuminate\Support\Collection + */ + public function getDataForReinstall(int $server = null, int $node = null): Collection + { + $instance = $this->getBuilder()->with(['allocation', 'allocations', 'pack', 'egg', 'node']); + + if (! is_null($server) && is_null($node)) { + $instance = $instance->where('id', '=', $server); + } elseif (is_null($server) && ! is_null($node)) { + $instance = $instance->where('node_id', '=', $node); + } + + return $instance->get($this->getColumns()); + } + /** * Return a server model and all variables associated with the server. * diff --git a/resources/lang/en/command/messages.php b/resources/lang/en/command/messages.php index 8741fc42..cd10ff49 100644 --- a/resources/lang/en/command/messages.php +++ b/resources/lang/en/command/messages.php @@ -42,6 +42,10 @@ return [ ], 'server' => [ 'rebuild_failed' => 'Rebuild request for ":name" (#:id) on node ":node" failed with error: :message', + 'reinstall' => [ + 'failed' => 'Reinstall request for ":name" (#:id) on node ":node" failed with error: :message', + 'confirm' => 'You are about to reinstall against a group of servers. Do you wish to continue?' + ], 'power' => [ 'confirm' => 'You are about to perform a :action against :count servers. Do you wish to continue?', 'action_failed' => 'Power action request for ":name" (#:id) on node ":node" failed with error: :message', From 34b166cde934c51a2db1aea8177082ab071d7191 Mon Sep 17 00:00:00 2001 From: Jamsheed Mistri Date: Sun, 2 Dec 2018 23:42:35 -0800 Subject: [PATCH 2/8] StyleCI fixes --- app/Console/Commands/Server/BulkReinstallActionCommand.php | 2 +- resources/lang/en/command/messages.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Console/Commands/Server/BulkReinstallActionCommand.php b/app/Console/Commands/Server/BulkReinstallActionCommand.php index 86c40a9e..ccca701a 100644 --- a/app/Console/Commands/Server/BulkReinstallActionCommand.php +++ b/app/Console/Commands/Server/BulkReinstallActionCommand.php @@ -69,7 +69,7 @@ class BulkReinstallActionCommand extends Command */ public function handle() { - $servers = $this->getServersToProcess(); + $servers = $this->getServersToProcess(); if (! $this->confirm(trans('command/messages.server.reinstall.confirm'))) { return; diff --git a/resources/lang/en/command/messages.php b/resources/lang/en/command/messages.php index cd10ff49..71731a2d 100644 --- a/resources/lang/en/command/messages.php +++ b/resources/lang/en/command/messages.php @@ -44,7 +44,7 @@ return [ 'rebuild_failed' => 'Rebuild request for ":name" (#:id) on node ":node" failed with error: :message', 'reinstall' => [ 'failed' => 'Reinstall request for ":name" (#:id) on node ":node" failed with error: :message', - 'confirm' => 'You are about to reinstall against a group of servers. Do you wish to continue?' + 'confirm' => 'You are about to reinstall against a group of servers. Do you wish to continue?', ], 'power' => [ 'confirm' => 'You are about to perform a :action against :count servers. Do you wish to continue?', From 0112091827435d46fddaa3747fcd62efdc997f55 Mon Sep 17 00:00:00 2001 From: Jordy Date: Sun, 23 Jun 2019 12:52:57 +0200 Subject: [PATCH 3/8] Update README.md changed guides website url --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8ff13e8c..4dd56ba1 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ What more are you waiting for? Make game servers a first class citizen on your p ![Image](https://cdn.pterodactyl.io/site-assets/mockup-macbook-grey.png) ## Support & Documentation -Support for using Pterodactyl can be found on our [Documentation Website](https://pterodactyl.io/project/introduction.html), [Guides Website](https://guides.pterodactyl.io), or via our [Discord Chat](https://discord.gg/QRDZvVm). +Support for using Pterodactyl can be found on our [Documentation Website](https://pterodactyl.io/project/introduction.html), [Guides Website](https://pterodactyl.io/community/about.html), or via our [Discord Chat](https://discord.gg/QRDZvVm). ### Supported Games We support a huge variety of games by utilizing Docker containers to isolate each instance, giving you the power to host your games across the world without having to bloat each physical machine with additional dependencies. From b252374d394b7940162693aae7c69d1f036ac3d2 Mon Sep 17 00:00:00 2001 From: Austin Hickey Date: Mon, 1 Jul 2019 21:30:46 -0400 Subject: [PATCH 4/8] Add link to Laravel Framework validation rules/docs Small QoL fix for adding variables to eggs: References to "Laravel Framework validation rules" are now linked to the official Laravel 5.7 docs referring to the validation syntax. Links are also set to open reference in a new tab/window. --- resources/themes/pterodactyl/admin/eggs/variables.blade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/themes/pterodactyl/admin/eggs/variables.blade.php b/resources/themes/pterodactyl/admin/eggs/variables.blade.php index f49886ee..d84aa415 100644 --- a/resources/themes/pterodactyl/admin/eggs/variables.blade.php +++ b/resources/themes/pterodactyl/admin/eggs/variables.blade.php @@ -81,7 +81,7 @@
-

These rules are defined using standard Laravel Framework validation rules.

+

These rules are defined using standard Laravel Framework validation rules.