From e0a72e5a11e01d5d465b79136ff16e34bf8fffce Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 10 Feb 2023 12:05:34 +0100 Subject: [PATCH] wip #5721 @2 --- .docker/images/php/Dockerfile | 1 + .../Commands/FluidbookDocumentProcess.php | 3 +- app/Fluidbook/Farm.php | 15 ++++++---- ...ookExternalInstallServerCrudController.php | 29 +++++++++++++++++++ .../CompositionOperation.php | 2 +- app/Jobs/FluidbookDocumentFileProcess.php | 26 +++++++++++++---- app/Jobs/FluidbookDocumentUpload.php | 14 +++++---- .../fields/fluidbook_composition.blade.php | 8 +++-- 8 files changed, 78 insertions(+), 20 deletions(-) create mode 100644 app/Http/Controllers/Admin/FluidbookExternalInstallServerCrudController.php diff --git a/.docker/images/php/Dockerfile b/.docker/images/php/Dockerfile index 6021a32a8..77773a127 100644 --- a/.docker/images/php/Dockerfile +++ b/.docker/images/php/Dockerfile @@ -42,6 +42,7 @@ RUN apt-get update && apt-get -y --no-install-recommends install \ php8.1-intl \ php8.1-memcached \ php8.1-mysql \ + php8.1-sqlite \ php8.1-redis \ php8.1-soap \ php8.1-ssh2 \ diff --git a/app/Console/Commands/FluidbookDocumentProcess.php b/app/Console/Commands/FluidbookDocumentProcess.php index d4a5687bb..705322e26 100644 --- a/app/Console/Commands/FluidbookDocumentProcess.php +++ b/app/Console/Commands/FluidbookDocumentProcess.php @@ -25,6 +25,7 @@ class FluidbookDocumentProcess extends CubistCommand $doc = FluidbookDocument::find($this->argument('id')); $doc->clearAllFiles(); $user = User::withoutGlobalScope('ownerclause')->where('id', $doc->owner)->first(); - FluidbookDocumentUpload::dispatchSync(Str::random(), $doc, $user); + $job = new FluidbookDocumentUpload(Str::random(), $doc, $user); + $job->handle(true); } } diff --git a/app/Fluidbook/Farm.php b/app/Fluidbook/Farm.php index d93a238eb..9bb1fddb6 100644 --- a/app/Fluidbook/Farm.php +++ b/app/Fluidbook/Farm.php @@ -11,7 +11,7 @@ class Farm { protected static $_farmServers = [ ['name' => 'alphaville', 'host' => 'fluidbook-processfarm', 'port' => 9000, 'weight' => 24], - ['name' => 'brazil', 'host' => 'brazil.cubedesigners.com', 'weight' => 6], + //['name' => 'brazil', 'host' => 'brazil.cubedesigners.com', 'weight' => 6], ['name' => 'clockwork', 'host' => 'clockwork.cubedesigners.com', 'weight' => 2], ['name' => 'dracula', 'host' => 'dracula.cubedesigners.com', 'weight' => 3], ['name' => 'elephantman', 'host' => 'elephantman.cubedesigners.com', 'weight' => 1], @@ -20,7 +20,7 @@ class Farm ['name' => 'her', 'host' => 'her2.cubedesigners.com', 'weight' => 4], ['name' => 'isleofdogs', 'host' => 'paris.cubedesigners.com', 'port' => 9458, 'weight' => 2], ['name' => 'jumanji', 'host' => 'paris.cubedesigners.com', 'port' => 9459, 'weight' => 2], - ['name' => 'kingkong', 'host' => 'kingkong.cubedesigners.com', 'weight' => 2], + //['name' => 'kingkong', 'host' => 'kingkong.cubedesigners.com', 'weight' => 2], ]; protected static function _pingCache() @@ -79,11 +79,14 @@ class Farm $start = microtime(true); $farmer = self::pickOneServer(); + $path = str_replace('/protected/fluidbookpublication/docs/', '/fluidbook/docs/', $path); + $params = ['page' => $page, 'format' => $format, 'resolution' => $resolution, 'withText' => $withText, 'withGraphics' => $withGraphics, 'version' => $version, 'force' => $force, 'out' => $path, 'resolutionRatio' => $resolutionRatio, 'mobileRatio' => $mobileFirstRatio]; $output = self::sendRequest($farmer, 'process.php', $params); - if (preg_match('|/data1/extranet/www/[^\s]+|', $output, $matches)) { - $o = $matches[0]; + + if (preg_match('|^/application/fluidbook/docs/[^\s]+$|', $output, $matches)) { + $o = str_replace('/fluidbook/docs/', '/protected/fluidbookpublication/docs/', $matches[0]); } else { $o = $output; } @@ -96,11 +99,11 @@ class Farm } $time = round(microtime(true) - $start, 4); - $log = '[' . $farmer['name'] . ']' . "\t" . date('Y-m-d H:i:s') . "\t" . $time . "\t$page|$format|$resolution|$withText|$withGraphics|$version\t$res\t" . $output . "\n"; + $log = '[' . $farmer['name'] . ']' . "\t" . date('Y-m-d H:i:s') . "\t" . $time . "\t$page|$format|$resolution|$withText|$withGraphics|$version\t($res)\t>>" . $output . "\n"; error_log($log); - return str_replace('/fluidbook/docs/', '/protected/fluidbookpublication/docs/', $res); + return $res; } public static function ping($echo = true, $force = false) diff --git a/app/Http/Controllers/Admin/FluidbookExternalInstallServerCrudController.php b/app/Http/Controllers/Admin/FluidbookExternalInstallServerCrudController.php new file mode 100644 index 000000000..36b55a502 --- /dev/null +++ b/app/Http/Controllers/Admin/FluidbookExternalInstallServerCrudController.php @@ -0,0 +1,29 @@ +owner = backpack_user()->id; $document->save(); move_uploaded_file($file->getPathname(), Files::mkdir($document->path()) . 'original.pdf'); - FluidbookDocumentUpload::updateProgression($uploadID, __('Mise en file d\'attente du traitement du document'), 1.2); + FluidbookDocumentUpload::updateProgression($uploadID, $document->id, __('Mise en file d\'attente du traitement du document'), 1.2); FluidbookDocumentUpload::dispatch($uploadID, $document, backpack_user(), request('fluidbook_id', null)); return response()->json(['uploadID' => $uploadID, 'document' => $document->id]); } diff --git a/app/Jobs/FluidbookDocumentFileProcess.php b/app/Jobs/FluidbookDocumentFileProcess.php index 970032b84..cff10bacb 100644 --- a/app/Jobs/FluidbookDocumentFileProcess.php +++ b/app/Jobs/FluidbookDocumentFileProcess.php @@ -14,9 +14,12 @@ class FluidbookDocumentFileProcess extends Base protected $withText; protected $withGraphics; protected $version; - protected $force; + protected $forceCheck; + protected $forceProcess; - public function __construct($document, $page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $force = false) + protected $finish = false; + + public function __construct($document, $page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $forceCheck = false, $forceProcess = false) { $this->onQueue('fluidbookprocess'); $this->document = $document; @@ -26,12 +29,15 @@ class FluidbookDocumentFileProcess extends Base $this->withGraphics = $withGraphics; $this->withText = $withText; $this->version = $version; - $this->force = $force; + $this->forceCheck = $forceCheck || $forceProcess; + $this->forceProcess = $forceProcess; } public function handle() { - $this->document->getFile($this->page, $this->format, $this->resolution, $this->withText, $this->withGraphics, $this->version, $this->force); + $this->finish = false; + echo $this->document->getFile($this->page, $this->format, $this->resolution, $this->withText, $this->withGraphics, $this->version, $this->forceCheck, $this->forceProcess) . "\n"; + $this->finish = true; } /** @@ -39,6 +45,16 @@ class FluidbookDocumentFileProcess extends Base */ public function isDone() { - return $this->document->hasFile($this->page, $this->format, $this->resolution, $this->withText, $this->withGraphics, $this->version); + return $this->finish || $this->isOK(); + } + + public function isOK() + { + return $this->document->hasFile($this->page, $this->format, $this->resolution, $this->withText, $this->withGraphics, $this->version, $this->forceCheck); + } + + public function isError() + { + return $this->finish && !$this->isOK(); } } diff --git a/app/Jobs/FluidbookDocumentUpload.php b/app/Jobs/FluidbookDocumentUpload.php index c5e007bbd..09a028262 100644 --- a/app/Jobs/FluidbookDocumentUpload.php +++ b/app/Jobs/FluidbookDocumentUpload.php @@ -34,15 +34,19 @@ class FluidbookDocumentUpload extends Base $this->setUser($user); } - public function handle() + public function handle($sync = false) { - FluidbookDocumentUpload::updateProgression($this->uploadID, __('Début du traitement du document'), 1.25); - $this->document->processUpload($this->uploadID, false); + try { + FluidbookDocumentUpload::updateProgression($this->uploadID, $this->document->id, __('Début du traitement du document'), 1.25); + $this->document->processUpload($this->uploadID, $sync); + } catch (\Exception $e) { + error_log($e); + } } - public static function updateProgression($id, $message, $progress) + public static function updateProgression($id, $document_id, $message, $progress) { - Cache::put('FluidbookDocumentUpload_' . $id, ['message' => $message, 'progress' => $progress]); + Cache::put('FluidbookDocumentUpload_' . $id, ['message' => $message, 'document' => $document_id, 'progress' => $progress]); } public static function getProgression($id) diff --git a/resources/views/fields/fluidbook_composition.blade.php b/resources/views/fields/fluidbook_composition.blade.php index f4385bb51..d1e18df57 100644 --- a/resources/views/fields/fluidbook_composition.blade.php +++ b/resources/views/fields/fluidbook_composition.blade.php @@ -165,7 +165,11 @@ $.ajax({ url: '{{backpack_url($entry->getOption('name').'/uploadProgress')}}' + '/' + uploadID, success: function (data) { - showProgressBar(data.message, parseFloat(data.progress), uploadID); + let message = data.message; + if (data.document) { + message += '
Document #' + data.document + ''; + } + showProgressBar(message, parseFloat(data.progress), uploadID); } }); } @@ -175,7 +179,7 @@ $('body').append('
'); } if (message !== '' && progress > 0) { - $("#compositionProgress span").text(message); + $("#compositionProgress span").html(message); if ($("#compositionProgress progress").attr('data-progress') == progress) { return; } -- 2.39.5