vito/app/Actions/NodeJS/InstallNewNodeJsVersion.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

46 lines
1.2 KiB
PHP
Executable File

<?php
namespace App\Actions\NodeJS;
use App\Enums\NodeJS;
use App\Enums\ServiceStatus;
use App\Models\Server;
use App\Models\Service;
use Illuminate\Validation\Rule;
class InstallNewNodeJsVersion
{
public function install(Server $server, array $input): void
{
$nodejs = new Service([
'server_id' => $server->id,
'type' => 'nodejs',
'type_data' => [],
'name' => 'nodejs',
'version' => $input['version'],
'status' => ServiceStatus::INSTALLING,
'is_default' => false,
]);
$nodejs->save();
dispatch(function () use ($nodejs) {
$nodejs->handler()->install();
$nodejs->status = ServiceStatus::READY;
$nodejs->save();
})->catch(function () use ($nodejs) {
$nodejs->delete();
})->onConnection('ssh');
}
public static function rules(Server $server): array
{
return [
'version' => [
'required',
Rule::in(config('core.nodejs_versions')),
Rule::notIn(array_merge($server->installedNodejsVersions(), [NodeJS::NONE])),
],
];
}
}