Remove ServerRepository and ServerRepositoryInterface

This commit is contained in:
Lance Pioch 2022-10-20 21:17:03 -04:00
parent 22d560de64
commit 4d7ea155b1
19 changed files with 63 additions and 146 deletions

View file

@ -2,13 +2,13 @@
namespace Pterodactyl\Http\Controllers\Api\Remote\Servers;
use Carbon\CarbonImmutable;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Pterodactyl\Models\Server;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Repositories\Eloquent\ServerRepository;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Container\ContainerExceptionInterface;
use Pterodactyl\Events\Server\Installed as ServerInstalled;
use Illuminate\Contracts\Events\Dispatcher as EventDispatcher;
use Pterodactyl\Http\Requests\Api\Remote\InstallationDataRequest;
@ -18,18 +18,16 @@ class ServerInstallController extends Controller
/**
* ServerInstallController constructor.
*/
public function __construct(private ServerRepository $repository, private EventDispatcher $eventDispatcher)
public function __construct(private EventDispatcher $eventDispatcher)
{
}
/**
* Returns installation information for a server.
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function index(Request $request, string $uuid): JsonResponse
{
$server = $this->repository->getByUuid($uuid);
$server = Server::findOrFailByUuid($uuid);
$egg = $server->egg;
return new JsonResponse([
@ -42,23 +40,27 @@ class ServerInstallController extends Controller
/**
* Updates the installation state of a server.
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function store(InstallationDataRequest $request, string $uuid): JsonResponse
{
$server = $this->repository->getByUuid($uuid);
$server = Server::findOrFailByUuid($uuid);
$status = $request->boolean('successful') ? null : Server::STATUS_INSTALL_FAILED;
if ($server->status === Server::STATUS_SUSPENDED) {
$status = Server::STATUS_SUSPENDED;
}
$this->repository->update($server->id, ['status' => $status, 'installed_at' => CarbonImmutable::now()], true, true);
$previouslyInstalledAt = $server->installed_at;
$server->status = $status;
$server->installed_at = now();
$server->save();
// If the server successfully installed, fire installed event.
// This logic allows individually disabling install and reinstall notifications separately.
$isInitialInstall = is_null($server->installed_at);
$isInitialInstall = is_null($previouslyInstalledAt);
if ($isInitialInstall && config()->get('pterodactyl.email.send_install_notification', true)) {
$this->eventDispatcher->dispatch(new ServerInstalled($server));
} elseif (!$isInitialInstall && config()->get('pterodactyl.email.send_reinstall_notification', true)) {