forked from Alex/Pterodactyl-Panel
Code cleanup to use new findCountWhere function
This commit is contained in:
parent
c1a078bdcf
commit
4da7922de6
@ -141,13 +141,11 @@ class DeletionService
|
||||
}
|
||||
|
||||
$this->database->beginTransaction();
|
||||
|
||||
$this->databaseRepository->withColumns('id')->findWhere([['server_id', '=', $server->id]])->each(function ($item) {
|
||||
$this->databaseManagementService->delete($item->id);
|
||||
});
|
||||
|
||||
$this->repository->delete($server->id);
|
||||
|
||||
$this->database->commit();
|
||||
}
|
||||
}
|
||||
|
@ -78,8 +78,8 @@ class DeletionService
|
||||
$user = $user->id;
|
||||
}
|
||||
|
||||
$servers = $this->serverRepository->findWhere([['owner_id', '=', $user]]);
|
||||
if (count($servers) > 0) {
|
||||
$servers = $this->serverRepository->withColumns('id')->findCountWhere([['owner_id', '=', $user]]);
|
||||
if ($servers > 0) {
|
||||
throw new DisplayException($this->translator->trans('admin/user.exceptions.user_has_servers'));
|
||||
}
|
||||
|
||||
|
@ -68,8 +68,6 @@ class UpdateService
|
||||
$data['password'] = $this->hasher->make($data['password']);
|
||||
}
|
||||
|
||||
$user = $this->repository->update($id, $data);
|
||||
|
||||
return $user;
|
||||
return $this->repository->update($id, $data);
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +81,8 @@ class DeletionServiceTest extends TestCase
|
||||
*/
|
||||
public function testUserIsDeletedIfNoServersAreAttachedToAccount()
|
||||
{
|
||||
$this->serverRepository->shouldReceive('findWhere')->with([['owner_id', '=', $this->user->id]])->once()->andReturn([]);
|
||||
$this->serverRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findCountWhere')->with([['owner_id', '=', $this->user->id]])->once()->andReturn(0);
|
||||
$this->repository->shouldReceive('delete')->with($this->user->id)->once()->andReturn(true);
|
||||
|
||||
$this->assertTrue(
|
||||
@ -97,7 +98,8 @@ class DeletionServiceTest extends TestCase
|
||||
*/
|
||||
public function testExceptionIsThrownIfServersAreAttachedToAccount()
|
||||
{
|
||||
$this->serverRepository->shouldReceive('findWhere')->with([['owner_id', '=', $this->user->id]])->once()->andReturn(['item']);
|
||||
$this->serverRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findCountWhere')->with([['owner_id', '=', $this->user->id]])->once()->andReturn(1);
|
||||
$this->translator->shouldReceive('trans')->with('admin/user.exceptions.user_has_servers')->once()->andReturnNull();
|
||||
|
||||
$this->service->handle($this->user->id);
|
||||
@ -108,7 +110,8 @@ class DeletionServiceTest extends TestCase
|
||||
*/
|
||||
public function testModelCanBePassedInPlaceOfUserId()
|
||||
{
|
||||
$this->serverRepository->shouldReceive('findWhere')->with([['owner_id', '=', $this->user->id]])->once()->andReturn([]);
|
||||
$this->serverRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findCountWhere')->with([['owner_id', '=', $this->user->id]])->once()->andReturn(0);
|
||||
$this->repository->shouldReceive('delete')->with($this->user->id)->once()->andReturn(true);
|
||||
|
||||
$this->assertTrue(
|
||||
|
Loading…
Reference in New Issue
Block a user