vito/app/Actions/PHP/UninstallPHP.php
2023-08-06 17:36:39 +02:00

42 lines
1.1 KiB
PHP
Executable File

<?php
namespace App\Actions\PHP;
use App\Models\Server;
use App\Models\Service;
use Illuminate\Validation\ValidationException;
class UninstallPHP
{
public function uninstall(Server $server, string $version): void
{
$this->validate($server, $version);
/** @var Service $php */
$php = $server->services()->where('type', 'php')->where('version', $version)->first();
$php->uninstall();
}
/**
* @throws ValidationException
*/
private function validate(Server $server, string $version): void
{
$php = $server->services()->where('type', 'php')->where('version', $version)->first();
if (! $php) {
throw ValidationException::withMessages(
['version' => __('This version has not been installed yet!')]
);
}
$hasSite = $server->sites()->where('php_version', $version)->first();
if ($hasSite) {
throw ValidationException::withMessages(
['version' => __('Cannot uninstall this version because some sites are using it!')]
);
}
}
}