misc_pterodactyl-panel/app/Services/Allocations/AllocationDeletionService.php

25 lines
699 B
PHP
Raw Permalink Normal View History

<?php
namespace Pterodactyl\Services\Allocations;
use Pterodactyl\Models\Allocation;
use Pterodactyl\Exceptions\Service\Allocation\ServerUsingAllocationException;
class AllocationDeletionService
{
/**
* Delete an allocation from the database only if it does not have a server
* that is actively attached to it.
*
* @throws \Pterodactyl\Exceptions\Service\Allocation\ServerUsingAllocationException
*/
public function handle(Allocation $allocation): int
{
2021-01-23 12:33:34 -08:00
if (!is_null($allocation->server_id)) {
throw new ServerUsingAllocationException(trans('exceptions.allocations.server_using'));
}
2022-10-23 02:02:58 -04:00
return $allocation->delete();
}
}