Merge branch 'develop' into feature/api-v1

# Conflicts:
#	app/Contracts/Repository/RepositoryInterface.php
#	app/Repositories/Eloquent/EloquentRepository.php
#	app/Services/Nodes/NodeUpdateService.php
#	tests/Unit/Services/Nodes/NodeUpdateServiceTest.php
This commit is contained in:
Dane Everitt 2018-01-10 20:55:22 -06:00
commit 800e2df6b2
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
187 changed files with 1878 additions and 3143 deletions

View file

@ -83,11 +83,11 @@ class SetDefaultAllocationService
}
$this->connection->beginTransaction();
$this->serverRepository->withoutFresh()->update($server->id, ['allocation_id' => $model->id]);
$this->serverRepository->withoutFreshModel()->update($server->id, ['allocation_id' => $model->id]);
// Update on the daemon.
try {
$this->daemonRepository->setAccessServer($server->uuid)->setNode($server->node_id)->update([
$this->daemonRepository->setServer($server)->update([
'build' => [
'default' => [
'ip' => $model->ip,

View file

@ -40,7 +40,7 @@ class PermissionService
public function create($key, $permission)
{
// @todo handle an array of permissions to do a mass assignment?
return $this->repository->withoutFresh()->create([
return $this->repository->withoutFreshModel()->create([
'key_id' => $key,
'permission' => $permission,
]);

View file

@ -75,7 +75,7 @@ class DaemonKeyCreationService
{
$secret = DaemonKeyRepositoryInterface::INTERNAL_KEY_IDENTIFIER . str_random(40);
$this->repository->withoutFresh()->create([
$this->repository->withoutFreshModel()->create([
'user_id' => $user,
'server_id' => $server,
'secret' => $secret,

View file

@ -108,7 +108,7 @@ class DaemonKeyDeletionService
$this->repository->delete($key->id);
try {
$this->daemonRepository->setNode($server->node_id)->revokeAccessKey($key->secret);
$this->daemonRepository->setServer($server)->revokeAccessKey($key->secret);
} catch (RequestException $exception) {
$response = $exception->getResponse();
$this->connection->rollBack();

View file

@ -78,7 +78,7 @@ class DaemonKeyUpdateService
Assert::integerish($key, 'First argument passed to handle must be an integer, received %s.');
$secret = DaemonKeyRepositoryInterface::INTERNAL_KEY_IDENTIFIER . str_random(40);
$this->repository->withoutFresh()->update($key, [
$this->repository->withoutFreshModel()->update($key, [
'secret' => $secret,
'expires_at' => $this->carbon->now()->addMinutes($this->config->get('pterodactyl.api.key_expire_time'))->toDateTimeString(),
]);

View file

@ -46,22 +46,20 @@ class RevokeMultipleDaemonKeysService
*
* @param \Pterodactyl\Models\User $user
* @param bool $ignoreConnectionErrors
*
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
*/
public function handle(User $user, bool $ignoreConnectionErrors = false)
{
$keys = $this->repository->getKeysForRevocation($user);
$keys->groupBy('server.node_id')->each(function ($group, $node) use ($ignoreConnectionErrors) {
$keys->groupBy('node.id')->each(function ($group, $nodeId) use ($ignoreConnectionErrors) {
try {
$this->daemonRepository->setNode($node)->revokeAccessKey(collect($group)->pluck('secret')->toArray());
$this->daemonRepository->setNode(collect($group)->first()->getRelation('node'))->revokeAccessKey(collect($group)->pluck('secret')->toArray());
} catch (RequestException $exception) {
if (! $ignoreConnectionErrors) {
throw new DaemonConnectionException($exception);
}
$this->setConnectionException($node, $exception);
$this->setConnectionException($nodeId, $exception);
}
$this->repository->deleteKeys(collect($group)->pluck('id')->toArray());

View file

@ -69,7 +69,7 @@ class DatabasePasswordService
$this->dynamic->set('dynamic', $database->database_host_id);
$this->connection->beginTransaction();
$updated = $this->repository->withoutFresh()->update($database->id, [
$updated = $this->repository->withoutFreshModel()->update($database->id, [
'password' => $this->encrypter->encrypt($password),
]);

View file

@ -57,6 +57,6 @@ class EggUpdateService
}
}
$this->repository->withoutFresh()->update($egg->id, $data);
$this->repository->withoutFreshModel()->update($egg->id, $data);
}
}

View file

@ -52,7 +52,7 @@ class InstallScriptService
}
}
$this->repository->withoutFresh()->update($egg->id, [
$this->repository->withoutFreshModel()->update($egg->id, [
'script_install' => array_get($data, 'script_install'),
'script_is_privileged' => array_get($data, 'script_is_privileged', 1),
'script_entry' => array_get($data, 'script_entry'),

View file

@ -89,14 +89,14 @@ class EggUpdateImporterService
// Update Existing Variables
collect($parsed->variables)->each(function ($variable) use ($egg) {
$this->variableRepository->withoutFresh()->updateOrCreate([
$this->variableRepository->withoutFreshModel()->updateOrCreate([
'egg_id' => $egg,
'env_variable' => $variable->env_variable,
], collect($variable)->except(['egg_id', 'env_variable'])->toArray());
});
$imported = collect($parsed->variables)->pluck('env_variable')->toArray();
$existing = $this->variableRepository->withColumns(['id', 'env_variable'])->findWhere([['egg_id', '=', $egg]]);
$existing = $this->variableRepository->setColumns(['id', 'env_variable'])->findWhere([['egg_id', '=', $egg]]);
// Delete variables not present in the import.
collect($existing)->each(function ($variable) use ($egg, $imported) {

View file

@ -49,7 +49,7 @@ class VariableUpdateService
]));
}
$search = $this->repository->withColumns('id')->findCountWhere([
$search = $this->repository->setColumns('id')->findCountWhere([
['env_variable', '=', array_get($data, 'env_variable')],
['egg_id', '=', $variable->egg_id],
['id', '!=', $variable->id],
@ -64,7 +64,7 @@ class VariableUpdateService
$options = array_get($data, 'options') ?? [];
return $this->repository->withoutFresh()->update($variable->id, array_merge($data, [
return $this->repository->withoutFreshModel()->update($variable->id, array_merge($data, [
'user_viewable' => in_array('user_viewable', $options),
'user_editable' => in_array('user_editable', $options),
]));

View file

@ -42,6 +42,6 @@ class NestUpdateService
unset($data['author']);
}
$this->repository->withoutFresh()->update($nest, $data);
$this->repository->withoutFreshModel()->update($nest, $data);
}
}

View file

@ -63,7 +63,7 @@ class NodeDeletionService
$node = $node->id;
}
$servers = $this->serverRepository->withColumns('id')->findCountWhere([['node_id', '=', $node]]);
$servers = $this->serverRepository->setColumns('id')->findCountWhere([['node_id', '=', $node]]);
if ($servers > 0) {
throw new HasActiveServersException($this->translator->trans('exceptions.node.servers_attached'));
}

View file

@ -65,11 +65,11 @@ class NodeUpdateService
if ($this->getUpdatedModel()) {
$response = $this->repository->update($node->id, $data);
} else {
$response = $this->repository->withoutFresh()->update($node->id, $data);
$response = $this->repository->withoutFreshModel()->update($node->id, $data);
}
try {
$this->configRepository->setNode($node->id)->update();
$this->configRepository->setNode($node)->update();
} catch (RequestException $exception) {
throw new DaemonConnectionException($exception);
}

View file

@ -69,7 +69,7 @@ class PackDeletionService
public function handle($pack)
{
if (! $pack instanceof Pack) {
$pack = $this->repository->withColumns(['id', 'uuid'])->find($pack);
$pack = $this->repository->setColumns(['id', 'uuid'])->find($pack);
}
$count = $this->serverRepository->findCountWhere([['pack_id', '=', $pack->id]]);

View file

@ -54,7 +54,7 @@ class PackUpdateService
public function handle($pack, array $data)
{
if (! $pack instanceof Pack) {
$pack = $this->repository->withColumns(['id', 'egg_id'])->find($pack);
$pack = $this->repository->setColumns(['id', 'egg_id'])->find($pack);
}
if ((int) array_get($data, 'egg_id', $pack->egg_id) !== $pack->egg_id) {
@ -70,6 +70,6 @@ class PackUpdateService
$data['visible'] = isset($data['visible']);
$data['locked'] = isset($data['locked']);
return $this->repository->withoutFresh()->update($pack->id, $data);
return $this->repository->withoutFreshModel()->update($pack->id, $data);
}
}

View file

@ -1,16 +1,9 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Services\Schedules;
use Carbon\Carbon;
use Cron\CronExpression;
use Webmozart\Assert\Assert;
use Pterodactyl\Models\Schedule;
use Pterodactyl\Services\Schedules\Tasks\RunTaskService;
use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface;
@ -20,12 +13,17 @@ class ProcessScheduleService
/**
* @var \Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface
*/
protected $repository;
private $repository;
/**
* @var \Pterodactyl\Services\Schedules\Tasks\RunTaskService
*/
protected $runnerService;
private $runnerService;
/**
* @var \Carbon\Carbon|null
*/
private $runTimeOverride;
/**
* ProcessScheduleService constructor.
@ -39,23 +37,31 @@ class ProcessScheduleService
$this->runnerService = $runnerService;
}
/**
* Set the time that this schedule should be run at. This will override the time
* defined on the schedule itself. Useful for triggering one-off task runs.
*
* @param \Carbon\Carbon $time
* @return $this
*/
public function setRunTimeOverride(Carbon $time)
{
$this->runTimeOverride = $time;
return $this;
}
/**
* Process a schedule and push the first task onto the queue worker.
*
* @param int|\Pterodactyl\Models\Schedule $schedule
* @param \Pterodactyl\Models\Schedule $schedule
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function handle($schedule)
public function handle(Schedule $schedule)
{
Assert::true(($schedule instanceof Schedule || is_digit($schedule)),
'First argument passed to handle must be instance of \Pterodactyl\Models\Schedule or an integer, received %s.'
);
if (($schedule instanceof Schedule && ! $schedule->relationLoaded('tasks')) || ! $schedule instanceof Schedule) {
$schedule = $this->repository->getScheduleWithTasks(is_digit($schedule) ? $schedule : $schedule->id);
}
$this->repository->loadTasks($schedule);
$formattedCron = sprintf('%s %s %s * %s *',
$schedule->cron_minute,
@ -66,10 +72,25 @@ class ProcessScheduleService
$this->repository->update($schedule->id, [
'is_processing' => true,
'next_run_at' => CronExpression::factory($formattedCron)->getNextRunDate(),
'next_run_at' => $this->getRunAtTime($formattedCron),
]);
$task = $schedule->tasks->where('sequence_id', 1)->first();
$task = $schedule->getRelation('tasks')->where('sequence_id', 1)->first();
$this->runnerService->handle($task);
}
/**
* Get the timestamp to store in the database as the next_run time for a schedule.
*
* @param string $formatted
* @return \DateTime|string
*/
private function getRunAtTime(string $formatted)
{
if ($this->runTimeOverride instanceof Carbon) {
return $this->runTimeOverride->toDateTimeString();
}
return CronExpression::factory($formatted)->getNextRunDate();
}
}

View file

@ -1,16 +1,8 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Services\Schedules;
use Cron\CronExpression;
use Webmozart\Assert\Assert;
use Pterodactyl\Models\Server;
use Illuminate\Database\ConnectionInterface;
use Pterodactyl\Services\Schedules\Tasks\TaskCreationService;
@ -53,37 +45,32 @@ class ScheduleCreationService
/**
* Create a new schedule for a specific server.
*
* @param int|\Pterodactyl\Models\Server $server
* @param array $data
* @param array $tasks
* @param \Pterodactyl\Models\Server $server
* @param array $data
* @param array $tasks
* @return \Pterodactyl\Models\Schedule
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Service\Schedule\Task\TaskIntervalTooLongException
*/
public function handle($server, array $data, array $tasks = [])
public function handle(Server $server, array $data, array $tasks = [])
{
Assert::true(($server instanceof Server || is_digit($server)),
'First argument passed to handle must be numeric or instance of \Pterodactyl\Models\Server, received %s.'
);
$server = ($server instanceof Server) ? $server->id : $server;
$data['server_id'] = $server;
$data['next_run_at'] = $this->getCronTimestamp($data);
$data = array_merge($data, [
'server_id' => $server->id,
'next_run_at' => $this->getCronTimestamp($data),
]);
$this->connection->beginTransaction();
$schedule = $this->repository->create($data);
if (! empty($tasks)) {
foreach ($tasks as $index => $task) {
$this->taskCreationService->handle($schedule, [
'time_interval' => array_get($task, 'time_interval'),
'time_value' => array_get($task, 'time_value'),
'sequence_id' => $index + 1,
'action' => array_get($task, 'action'),
'payload' => array_get($task, 'payload'),
], false);
}
foreach ($tasks as $index => $task) {
$this->taskCreationService->handle($schedule, [
'time_interval' => array_get($task, 'time_interval'),
'time_value' => array_get($task, 'time_value'),
'sequence_id' => $index + 1,
'action' => array_get($task, 'action'),
'payload' => array_get($task, 'payload'),
], false);
}
$this->connection->commit();

View file

@ -56,7 +56,7 @@ class TaskCreationService
throw new TaskIntervalTooLongException(trans('exceptions.tasks.chain_interval_too_long'));
}
$repository = ($returnModel) ? $this->repository : $this->repository->withoutFresh();
$repository = ($returnModel) ? $this->repository : $this->repository->withoutFreshModel();
$task = $repository->create([
'schedule_id' => $schedule,
'sequence_id' => $data['sequence_id'],

View file

@ -154,7 +154,7 @@ class BuildModificationService
})->toArray());
try {
$this->daemonServerRepository->setNode($server->node_id)->setAccessServer($server->uuid)->update([
$this->daemonServerRepository->setServer($server)->update([
'build' => $this->getBuild(),
]);

View file

@ -1,77 +1,42 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Services\Servers;
use Illuminate\Log\Writer;
use Pterodactyl\Models\Server;
use GuzzleHttp\Exception\RequestException;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface as DaemonServerRepositoryInterface;
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface;
class ContainerRebuildService
{
/**
* @var \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface
*/
protected $daemonServerRepository;
/**
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
*/
protected $repository;
/**
* @var \Illuminate\Log\Writer
*/
protected $writer;
private $repository;
/**
* ContainerRebuildService constructor.
*
* @param \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface $daemonServerRepository
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
* @param \Illuminate\Log\Writer $writer
* @param \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface $repository
*/
public function __construct(
DaemonServerRepositoryInterface $daemonServerRepository,
ServerRepositoryInterface $repository,
Writer $writer
) {
$this->daemonServerRepository = $daemonServerRepository;
public function __construct(ServerRepositoryInterface $repository)
{
$this->repository = $repository;
$this->writer = $writer;
}
/**
* Mark a server for rebuild on next boot cycle.
*
* @param int|\Pterodactyl\Models\Server $server
* @param \Pterodactyl\Models\Server $server
*
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
*/
public function rebuild($server)
public function handle(Server $server)
{
if (! $server instanceof Server) {
$server = $this->repository->find($server);
}
try {
$this->daemonServerRepository->setNode($server->node_id)->setAccessServer($server->uuid)->rebuild();
$this->repository->setServer($server)->rebuild();
} catch (RequestException $exception) {
$response = $exception->getResponse();
$this->writer->warning($exception);
throw new DisplayException(trans('admin/server.exceptions.daemon_exception', [
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
]));
throw new DaemonConnectionException($exception);
}
}
}

View file

@ -94,7 +94,7 @@ class DetailsModificationService
}
$this->connection->beginTransaction();
$this->repository->withoutFresh()->update($server->id, [
$this->repository->withoutFreshModel()->update($server->id, [
'owner_id' => array_get($data, 'owner_id'),
'name' => array_get($data, 'name'),
'description' => array_get($data, 'description', ''),
@ -125,10 +125,10 @@ class DetailsModificationService
}
$this->connection->beginTransaction();
$this->repository->withoutFresh()->update($server->id, ['image' => $image]);
$this->repository->withoutFreshModel()->update($server->id, ['image' => $image]);
try {
$this->daemonServerRepository->setNode($server->node_id)->setAccessServer($server->uuid)->update([
$this->daemonServerRepository->setServer($server)->update([
'build' => [
'image' => $image,
],

View file

@ -9,12 +9,11 @@
namespace Pterodactyl\Services\Servers;
use Illuminate\Log\Writer;
use Pterodactyl\Models\Server;
use GuzzleHttp\Exception\RequestException;
use Illuminate\Database\ConnectionInterface;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface as DaemonServerRepositoryInterface;
class ReinstallServerService
@ -34,29 +33,21 @@ class ReinstallServerService
*/
protected $repository;
/**
* @var \Illuminate\Log\Writer
*/
protected $writer;
/**
* ReinstallService constructor.
*
* @param \Illuminate\Database\ConnectionInterface $database
* @param \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface $daemonServerRepository
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
* @param \Illuminate\Log\Writer $writer
*/
public function __construct(
ConnectionInterface $database,
DaemonServerRepositoryInterface $daemonServerRepository,
ServerRepositoryInterface $repository,
Writer $writer
ServerRepositoryInterface $repository
) {
$this->daemonServerRepository = $daemonServerRepository;
$this->database = $database;
$this->repository = $repository;
$this->writer = $writer;
}
/**
@ -64,6 +55,7 @@ class ReinstallServerService
*
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function reinstall($server)
{
@ -72,20 +64,15 @@ class ReinstallServerService
}
$this->database->beginTransaction();
$this->repository->withoutFresh()->update($server->id, [
$this->repository->withoutFreshModel()->update($server->id, [
'installed' => 0,
]);
try {
$this->daemonServerRepository->setNode($server->node_id)->setAccessServer($server->uuid)->reinstall();
$this->daemonServerRepository->setServer($server)->reinstall();
$this->database->commit();
} catch (RequestException $exception) {
$response = $exception->getResponse();
$this->writer->warning($exception);
throw new DisplayException(trans('admin/server.exceptions.daemon_exception', [
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
]));
throw new DaemonConnectionException($exception);
}
}
}

View file

@ -118,7 +118,7 @@ class ServerCreationService
'uuidShort' => str_random(8),
'node_id' => array_get($data, 'node_id'),
'name' => array_get($data, 'name'),
'description' => array_get($data, 'description', ''),
'description' => array_get($data, 'description') ?? '',
'skip_scripts' => isset($data['skip_scripts']),
'suspended' => false,
'owner_id' => array_get($data, 'owner_id'),
@ -127,7 +127,7 @@ class ServerCreationService
'disk' => array_get($data, 'disk'),
'io' => array_get($data, 'io'),
'cpu' => array_get($data, 'cpu'),
'oom_disabled' => isset($data['oom_disabled']),
'oom_disabled' => false,
'allocation_id' => array_get($data, 'allocation_id'),
'nest_id' => array_get($data, 'nest_id'),
'egg_id' => array_get($data, 'egg_id'),
@ -163,8 +163,9 @@ class ServerCreationService
$structure = $this->configurationStructureService->handle($server);
// Create the server on the daemon & commit it to the database.
$node = $this->nodeRepository->find($server->node_id);
try {
$this->daemonServerRepository->setNode($server->node_id)->create($structure, [
$this->daemonServerRepository->setNode($node)->create($structure, [
'start_on_completion' => (bool) array_get($data, 'start_on_completion', false),
]);
$this->connection->commit();

View file

@ -106,11 +106,11 @@ class ServerDeletionService
public function handle($server)
{
if (! $server instanceof Server) {
$server = $this->repository->withColumns(['id', 'node_id', 'uuid'])->find($server);
$server = $this->repository->setColumns(['id', 'node_id', 'uuid'])->find($server);
}
try {
$this->daemonServerRepository->setNode($server->node_id)->setAccessServer($server->uuid)->delete();
$this->daemonServerRepository->setServer($server)->delete();
} catch (RequestException $exception) {
$response = $exception->getResponse();
@ -128,7 +128,7 @@ class ServerDeletionService
}
$this->connection->beginTransaction();
$this->databaseRepository->withColumns('id')->findWhere([['server_id', '=', $server->id]])->each(function ($item) {
$this->databaseRepository->setColumns('id')->findWhere([['server_id', '=', $server->id]])->each(function ($item) {
$this->databaseManagementService->delete($item->id);
});

View file

@ -91,7 +91,7 @@ class StartupModificationService
$results = $this->validatorService->handle(array_get($data, 'egg_id', $server->egg_id), array_get($data, 'environment', []));
$results->each(function ($result) use ($server) {
$this->serverVariableRepository->withoutFresh()->updateOrCreate([
$this->serverVariableRepository->withoutFreshModel()->updateOrCreate([
'server_id' => $server->id,
'variable_id' => $result->id,
], [
@ -112,7 +112,7 @@ class StartupModificationService
]);
try {
$this->daemonServerRepository->setNode($server->node_id)->setAccessServer($server->uuid)->update($daemonData);
$this->daemonServerRepository->setServer($server)->update($daemonData);
} catch (RequestException $exception) {
$this->connection->rollBack();
throw new DaemonConnectionException($exception);

View file

@ -91,12 +91,12 @@ class SuspensionService
}
$this->database->beginTransaction();
$this->repository->withoutFresh()->update($server->id, [
$this->repository->withoutFreshModel()->update($server->id, [
'suspended' => $action === 'suspend',
]);
try {
$this->daemonServerRepository->setNode($server->node_id)->setAccessServer($server->uuid)->$action();
$this->daemonServerRepository->setServer($server)->$action();
$this->database->commit();
return true;

View file

@ -68,7 +68,7 @@ class AuthenticateUsingPasswordService
}
try {
$user = $this->userRepository->withColumns(['id', 'root_admin', 'password'])->findFirstWhere([['username', '=', $username]]);
$user = $this->userRepository->setColumns(['id', 'root_admin', 'password'])->findFirstWhere([['username', '=', $username]]);
if (! password_verify($password, $user->password)) {
throw new AuthenticationException;
@ -77,7 +77,7 @@ class AuthenticateUsingPasswordService
throw new AuthenticationException;
}
$server = $this->repository->withColumns(['id', 'node_id', 'owner_id', 'uuid'])->getByUuid($server);
$server = $this->repository->setColumns(['id', 'node_id', 'owner_id', 'uuid'])->getByUuid($server);
if ($server->node_id !== $node || (! $user->root_admin && $server->owner_id !== $user->id)) {
throw new RecordNotFoundException;
}

View file

@ -56,6 +56,6 @@ class PermissionCreationService
}
}
$this->repository->withoutFresh()->insert($insertPermissions);
$this->repository->withoutFreshModel()->insert($insertPermissions);
}
}

View file

@ -96,7 +96,7 @@ class SubuserUpdateService
try {
$token = $this->keyProviderService->handle($subuser->getRelation('server'), $subuser->getRelation('user'), false);
$this->daemonRepository->setNode($subuser->getRelation('server')->node_id)->revokeAccessKey($token);
$this->daemonRepository->setServer($subuser->getRelation('server'))->revokeAccessKey($token);
} catch (RequestException $exception) {
$this->connection->rollBack();
throw new DaemonConnectionException($exception);

View file

@ -75,7 +75,7 @@ class ToggleTwoFactorService
throw new TwoFactorAuthenticationTokenInvalid;
}
$this->repository->withoutFresh()->update($user->id, [
$this->repository->withoutFreshModel()->update($user->id, [
'totp_authenticated_at' => Carbon::now(),
'use_totp' => (is_null($toggleState) ? ! $user->use_totp : $toggleState),
]);

View file

@ -72,7 +72,7 @@ class TwoFactorSetupService
$secret = $this->google2FA->generateSecretKey($this->config->get('pterodactyl.auth.2fa.bytes'));
$image = $this->google2FA->getQRCodeGoogleUrl($this->config->get('app.name'), $user->email, $secret);
$this->repository->withoutFresh()->update($user->id, [
$this->repository->withoutFreshModel()->update($user->id, [
'totp_secret' => $this->encrypter->encrypt($secret),
]);

View file

@ -63,7 +63,7 @@ class UserDeletionService
$user = $user->id;
}
$servers = $this->serverRepository->withColumns('id')->findCountWhere([['owner_id', '=', $user]]);
$servers = $this->serverRepository->setColumns('id')->findCountWhere([['owner_id', '=', $user]]);
if ($servers > 0) {
throw new DisplayException($this->translator->trans('admin/user.exceptions.user_has_servers'));
}

View file

@ -55,7 +55,6 @@ class UserUpdateService
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
*/
public function handle(User $user, array $data): Collection
{