mirror of
https://github.com/vitodeploy/vito.git
synced 2025-04-19 18:01:37 +00:00
enable php extension installation (#68)
This commit is contained in:
parent
f51d7900f0
commit
9d13cc0756
@ -3,11 +3,13 @@
|
||||
namespace App\Http\Livewire\Php;
|
||||
|
||||
use App\Actions\PHP\InstallNewPHP;
|
||||
use App\Actions\PHP\InstallPHPExtension;
|
||||
use App\Actions\PHP\UpdatePHPIni;
|
||||
use App\Models\Server;
|
||||
use App\Models\Service;
|
||||
use App\SSHCommands\PHP\GetPHPIniCommand;
|
||||
use App\Traits\RefreshComponentOnBroadcast;
|
||||
use Exception;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Livewire\Component;
|
||||
use Throwable;
|
||||
@ -24,6 +26,10 @@ class InstalledVersions extends Component
|
||||
|
||||
public string $ini = 'Loading php.ini';
|
||||
|
||||
public ?int $extensionId = null;
|
||||
|
||||
public string $extension = '';
|
||||
|
||||
public function install(string $version): void
|
||||
{
|
||||
app(InstallNewPHP::class)->install($this->server, [
|
||||
@ -35,6 +41,7 @@ public function install(string $version): void
|
||||
|
||||
public function restart(int $id): void
|
||||
{
|
||||
/** @var Service $service */
|
||||
$service = Service::query()->findOrFail($id);
|
||||
$service->restart();
|
||||
|
||||
@ -43,6 +50,7 @@ public function restart(int $id): void
|
||||
|
||||
public function uninstall(): void
|
||||
{
|
||||
/** @var Service $service */
|
||||
$service = Service::query()->findOrFail($this->uninstallId);
|
||||
$service->uninstall();
|
||||
|
||||
@ -56,6 +64,7 @@ public function loadIni(int $id): void
|
||||
$this->iniId = $id;
|
||||
$this->ini = 'Loading php.ini';
|
||||
|
||||
/** @var Service $service */
|
||||
$service = Service::query()->findOrFail($this->iniId);
|
||||
|
||||
try {
|
||||
@ -67,6 +76,7 @@ public function loadIni(int $id): void
|
||||
|
||||
public function saveIni(): void
|
||||
{
|
||||
/** @var Service $service */
|
||||
$service = Service::query()->findOrFail($this->iniId);
|
||||
|
||||
app(UpdatePHPIni::class)->update($service, $this->all()['ini']);
|
||||
@ -76,10 +86,32 @@ public function saveIni(): void
|
||||
session()->flash('status', 'ini-updated');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function installExtension(): void
|
||||
{
|
||||
/** @var Service $service */
|
||||
$service = Service::query()->findOrFail($this->extensionId);
|
||||
|
||||
app(InstallPHPExtension::class)->handle($service, [
|
||||
'name' => $this->extension,
|
||||
]);
|
||||
|
||||
session()->flash('status', 'started-installation');
|
||||
}
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
if ($this->extensionId) {
|
||||
/** @var Service $php */
|
||||
$php = Service::query()->findOrFail($this->extensionId);
|
||||
$installedExtensions = $php->type_data['extensions'] ?? [];
|
||||
}
|
||||
|
||||
return view('livewire.php.installed-versions', [
|
||||
'phps' => $this->server->services()->where('type', 'php')->get(),
|
||||
'installedExtensions' => $installedExtensions ?? [],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -292,11 +292,12 @@
|
||||
*/
|
||||
'php_extensions' => [
|
||||
'imagick',
|
||||
'geoip',
|
||||
'exif',
|
||||
'gmagick',
|
||||
'gmp',
|
||||
'intl',
|
||||
'sqlite3',
|
||||
'opcache',
|
||||
],
|
||||
|
||||
/*
|
||||
|
@ -38,7 +38,8 @@
|
||||
class="left-0 top-0 min-h-screen w-64 flex-none bg-gray-800 dark:bg-gray-800/50 p-3 dark:border-r-2 dark:border-gray-800">
|
||||
<div class="h-16 block">
|
||||
<div class="flex items-center justify-start text-3xl font-extrabold text-white">
|
||||
Vito
|
||||
<x-application-logo class="w-10 h-10 rounded-md"/>
|
||||
<span class="ml-1">Deploy</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -28,9 +28,9 @@
|
||||
</x-secondary-button>
|
||||
</x-slot>
|
||||
<x-slot name="content">
|
||||
{{--<x-dropdown-link class="cursor-pointer">--}}
|
||||
{{-- {{ __("Install Extension") }}--}}
|
||||
{{--</x-dropdown-link>--}}
|
||||
<x-dropdown-link class="cursor-pointer" x-on:click="$wire.extensionId = {{ $php->id }}; $dispatch('open-modal', 'install-extension')">
|
||||
{{ __("Install Extension") }}
|
||||
</x-dropdown-link>
|
||||
<x-dropdown-link class="cursor-pointer" x-on:click="$dispatch('open-modal', 'update-php-ini')" wire:click="loadIni({{ $php->id }})">
|
||||
{{ __("Edit php.ini") }}
|
||||
</x-dropdown-link>
|
||||
@ -52,6 +52,7 @@
|
||||
</div>
|
||||
@include('livewire.php.partials.uninstall-php')
|
||||
@include('livewire.php.partials.update-php-ini')
|
||||
@include('livewire.php.partials.install-extension')
|
||||
@else
|
||||
<x-simple-card>
|
||||
<div class="text-center">
|
||||
|
@ -0,0 +1,36 @@
|
||||
<x-modal name="install-extension">
|
||||
<form wire:submit.prevent="installExtension" class="p-6">
|
||||
<h2 class="text-lg font-medium text-gray-900 dark:text-gray-100">
|
||||
{{ __('Install Extension') }}
|
||||
</h2>
|
||||
|
||||
<div class="mt-6">
|
||||
<x-input-label for="extension" value="Name" />
|
||||
<x-select-input wire:model.defer="extension" name="extension" class="mt-1 w-full">
|
||||
<option value="" selected>{{ __("Select") }}</option>
|
||||
@foreach(config('core.php_extensions') as $extension)
|
||||
<option value="{{ $extension }}" @if(in_array($extension, $installedExtensions)) disabled @endif>
|
||||
{{ $extension }} @if(in_array($extension, $installedExtensions)) ({{ __("Installed") }}) @endif
|
||||
</option>
|
||||
@endforeach
|
||||
</x-select-input>
|
||||
@error('name')
|
||||
<x-input-error class="mt-2" :messages="$message" />
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div class="mt-6 flex items-center justify-end">
|
||||
@if (session('status') === 'started-installation')
|
||||
<p class="mr-2">{{ __('Installation Started!') }}</p>
|
||||
@endif
|
||||
|
||||
<x-secondary-button type="button" x-on:click="$dispatch('close')">
|
||||
{{ __('Cancel') }}
|
||||
</x-secondary-button>
|
||||
|
||||
<x-primary-button class="ml-3">
|
||||
{{ __('Install') }}
|
||||
</x-primary-button>
|
||||
</div>
|
||||
</form>
|
||||
</x-modal>
|
@ -7,6 +7,7 @@
|
||||
use App\Http\Livewire\Php\InstalledVersions;
|
||||
use App\Jobs\Installation\InstallPHP;
|
||||
use App\Jobs\Installation\UninstallPHP;
|
||||
use App\Jobs\PHP\InstallPHPExtension;
|
||||
use App\Jobs\PHP\SetDefaultCli;
|
||||
use App\Models\Service;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
@ -68,4 +69,42 @@ public function test_change_default_php_cli(): void
|
||||
|
||||
Bus::assertDispatched(SetDefaultCli::class);
|
||||
}
|
||||
|
||||
public function test_install_extension(): void
|
||||
{
|
||||
Bus::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(InstalledVersions::class, ['server' => $this->server])
|
||||
->set('extensionId', $this->server->php('8.2')?->id)
|
||||
->set('extension', 'gmp')
|
||||
->call('installExtension')
|
||||
->assertSuccessful();
|
||||
|
||||
Bus::assertDispatched(InstallPHPExtension::class);
|
||||
}
|
||||
|
||||
public function test_extension_already_installed(): void
|
||||
{
|
||||
Bus::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->server->php('8.2')->update([
|
||||
'type_data' => [
|
||||
'extensions' => [
|
||||
'gmp',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
Livewire::test(InstalledVersions::class, ['server' => $this->server])
|
||||
->set('extensionId', $this->server->php('8.2')?->id)
|
||||
->set('extension', 'gmp')
|
||||
->call('installExtension')
|
||||
->assertSuccessful();
|
||||
|
||||
Bus::assertNotDispatched(InstallPHPExtension::class);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user