2017-08-04 19:11:41 -05:00
|
|
|
<?php
|
2022-01-15 18:10:37 +02:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
declare(strict_types=1);
|
2017-08-04 19:11:41 -05:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
namespace Pterodactyl\Actions\Users;
|
|
|
|
|
|
|
|
|
|
use Pterodactyl\Contracts\Users\DeletesUsers;
|
2017-08-05 17:26:30 -05:00
|
|
|
use Pterodactyl\Exceptions\DisplayException;
|
2026-10-05 18:10:18 -04:00
|
|
|
use Pterodactyl\Models\User;
|
2017-08-04 19:11:41 -05:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
final class DeleteUser implements DeletesUsers
|
2017-08-04 19:11:41 -05:00
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Delete a user from the panel only if they have no servers attached to their account.
|
|
|
|
|
*
|
2024-10-21 19:18:20 -06:00
|
|
|
* @throws DisplayException
|
2017-08-04 19:11:41 -05:00
|
|
|
*/
|
2026-10-05 18:10:18 -04:00
|
|
|
public function delete(User $user): ?bool
|
2017-08-04 19:11:41 -05:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
if ($user->servers()->exists()) {
|
2026-02-14 10:51:26 -08:00
|
|
|
throw new DisplayException(trans('admin/user.exceptions.user_has_servers'));
|
2017-08-04 19:11:41 -05:00
|
|
|
}
|
|
|
|
|
|
2026-02-14 10:51:26 -08:00
|
|
|
return $user->delete();
|
2017-08-04 19:11:41 -05:00
|
|
|
}
|
|
|
|
|
}
|