mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 22:46:16 +00:00
2.x - php
This commit is contained in:
@ -5,16 +5,12 @@
|
||||
use App\Enums\ServiceStatus;
|
||||
use App\Models\Server;
|
||||
use App\Models\Service;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class InstallNewPHP
|
||||
{
|
||||
public function install(Server $server, array $input): void
|
||||
{
|
||||
$this->validate($server, $input);
|
||||
|
||||
$php = new Service([
|
||||
'server_id' => $server->id,
|
||||
'type' => 'php',
|
||||
@ -38,22 +34,14 @@ public function install(Server $server, array $input): void
|
||||
})->onConnection('ssh');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ValidationException
|
||||
*/
|
||||
private function validate(Server $server, array $input): void
|
||||
public static function rules(Server $server): array
|
||||
{
|
||||
Validator::make($input, [
|
||||
return [
|
||||
'version' => [
|
||||
'required',
|
||||
Rule::in(config('core.php_versions')),
|
||||
Rule::notIn($server->installedPHPVersions()),
|
||||
],
|
||||
])->validate();
|
||||
|
||||
if (in_array($input['version'], $server->installedPHPVersions())) {
|
||||
throw ValidationException::withMessages(
|
||||
['version' => __('This version is already installed')]
|
||||
);
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
namespace App\Actions\PHP;
|
||||
|
||||
use App\Exceptions\SSHCommandError;
|
||||
use App\Models\Server;
|
||||
use App\Models\Service;
|
||||
use App\SSH\Services\PHP\PHP;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
@ -13,54 +13,53 @@ class InstallPHPExtension
|
||||
{
|
||||
public function install(Server $server, array $input): Service
|
||||
{
|
||||
$this->validate($server, $input);
|
||||
|
||||
/** @var Service $service */
|
||||
$service = $server->php($input['version']);
|
||||
|
||||
if (in_array($input['extension'], $service->type_data['extensions'] ?? [])) {
|
||||
throw ValidationException::withMessages([
|
||||
'extension' => 'The extension is already installed.',
|
||||
]);
|
||||
}
|
||||
|
||||
$typeData = $service->type_data;
|
||||
$typeData['extensions'] = $typeData['extensions'] ?? [];
|
||||
$typeData['extensions'][] = $input['extension'];
|
||||
$service->type_data = $typeData;
|
||||
$service->save();
|
||||
|
||||
dispatch(function () use ($service, $input) {
|
||||
/** @var PHP $handler */
|
||||
$handler = $service->handler();
|
||||
$handler->installExtension($input['extension']);
|
||||
})->catch(function () use ($service, $input) {
|
||||
$service->refresh();
|
||||
$typeData = $service->type_data;
|
||||
$typeData['extensions'] = array_values(array_diff($typeData['extensions'], [$input['extension']]));
|
||||
$service->type_data = $typeData;
|
||||
$service->save();
|
||||
})->onConnection('ssh');
|
||||
dispatch(
|
||||
/**
|
||||
* @throws SSHCommandError
|
||||
*/
|
||||
function () use ($service, $input) {
|
||||
/** @var PHP $handler */
|
||||
$handler = $service->handler();
|
||||
$handler->installExtension($input['extension']);
|
||||
})->catch(function () use ($service, $input) {
|
||||
$service->refresh();
|
||||
$typeData = $service->type_data;
|
||||
$typeData['extensions'] = array_values(array_diff($typeData['extensions'], [$input['extension']]));
|
||||
$service->type_data = $typeData;
|
||||
$service->save();
|
||||
})->onConnection('ssh');
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ValidationException
|
||||
*/
|
||||
private function validate(Server $server, array $input): void
|
||||
public static function rules(Server $server): array
|
||||
{
|
||||
Validator::make($input, [
|
||||
return [
|
||||
'extension' => [
|
||||
'required',
|
||||
'in:'.implode(',', config('core.php_extensions')),
|
||||
Rule::in(config('core.php_extensions')),
|
||||
],
|
||||
'version' => [
|
||||
'required',
|
||||
Rule::in($server->installedPHPVersions()),
|
||||
Rule::exists('services', 'version')
|
||||
->where('server_id', $server->id)
|
||||
->where('type', 'php'),
|
||||
],
|
||||
])->validate();
|
||||
|
||||
/** @var Service $service */
|
||||
$service = $server->php($input['version']);
|
||||
|
||||
if (in_array($input['extension'], $service->type_data['extensions'])) {
|
||||
throw ValidationException::withMessages(
|
||||
['extension' => __('This extension already installed')]
|
||||
)->errorBag('installPHPExtension');
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@
|
||||
use App\Models\Server;
|
||||
use Illuminate\Filesystem\FilesystemAdapter;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
@ -19,8 +18,6 @@ class UpdatePHPIni
|
||||
*/
|
||||
public function update(Server $server, array $input): void
|
||||
{
|
||||
$this->validate($server, $input);
|
||||
|
||||
$service = $server->php($input['version']);
|
||||
|
||||
$tmpName = Str::random(10).strtotime('now');
|
||||
@ -51,24 +48,23 @@ private function deleteTempFile(string $name): void
|
||||
}
|
||||
}
|
||||
|
||||
public function validate(Server $server, array $input): void
|
||||
public static function rules(Server $server): array
|
||||
{
|
||||
Validator::make($input, [
|
||||
return [
|
||||
'ini' => [
|
||||
'required',
|
||||
'string',
|
||||
],
|
||||
'version' => 'required|string',
|
||||
'version' => [
|
||||
'required',
|
||||
Rule::exists('services', 'version')
|
||||
->where('server_id', $server->id)
|
||||
->where('type', 'php'),
|
||||
],
|
||||
'type' => [
|
||||
'required',
|
||||
Rule::in([PHPIniType::CLI, PHPIniType::FPM]),
|
||||
],
|
||||
])->validate();
|
||||
|
||||
if (! in_array($input['version'], $server->installedPHPVersions())) {
|
||||
throw ValidationException::withMessages(
|
||||
['version' => __('This version is not installed')]
|
||||
);
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user