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;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
* @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,
|
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;
|
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\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);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|