vito/app/Actions/NodeJS/ChangeDefaultCli.php
Mark Topper 924920e6e8
Feature/nodejs (#397)
* 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>
2024-12-24 17:49:27 +01:00

33 lines
999 B
PHP

<?php
namespace App\Actions\NodeJS;
use App\Enums\ServiceStatus;
use App\Models\Server;
use App\SSH\Services\NodeJS\NodeJS;
use Illuminate\Validation\ValidationException;
class ChangeDefaultCli
{
public function change(Server $server, array $input): void
{
$this->validate($server, $input);
$service = $server->nodejs($input['version']);
/** @var NodeJS $handler */
$handler = $service->handler();
$handler->setDefaultCli();
$server->defaultService('nodejs')->update(['is_default' => 0]);
$service->update(['is_default' => 1]);
$service->update(['status' => ServiceStatus::READY]);
}
public function validate(Server $server, array $input): void
{
if (! isset($input['version']) || ! in_array($input['version'], $server->installedNodejsVersions())) {
throw ValidationException::withMessages(
['version' => __('This version is not installed')]
);
}
}
}