diff --git a/app/Http/Livewire/Php/InstalledVersions.php b/app/Http/Livewire/Php/InstalledVersions.php index a792781..b9d1a8d 100644 --- a/app/Http/Livewire/Php/InstalledVersions.php +++ b/app/Http/Livewire/Php/InstalledVersions.php @@ -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 ?? [], ]); } } diff --git a/config/core.php b/config/core.php index 4ecfaa7..a57c999 100755 --- a/config/core.php +++ b/config/core.php @@ -292,11 +292,12 @@ */ 'php_extensions' => [ 'imagick', - 'geoip', 'exif', 'gmagick', 'gmp', 'intl', + 'sqlite3', + 'opcache', ], /* diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 04fec12..4d53459 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -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">
- Vito + + Deploy
diff --git a/resources/views/livewire/php/installed-versions.blade.php b/resources/views/livewire/php/installed-versions.blade.php index f5606a1..99ccf2f 100644 --- a/resources/views/livewire/php/installed-versions.blade.php +++ b/resources/views/livewire/php/installed-versions.blade.php @@ -28,9 +28,9 @@ - {{----}} - {{-- {{ __("Install Extension") }}--}} - {{----}} + + {{ __("Install Extension") }} + {{ __("Edit php.ini") }} @@ -52,6 +52,7 @@ @include('livewire.php.partials.uninstall-php') @include('livewire.php.partials.update-php-ini') + @include('livewire.php.partials.install-extension') @else
diff --git a/resources/views/livewire/php/partials/install-extension.blade.php b/resources/views/livewire/php/partials/install-extension.blade.php new file mode 100644 index 0000000..f223a48 --- /dev/null +++ b/resources/views/livewire/php/partials/install-extension.blade.php @@ -0,0 +1,36 @@ + +
+

+ {{ __('Install Extension') }} +

+ +
+ + + + @foreach(config('core.php_extensions') as $extension) + + @endforeach + + @error('name') + + @enderror +
+ +
+ @if (session('status') === 'started-installation') +

{{ __('Installation Started!') }}

+ @endif + + + {{ __('Cancel') }} + + + + {{ __('Install') }} + +
+
+
diff --git a/tests/Feature/Http/PHP.php b/tests/Feature/Http/PHP.php index 7a4eb3f..2b40109 100644 --- a/tests/Feature/Http/PHP.php +++ b/tests/Feature/Http/PHP.php @@ -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); + } }