mirror of
https://github.com/vitodeploy/vito.git
synced 2025-04-20 10:21:37 +00:00
* Add node support using nvm * Add icon * Rename to NodeJS * Rename to NodeJS * update php and node logo * only services which have units can be started,restarted,stopped,disabled and enabled * add tests --------- Co-authored-by: Saeed Vaziry <mr.saeedvaziry@gmail.com> Co-authored-by: Saeed Vaziry <61919774+saeedvaziry@users.noreply.github.com>
54 lines
1.5 KiB
PHP
Executable File
54 lines
1.5 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Actions\NodeJS;
|
|
|
|
use App\Enums\ServiceStatus;
|
|
use App\Models\Server;
|
|
use App\Models\Service;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
class UninstallNodeJS
|
|
{
|
|
public function uninstall(Server $server, array $input): void
|
|
{
|
|
$this->validate($server, $input);
|
|
|
|
/** @var Service $nodejs */
|
|
$nodejs = $server->nodejs($input['version']);
|
|
$nodejs->status = ServiceStatus::UNINSTALLING;
|
|
$nodejs->save();
|
|
|
|
dispatch(function () use ($nodejs) {
|
|
$nodejs->handler()->uninstall();
|
|
$nodejs->delete();
|
|
})->catch(function () use ($nodejs) {
|
|
$nodejs->status = ServiceStatus::FAILED;
|
|
$nodejs->save();
|
|
})->onConnection('ssh');
|
|
}
|
|
|
|
/**
|
|
* @throws ValidationException
|
|
*/
|
|
private function validate(Server $server, array $input): void
|
|
{
|
|
Validator::make($input, [
|
|
'version' => 'required|string',
|
|
])->validate();
|
|
|
|
if (! in_array($input['version'], $server->installedNodejsVersions())) {
|
|
throw ValidationException::withMessages(
|
|
['version' => __('This version is not installed')]
|
|
);
|
|
}
|
|
|
|
$hasSite = $server->sites()->where('nodejs_version', $input['version'])->first();
|
|
if ($hasSite) {
|
|
throw ValidationException::withMessages(
|
|
['version' => __('Cannot uninstall this version because some sites are using it!')]
|
|
);
|
|
}
|
|
}
|
|
}
|