misc_pterodactyl-panel/app/Services/Subusers/SubuserDeletionService.php

71 lines
2.1 KiB
PHP
Raw Normal View History

2017-08-26 18:31:18 +00:00
<?php
2017-09-26 02:43:01 +00:00
/**
2017-08-26 18:31:18 +00:00
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
2017-09-26 02:43:01 +00:00
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
2017-08-26 18:31:18 +00:00
*/
namespace Pterodactyl\Services\Subusers;
2017-09-25 03:28:16 +00:00
use Pterodactyl\Models\Subuser;
2017-08-26 18:31:18 +00:00
use Illuminate\Database\ConnectionInterface;
use Pterodactyl\Services\DaemonKeys\DaemonKeyDeletionService;
2017-08-26 18:31:18 +00:00
use Pterodactyl\Contracts\Repository\SubuserRepositoryInterface;
class SubuserDeletionService
{
/**
* @var \Illuminate\Database\ConnectionInterface
*/
protected $connection;
/**
* @var \Pterodactyl\Services\DaemonKeys\DaemonKeyDeletionService
2017-08-26 18:31:18 +00:00
*/
protected $keyDeletionService;
2017-08-26 18:31:18 +00:00
/**
* @var \Pterodactyl\Contracts\Repository\SubuserRepositoryInterface
*/
protected $repository;
/**
* SubuserDeletionService constructor.
*
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Pterodactyl\Services\DaemonKeys\DaemonKeyDeletionService $keyDeletionService
* @param \Pterodactyl\Contracts\Repository\SubuserRepositoryInterface $repository
2017-08-26 18:31:18 +00:00
*/
public function __construct(
ConnectionInterface $connection,
DaemonKeyDeletionService $keyDeletionService,
SubuserRepositoryInterface $repository
2017-08-26 18:31:18 +00:00
) {
$this->connection = $connection;
$this->keyDeletionService = $keyDeletionService;
2017-08-26 18:31:18 +00:00
$this->repository = $repository;
}
/**
* Delete a subuser and their associated permissions from the Panel and Daemon.
*
2017-09-25 03:28:16 +00:00
* @param int|\Pterodactyl\Models\Subuser $subuser
2017-08-26 18:31:18 +00:00
*
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function handle($subuser)
{
2017-09-25 03:28:16 +00:00
if (! $subuser instanceof Subuser) {
$subuser = $this->repository->find($subuser);
}
2017-08-26 18:31:18 +00:00
$this->connection->beginTransaction();
$this->keyDeletionService->handle($subuser->server_id, $subuser->user_id);
$this->repository->delete($subuser->id);
$this->connection->commit();
2017-08-26 18:31:18 +00:00
}
}