This commit is contained in:
Saeed Vaziry
2024-03-24 09:56:34 +01:00
committed by GitHub
parent 884f18db63
commit 4d051330d6
1055 changed files with 14493 additions and 20278 deletions

View File

@ -2,36 +2,48 @@
namespace App\Actions\PHP;
use App\Enums\ServiceStatus;
use App\Models\Server;
use App\Models\Service;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
class UninstallPHP
{
public function uninstall(Server $server, string $version): void
public function uninstall(Server $server, array $input): void
{
$this->validate($server, $version);
$this->validate($server, $input);
/** @var Service $php */
$php = $server->services()->where('type', 'php')->where('version', $version)->first();
$php = $server->php($input['version']);
$php->status = ServiceStatus::UNINSTALLING;
$php->save();
$php->uninstall();
dispatch(function () use ($php) {
$php->handler()->uninstall();
$php->delete();
})->catch(function () use ($php) {
$php->status = ServiceStatus::FAILED;
$php->save();
})->onConnection('ssh');
}
/**
* @throws ValidationException
*/
private function validate(Server $server, string $version): void
private function validate(Server $server, array $input): void
{
$php = $server->services()->where('type', 'php')->where('version', $version)->first();
Validator::make($input, [
'version' => 'required|string',
])->validate();
if (! $php) {
if (! in_array($input['version'], $server->installedPHPVersions())) {
throw ValidationException::withMessages(
['version' => __('This version has not been installed yet!')]
['version' => __('This version is not installed')]
);
}
$hasSite = $server->sites()->where('php_version', $version)->first();
$hasSite = $server->sites()->where('php_version', $input['version'])->first();
if ($hasSite) {
throw ValidationException::withMessages(
['version' => __('Cannot uninstall this version because some sites are using it!')]