From 9701c652976fec94b9f7dc519642d2a8ae1f7203 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 2 Oct 2023 18:02:32 +0200 Subject: [PATCH] fix: predefined content for files --- app/Http/Livewire/Project/Service/Show.php | 3 --- app/Models/Service.php | 7 +++++-- app/Models/ServiceApplication.php | 4 ++-- app/Models/ServiceDatabase.php | 4 ++-- bootstrap/helpers/services.php | 6 +++++- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/Http/Livewire/Project/Service/Show.php b/app/Http/Livewire/Project/Service/Show.php index ebeb24ebc..958fd595a 100644 --- a/app/Http/Livewire/Project/Service/Show.php +++ b/app/Http/Livewire/Project/Service/Show.php @@ -33,9 +33,6 @@ class Show extends Component $this->serviceDatabase = $this->service->databases()->whereName($this->parameters['service_name'])->first(); $this->serviceDatabase->getFilesFromServer(); } - if (is_null($service)) { - throw new \Exception("Service not found."); - } } catch(\Throwable $e) { return handleError($e, $this); } diff --git a/app/Models/Service.php b/app/Models/Service.php index a430dc2dd..c23ff075a 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -287,7 +287,10 @@ class Service extends BaseModel $isDirectory = (bool) data_get($volume, 'isDirectory', false); $foundConfig = $savedService->fileStorages()->whereMountPath($target)->first(); if ($foundConfig) { - $content = data_get($foundConfig, 'content'); + $contentNotNull = data_get($foundConfig, 'content'); + if ($contentNotNull) { + $content = $contentNotNull; + } $isDirectory = (bool) data_get($foundConfig, 'is_directory'); } } @@ -343,7 +346,7 @@ class Service extends BaseModel ] ); } - $savedService->getFilesFromServer(); + $savedService->getFilesFromServer(isInit: true); return $volume; }); data_set($service, 'volumes', $serviceVolumes->toArray()); diff --git a/app/Models/ServiceApplication.php b/app/Models/ServiceApplication.php index 58569b6bd..284453c42 100644 --- a/app/Models/ServiceApplication.php +++ b/app/Models/ServiceApplication.php @@ -36,8 +36,8 @@ class ServiceApplication extends BaseModel ); } - public function getFilesFromServer() + public function getFilesFromServer(bool $isInit = false) { - getFilesystemVolumesFromServer($this); + getFilesystemVolumesFromServer($this, $isInit); } } diff --git a/app/Models/ServiceDatabase.php b/app/Models/ServiceDatabase.php index a94bca40a..057db8e67 100644 --- a/app/Models/ServiceDatabase.php +++ b/app/Models/ServiceDatabase.php @@ -26,8 +26,8 @@ class ServiceDatabase extends BaseModel { return $this->morphMany(LocalFileVolume::class, 'resource'); } - public function getFilesFromServer() + public function getFilesFromServer(bool $isInit = false) { - getFilesystemVolumesFromServer($this); + getFilesystemVolumesFromServer($this, $isInit); } } diff --git a/bootstrap/helpers/services.php b/bootstrap/helpers/services.php index 7977d4d26..306ca172f 100644 --- a/bootstrap/helpers/services.php +++ b/bootstrap/helpers/services.php @@ -64,7 +64,7 @@ function serviceStatus(Service $service) } return 'exited'; } -function getFilesystemVolumesFromServer(ServiceApplication|ServiceDatabase $oneService) +function getFilesystemVolumesFromServer(ServiceApplication|ServiceDatabase $oneService, bool $isInit = false) { // TODO: make this async try { @@ -87,6 +87,10 @@ function getFilesystemVolumesFromServer(ServiceApplication|ServiceDatabase $oneS } $isFile = instant_remote_process(["test -f $fileLocation && echo OK || echo NOK"], $server); $isDir = instant_remote_process(["test -d $fileLocation && echo OK || echo NOK"], $server); + if ($isFile === 'NOK' &&!$fileVolume->is_directory && $isInit) { + $fileVolume->saveStorageOnServer($oneService); + continue; + } if ($isFile == 'OK' && !$fileVolume->is_directory) { $filesystemContent = instant_remote_process(["cat $fileLocation"], $server); if (base64_encode($filesystemContent) != base64_encode($content)) {