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

67 lines
2 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
*/
2017-11-03 21:52:18 +00:00
private $connection;
2017-08-26 18:31:18 +00:00
/**
* @var \Pterodactyl\Services\DaemonKeys\DaemonKeyDeletionService
2017-08-26 18:31:18 +00:00
*/
2017-11-03 21:52:18 +00:00
private $keyDeletionService;
2017-08-26 18:31:18 +00:00
/**
* @var \Pterodactyl\Contracts\Repository\SubuserRepositoryInterface
*/
2017-11-03 21:52:18 +00:00
private $repository;
2017-08-26 18:31:18 +00:00
/**
* SubuserDeletionService constructor.
*
2019-09-06 04:32:57 +00:00
* @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.
*
* @param \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 $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
}
}