diff --git a/web/Modules/Docker/PostInstall.php b/web/Modules/Docker/PostInstall.php index ff215db..ba3519d 100644 --- a/web/Modules/Docker/PostInstall.php +++ b/web/Modules/Docker/PostInstall.php @@ -2,14 +2,16 @@ namespace Modules\Docker; -class PostInstall +use App\ModulePostInstall; + +class PostInstall extends ModulePostInstall { public function run() { $installDockerShellFile = base_path('Modules/Docker/shell-scripts/install-docker.sh'); shell_exec("chmod +x $installDockerShellFile"); - shell_exec("bash $installDockerShellFile"); + shell_exec("bash $installDockerShellFile >> $this->logFile &"); } } diff --git a/web/Modules/Microweber/PostInstall.php b/web/Modules/Microweber/PostInstall.php index cc98f99..98f43eb 100644 --- a/web/Modules/Microweber/PostInstall.php +++ b/web/Modules/Microweber/PostInstall.php @@ -2,9 +2,10 @@ namespace Modules\Microweber; +use App\ModulePostInstall; use Modules\Microweber\Filament\Clusters\Microweber\Pages\Version; -class PostInstall +class PostInstall extends ModulePostInstall { public function run() { diff --git a/web/app/Filament/Pages/Modules.php b/web/app/Filament/Pages/Modules.php index c44ea85..be8aa95 100644 --- a/web/app/Filament/Pages/Modules.php +++ b/web/app/Filament/Pages/Modules.php @@ -2,7 +2,9 @@ namespace App\Filament\Pages; +use App\Models\Module; use Filament\Pages\Page; +use Illuminate\Support\Str; class Modules extends Page { @@ -18,6 +20,8 @@ class Modules extends Page public $installLogPulling = false; public $installLog = ''; + public $installModule = ''; + public $installLogFilePath = ''; protected function getViewData(): array { @@ -61,13 +65,41 @@ class Modules extends Page public function getInstallLog() { - $this->installLog = time(); + $this->installLog = ''; + if (file_exists($this->installLogFilePath)) { + $this->installLog = file_get_contents($this->installLogFilePath); + $this->installLog = str_replace("\n", "
", $this->installLog); + } + + if (Str::contains($this->installLog, 'Installed')) { + $this->installLogPulling = false; + $newModule = new Module(); + $newModule->name = $module; + $newModule->namespace = 'Modules\\' . $module; + $newModule->installed = 1; + $newModule->save(); + } } public function openInstallModal($module) { - + $this->installModule = $module; $this->installLogPulling = true; + $this->installLogFilePath = storage_path('logs/' . $module . '-install.log'); + + file_put_contents($this->installLogFilePath, 'Installing ' . $module . '...'); + + $postInstall = app()->make('Modules\\' . $module . '\\PostInstall'); + if (method_exists($postInstall, 'run')) { + $postInstall->setLogFile($this->installLogFilePath); + $postInstall->run(); + } else { + $newModule = new Module(); + $newModule->name = $module; + $newModule->namespace = 'Modules\\' . $module; + $newModule->installed = 1; + $newModule->save(); + } $this->dispatch('open-modal', id: 'install-module-modal', props: ['module' => $module]); } diff --git a/web/app/Models/Module.php b/web/app/Models/Module.php index 621874a..5bdc65c 100644 --- a/web/app/Models/Module.php +++ b/web/app/Models/Module.php @@ -8,4 +8,5 @@ use Illuminate\Database\Eloquent\Model; class Module extends Model { use HasFactory; + } diff --git a/web/app/ModulePostInstall.php b/web/app/ModulePostInstall.php new file mode 100644 index 0000000..4c23a75 --- /dev/null +++ b/web/app/ModulePostInstall.php @@ -0,0 +1,11 @@ +logFile = $logFile; + } +}