2017-07-23 01:15:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Services\Servers;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Server;
|
2017-09-25 02:12:30 +00:00
|
|
|
use Illuminate\Database\ConnectionInterface;
|
2018-01-20 22:03:23 +00:00
|
|
|
use Pterodactyl\Traits\Services\ReturnsUpdatedModels;
|
2017-07-23 01:15:01 +00:00
|
|
|
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
2017-09-25 02:12:30 +00:00
|
|
|
use Pterodactyl\Services\DaemonKeys\DaemonKeyCreationService;
|
|
|
|
use Pterodactyl\Services\DaemonKeys\DaemonKeyDeletionService;
|
2017-07-23 01:15:01 +00:00
|
|
|
|
|
|
|
class DetailsModificationService
|
|
|
|
{
|
2018-01-20 22:03:23 +00:00
|
|
|
use ReturnsUpdatedModels;
|
2017-07-23 01:15:01 +00:00
|
|
|
|
|
|
|
/**
|
2018-01-20 22:03:23 +00:00
|
|
|
* @var \Illuminate\Database\ConnectionInterface
|
2017-07-23 01:15:01 +00:00
|
|
|
*/
|
2018-01-20 22:03:23 +00:00
|
|
|
private $connection;
|
2017-07-23 01:15:01 +00:00
|
|
|
|
2017-09-25 02:12:30 +00:00
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\DaemonKeys\DaemonKeyCreationService
|
|
|
|
*/
|
2018-01-20 22:03:23 +00:00
|
|
|
private $keyCreationService;
|
2017-09-25 02:12:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\DaemonKeys\DaemonKeyDeletionService
|
|
|
|
*/
|
2018-01-20 22:03:23 +00:00
|
|
|
private $keyDeletionService;
|
2017-09-25 02:12:30 +00:00
|
|
|
|
2017-07-23 01:15:01 +00:00
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
|
|
|
|
*/
|
2018-01-20 22:03:23 +00:00
|
|
|
private $repository;
|
2017-07-24 00:57:43 +00:00
|
|
|
|
2017-07-23 01:15:01 +00:00
|
|
|
/**
|
|
|
|
* DetailsModificationService constructor.
|
|
|
|
*
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param \Illuminate\Database\ConnectionInterface $connection
|
2017-09-25 02:12:30 +00:00
|
|
|
* @param \Pterodactyl\Services\DaemonKeys\DaemonKeyCreationService $keyCreationService
|
|
|
|
* @param \Pterodactyl\Services\DaemonKeys\DaemonKeyDeletionService $keyDeletionService
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $repository
|
2017-07-23 01:15:01 +00:00
|
|
|
*/
|
|
|
|
public function __construct(
|
2017-09-25 02:12:30 +00:00
|
|
|
ConnectionInterface $connection,
|
|
|
|
DaemonKeyCreationService $keyCreationService,
|
|
|
|
DaemonKeyDeletionService $keyDeletionService,
|
2018-01-20 22:03:23 +00:00
|
|
|
ServerRepository $repository
|
2017-07-23 01:15:01 +00:00
|
|
|
) {
|
2017-09-25 02:12:30 +00:00
|
|
|
$this->connection = $connection;
|
|
|
|
$this->keyCreationService = $keyCreationService;
|
|
|
|
$this->keyDeletionService = $keyDeletionService;
|
2017-07-23 01:15:01 +00:00
|
|
|
$this->repository = $repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the details for a single server instance.
|
|
|
|
*
|
2018-01-20 22:03:23 +00:00
|
|
|
* @param \Pterodactyl\Models\Server $server
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param array $data
|
2018-01-20 22:03:23 +00:00
|
|
|
* @return bool|\Pterodactyl\Models\Server
|
2017-07-23 01:15:01 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
2017-09-14 04:07:02 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-07-23 01:15:01 +00:00
|
|
|
*/
|
2018-01-20 22:03:23 +00:00
|
|
|
public function handle(Server $server, array $data)
|
2017-07-23 01:15:01 +00:00
|
|
|
{
|
2017-09-25 02:12:30 +00:00
|
|
|
$this->connection->beginTransaction();
|
2018-01-20 22:03:23 +00:00
|
|
|
|
|
|
|
$response = $this->repository->setFreshModel($this->getUpdatedModel())->update($server->id, [
|
2018-02-24 17:57:12 +00:00
|
|
|
'external_id' => array_get($data, 'external_id'),
|
2018-01-01 18:23:45 +00:00
|
|
|
'owner_id' => array_get($data, 'owner_id'),
|
|
|
|
'name' => array_get($data, 'name'),
|
2018-01-21 20:45:20 +00:00
|
|
|
'description' => array_get($data, 'description') ?? '',
|
2017-07-23 01:15:01 +00:00
|
|
|
], true, true);
|
|
|
|
|
2018-01-20 22:03:23 +00:00
|
|
|
if ((int) array_get($data, 'owner_id', 0) !== (int) $server->owner_id) {
|
2017-09-25 02:12:30 +00:00
|
|
|
$this->keyDeletionService->handle($server, $server->owner_id);
|
|
|
|
$this->keyCreationService->handle($server->id, array_get($data, 'owner_id'));
|
2017-07-23 01:15:01 +00:00
|
|
|
}
|
|
|
|
|
2017-09-25 02:12:30 +00:00
|
|
|
$this->connection->commit();
|
2017-07-23 01:15:01 +00:00
|
|
|
|
2018-01-20 22:03:23 +00:00
|
|
|
return $response;
|
2017-07-23 01:15:01 +00:00
|
|
|
}
|
|
|
|
}
|