From 50ff24efaabe6c018aec625a16b845054c118928 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 5 Jun 2023 14:20:27 +0200 Subject: [PATCH] wip #5991 @0.25 --- app/Fluidbook/Compiler/Compiler.php | 5 ++ app/Fluidbook/Farm.php | 16 ++++- .../Operations/Tools/PDF2SVGOperation.php | 2 +- app/Jobs/FluidbookDocumentFileProcess.php | 7 +- app/Models/FluidbookDocument.php | 44 ++++++------ app/Models/FluidbookPublication.php | 14 +--- composer.lock | 68 +++++++++++-------- 7 files changed, 87 insertions(+), 69 deletions(-) diff --git a/app/Fluidbook/Compiler/Compiler.php b/app/Fluidbook/Compiler/Compiler.php index 95265d739..36467d7f5 100644 --- a/app/Fluidbook/Compiler/Compiler.php +++ b/app/Fluidbook/Compiler/Compiler.php @@ -3111,4 +3111,9 @@ class Compiler extends Base implements CompilerInterface { return (int)$this->config->pages; } + + public function getQuality(): int + { + return (int)$this->config->JPEGQuality; + } } diff --git a/app/Fluidbook/Farm.php b/app/Fluidbook/Farm.php index 414f194df..0d21a49b3 100644 --- a/app/Fluidbook/Farm.php +++ b/app/Fluidbook/Farm.php @@ -7,6 +7,7 @@ use hollodotme\FastCGI\Client; use hollodotme\FastCGI\Requests\PostRequest; use hollodotme\FastCGI\SocketConnections\NetworkSocket; use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\Log; class Farm { @@ -91,7 +92,7 @@ class Farm return trim($response->getBody()); } - public static function getFile($page, $format, $resolution, $withText, $withGraphics, $version, $resolutionRatio, $mobileFirstRatio, $path, $force = false) + public static function getFile($page, $format, $resolution, $quality, $withText, $withGraphics, $version, $resolutionRatio, $mobileFirstRatio, $path, $force = false) { $params = ['toolbox' => 1, 'page' => $page, @@ -100,6 +101,7 @@ class Farm 'withText' => $withText, 'withGraphics' => $withGraphics, 'version' => $version, + 'quality' => $quality, 'force' => $force, 'out' => $path, 'resolutionRatio' => $resolutionRatio, @@ -108,7 +110,7 @@ class Farm } - public static function getFileFromPDF($pdf, $page, $format, $resolution, $withText = true, $withGraphics = true, $version = 'html', $out = null, $force = false) + public static function getFileFromPDF($pdf, $page, $format, $resolution, $quality, $withText = true, $withGraphics = true, $version = 'html', $out = null, $force = false) { if (null === $out) { $hash = Files::hashFileAttributes($pdf); @@ -119,6 +121,7 @@ class Farm 'page' => $page, 'format' => $format, 'resolution' => $resolution, + 'quality' => $quality, 'withText' => $withText, 'withGraphics' => $withGraphics, 'version' => $version, @@ -145,7 +148,14 @@ class Farm $start = microtime(true); $farmer = self::pickOneServer(); - $output = trim(self::sendRequest($farmer, 'process.php', $params)); + try { + $output = self::sendRequest($farmer, 'process.php', $params); + } catch (\Exception $e) { + Log::error('Farm server error ' . $farmer['name'] . ' : ' . json_encode($params) . ' : ' . $e->getMessage()); + exit; + } + + $output = trim($output); if (file_exists($output)) { $res = $output; diff --git a/app/Http/Controllers/Admin/Operations/Tools/PDF2SVGOperation.php b/app/Http/Controllers/Admin/Operations/Tools/PDF2SVGOperation.php index 423457e95..c23b54d0c 100644 --- a/app/Http/Controllers/Admin/Operations/Tools/PDF2SVGOperation.php +++ b/app/Http/Controllers/Admin/Operations/Tools/PDF2SVGOperation.php @@ -30,7 +30,7 @@ trait PDF2SVGOperation public function pdf2svg() { - $form = new Form(backpack_url('tools/convertpdf')); + $form = new Form(backpack_url('opentools/convertpdf')); $form->setEnctype('multipart/form-data'); $form->setTitle(__('Convertir un fichier pdf en images')); $form->setSubmitLabel(__('Convertir')); diff --git a/app/Jobs/FluidbookDocumentFileProcess.php b/app/Jobs/FluidbookDocumentFileProcess.php index cff10bacb..8f564bfc1 100644 --- a/app/Jobs/FluidbookDocumentFileProcess.php +++ b/app/Jobs/FluidbookDocumentFileProcess.php @@ -19,13 +19,14 @@ class FluidbookDocumentFileProcess extends Base protected $finish = false; - public function __construct($document, $page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $forceCheck = false, $forceProcess = false) + public function __construct($document, $page, $format = 'jpg', $resolution = 150,$quality=85, $withText = true, $withGraphics = true, $version = 'html', $forceCheck = false, $forceProcess = false) { $this->onQueue('fluidbookprocess'); $this->document = $document; $this->page = $page; $this->format = $format; $this->resolution = $resolution; + $this->quality=$quality; $this->withGraphics = $withGraphics; $this->withText = $withText; $this->version = $version; @@ -36,7 +37,7 @@ class FluidbookDocumentFileProcess extends Base public function handle() { $this->finish = false; - echo $this->document->getFile($this->page, $this->format, $this->resolution, $this->withText, $this->withGraphics, $this->version, $this->forceCheck, $this->forceProcess) . "\n"; + echo $this->document->getFile($this->page, $this->format, $this->resolution,$this->quality, $this->withText, $this->withGraphics, $this->version, $this->forceCheck, $this->forceProcess) . "\n"; $this->finish = true; } @@ -50,7 +51,7 @@ class FluidbookDocumentFileProcess extends Base public function isOK() { - return $this->document->hasFile($this->page, $this->format, $this->resolution, $this->withText, $this->withGraphics, $this->version, $this->forceCheck); + return $this->document->hasFile($this->page, $this->format, $this->resolution,$this->quality, $this->withText, $this->withGraphics, $this->version, $this->forceCheck); } public function isError() diff --git a/app/Models/FluidbookDocument.php b/app/Models/FluidbookDocument.php index cf0bd1462..daba021d7 100644 --- a/app/Models/FluidbookDocument.php +++ b/app/Models/FluidbookDocument.php @@ -209,14 +209,14 @@ class FluidbookDocument extends ToolboxModel return $res; } - public function hasFile($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $forceCheck = false) + public function hasFile($page, $format = 'jpg', $resolution = 150, $quality = 85, $withText = true, $withGraphics = true, $version = 'html', $forceCheck = false) { - $this->_normalize($format, $resolution, $withText, $withGraphics, $version); - $cacheKey = $this->fileCacheKey($page, $format, $resolution, $withText, $withGraphics, $version); + $this->_normalize($format, $resolution, $quality, $withText, $withGraphics, $version); + $cacheKey = $this->fileCacheKey($page, $format, $resolution, $quality, $withText, $withGraphics, $version); if (!$forceCheck && Cache::has($cacheKey)) { return true; } else { - $path = $this->_getPath($page, $format, $resolution, $withText, $withGraphics, $version); + $path = $this->_getPath($page, $format, $resolution, $quality, $withText, $withGraphics, $version); $minsize = $format === 'svg' ? 100 : 1; if (!file_exists($path)) { @@ -243,7 +243,7 @@ class FluidbookDocument extends ToolboxModel } } - protected function _normalize(&$format, &$resolution, &$withText, &$withGraphics, &$version) + protected function _normalize(&$format, &$resolution, &$quality, &$withText, &$withGraphics, &$version) { if ($format === 'jpeg') { $format = 'jpg'; @@ -261,14 +261,14 @@ class FluidbookDocument extends ToolboxModel } } - public function _getPath($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html') + public function _getPath($page, $format = 'jpg', $resolution = 150, $quality = 85, $withText = true, $withGraphics = true, $version = 'html') { - $cacheKey = $this->fileCacheKey($page, $format, $resolution, $withText, $withGraphics, $version); + $cacheKey = $this->fileCacheKey($page, $format, $resolution, $quality, $withText, $withGraphics, $version); if (Cache::has($cacheKey)) { return Cache::get($cacheKey); } - $this->_normalize($format, $resolution, $withText, $withGraphics, $version); + $this->_normalize($format, $resolution, $quality, $withText, $withGraphics, $version); $dir = $this->path($version) . '/'; @@ -293,15 +293,15 @@ class FluidbookDocument extends ToolboxModel return $file; } - protected function fileCacheKey($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html') + protected function fileCacheKey($page, $format = 'jpg', $resolution = 150, $quality = 85, $withText = true, $withGraphics = true, $version = 'html') { - $this->_normalize($format, $resolution, $withText, $withGraphics, $version); + $this->_normalize($format, $resolution, $quality, $withText, $withGraphics, $version); return 'FluidbookDocument_' . $this->id . '_' . $page . '_' . $format . '_' . $resolution . '_' . ($withText ? '1' : '0') . '_' . ($withGraphics ? '1' : '0') . '_' . $version; } - public function getFile($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $forceCheck = false, $forceProcess = false) + public function getFile($page, $format = 'jpg', $resolution = 150, $quality = 85, $withText = true, $withGraphics = true, $version = 'html', $forceCheck = false, $forceProcess = false) { - $this->_normalize($format, $resolution, $withText, $withGraphics, $version); + $this->_normalize($format, $resolution, $quality, $withText, $withGraphics, $version); if ($forceProcess) { $this->removeFile($page, $format, $resolution, $withText, $withGraphics, $version); } @@ -311,32 +311,32 @@ class FluidbookDocument extends ToolboxModel if ($forceCheck) { Cache::forget($cacheKey); } - $res = Cache::tags('fluidbook_document_' . $this->id)->rememberForever($cacheKey, function () use ($doc, $page, $format, $resolution, $withText, $withGraphics, $version) { - return $doc->_getFile($page, $format, $resolution, $withText, $withGraphics, $version); + $res = Cache::tags('fluidbook_document_' . $this->id)->rememberForever($cacheKey, function () use ($doc, $page, $format, $resolution, $quality, $withText, $withGraphics, $version) { + return $doc->_getFile($page, $format, $resolution, $quality, $withText, $withGraphics, $version); }); if (!$res && !$forceProcess) { - return $this->getFile($page, $format, $resolution, $withText, $withGraphics, $version, true, true); + return $this->getFile($page, $format, $resolution, $quality, $withText, $withGraphics, $version, true, true); } return $res; } - public function removeFile($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html') + public function removeFile($page, $format = 'jpg', $resolution = 150, $quality = 85, $withText = true, $withGraphics = true, $version = 'html') { - $path = $this->_getPath($page, $format, $resolution, $withText, $withGraphics, $version); + $path = $this->_getPath($page, $format, $resolution, $quality, $withText, $withGraphics, $version); if (file_exists($path)) { unlink($path); } - Cache::forget($this->fileCacheKey($page, $format, $resolution, $withText, $withGraphics, $version)); + Cache::forget($this->fileCacheKey($page, $format, $resolution, $quality, $withText, $withGraphics, $version)); } - public function _getFile($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $forceCheck = true) + public function _getFile($page, $format = 'jpg', $resolution = 150, $quality = 85, $withText = true, $withGraphics = true, $version = 'html', $forceCheck = true) { - if (!$this->hasFile($page, $format, $resolution, $withText, $withGraphics, $version, $forceCheck)) { - return Farm::getFile($page, $format, $resolution, $withText, $withGraphics, $version, $this->getResolutionRatio(), $this->getMobileFirstRatio(), $this->path()); + if (!$this->hasFile($page, $format, $resolution, $quality, $withText, $withGraphics, $version, $forceCheck)) { + return Farm::getFile($page, $format, $resolution, $quality, $withText, $withGraphics, $version, $this->getResolutionRatio(), $this->getMobileFirstRatio(), $this->path()); } - $path = $this->_getPath($page, $format, $resolution, $withText, $withGraphics, $version); + $path = $this->_getPath($page, $format, $resolution, $quality, $withText, $withGraphics, $version); touch($path); return $path; } diff --git a/app/Models/FluidbookPublication.php b/app/Models/FluidbookPublication.php index 2b83524c4..e09f22219 100644 --- a/app/Models/FluidbookPublication.php +++ b/app/Models/FluidbookPublication.php @@ -361,16 +361,8 @@ class FluidbookPublication extends ToolboxSettingsModel public function getFile($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $force = false) { - if ($format === 'jpg') { - $q = $this->JPEGQuality ?? 85; - } else { - $q = 85; - } - if ($q != 85) { - $resolution .= '-' . $q; - } $compo = $this->composition[$page]; - return self::_getDocument($compo[0])->getFile($compo[1], $format, $resolution, $withText, $withGraphics, $version, $force); + return self::_getDocument($compo[0])->getFile($compo[1], $format, $resolution, $this->JPEGQuality, $withText, $withGraphics, $version, $force); } @@ -379,10 +371,10 @@ class FluidbookPublication extends ToolboxSettingsModel if ($this->pdfThumbnails) { $thumbpdf = $this->getAssetDir() . $this->pdfThumbnails; if (file_exists($thumbpdf)) { - return Farm::getFileFromPDF($thumbpdf, $page, $format, $resolution, $withText, $withGraphics, $version, null, $force); + return Farm::getFileFromPDF($thumbpdf, $page, $format, $resolution, $this->JPEGQuality, $withText, $withGraphics, $version, null, $force); } } - return $this->getFile($page, $format, $resolution, $withText, $withGraphics, $version, $force); + return $this->getFile($page, $format, $resolution, $this->JPEGQuality, $withText, $withGraphics, $version, $force); } diff --git a/composer.lock b/composer.lock index af7a28884..fa639ec2f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "acbf857db884549552451fd0627e815a", + "content-hash": "fef46b5bfa05bbfea931657ffa20b91f", "packages": [ { "name": "archtechx/enums", @@ -1873,13 +1873,13 @@ "source": { "type": "git", "url": "git://git.cubedesigners.com/cubist_pdf.git", - "reference": "ad6cfa74d75d16e6802520c9581d49fcfa4a9bf8" + "reference": "aa082e3acaca6bef981ae178938945af5e5eb2ca" }, "dist": { "type": "tar", - "url": "https://composer.cubedesigners.com/dist/cubist/pdf/cubist-pdf-dev-master-116e2d.tar", - "reference": "ad6cfa74d75d16e6802520c9581d49fcfa4a9bf8", - "shasum": "8373614077332bc998389e20c4f7ae0d5662f1e9" + "url": "https://composer.cubedesigners.com/dist/cubist/pdf/cubist-pdf-dev-master-ffceb2.tar", + "reference": "aa082e3acaca6bef981ae178938945af5e5eb2ca", + "shasum": "ab0ed6813ff314253079f48f9101395b42d32538" }, "require": { "cubist/util": "dev-master", @@ -1915,7 +1915,7 @@ "cubist", "pdf" ], - "time": "2023-04-06T09:19:37+00:00" + "time": "2023-06-05T10:42:49+00:00" }, { "name": "cubist/scorm", @@ -2552,25 +2552,29 @@ }, { "name": "doctrine/deprecations", - "version": "v1.1.0", + "version": "v1.1.1", "source": { "type": "git", "url": "https://github.com/doctrine/deprecations.git", - "reference": "8cffffb2218e01f3b370bf763e00e81697725259" + "reference": "612a3ee5ab0d5dd97b7cf3874a6efe24325efac3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/deprecations/zipball/8cffffb2218e01f3b370bf763e00e81697725259", - "reference": "8cffffb2218e01f3b370bf763e00e81697725259", + "url": "https://api.github.com/repos/doctrine/deprecations/zipball/612a3ee5ab0d5dd97b7cf3874a6efe24325efac3", + "reference": "612a3ee5ab0d5dd97b7cf3874a6efe24325efac3", "shasum": "" }, "require": { - "php": "^7.1|^8.0" + "php": "^7.1 || ^8.0" }, "require-dev": { "doctrine/coding-standard": "^9", - "phpunit/phpunit": "^7.5|^8.5|^9.5", - "psr/log": "^1|^2|^3" + "phpstan/phpstan": "1.4.10 || 1.10.15", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "psalm/plugin-phpunit": "0.18.4", + "psr/log": "^1 || ^2 || ^3", + "vimeo/psalm": "4.30.0 || 5.12.0" }, "suggest": { "psr/log": "Allows logging deprecations via PSR-3 logger implementation" @@ -2589,9 +2593,9 @@ "homepage": "https://www.doctrine-project.org/", "support": { "issues": "https://github.com/doctrine/deprecations/issues", - "source": "https://github.com/doctrine/deprecations/tree/v1.1.0" + "source": "https://github.com/doctrine/deprecations/tree/v1.1.1" }, - "time": "2023-05-29T18:55:17+00:00" + "time": "2023-06-03T09:27:29+00:00" }, { "name": "doctrine/event-manager", @@ -3556,13 +3560,13 @@ "source": { "type": "git", "url": "git://git.cubedesigners.com/fluidbook_tools.git", - "reference": "62113b9880ca6515de74ca7161f6293b7feafa44" + "reference": "f370f46431a6c2d6bc88f765555ac4a2b1710cf7" }, "dist": { "type": "tar", - "url": "https://composer.cubedesigners.com/dist/fluidbook/tools/fluidbook-tools-dev-master-5738ef.tar", - "reference": "62113b9880ca6515de74ca7161f6293b7feafa44", - "shasum": "dc6651251450309fcace894ac9b06b9781d5f307" + "url": "https://composer.cubedesigners.com/dist/fluidbook/tools/fluidbook-tools-dev-master-d4e856.tar", + "reference": "f370f46431a6c2d6bc88f765555ac4a2b1710cf7", + "shasum": "91cfc88a62fa8b4d47063a2ec9aa9d382972be6a" }, "require": { "barryvdh/laravel-debugbar": "*", @@ -3596,7 +3600,7 @@ } ], "description": "Fluidbook Tools", - "time": "2023-06-01T09:36:30+00:00" + "time": "2023-06-05T11:49:06+00:00" }, { "name": "fruitcake/php-cors", @@ -14359,16 +14363,16 @@ }, { "name": "mockery/mockery", - "version": "1.5.1", + "version": "1.6.0", "source": { "type": "git", "url": "https://github.com/mockery/mockery.git", - "reference": "e92dcc83d5a51851baf5f5591d32cb2b16e3684e" + "reference": "bac1765cb52bbd3364a870e920cb69cd859ee302" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/mockery/mockery/zipball/e92dcc83d5a51851baf5f5591d32cb2b16e3684e", - "reference": "e92dcc83d5a51851baf5f5591d32cb2b16e3684e", + "url": "https://api.github.com/repos/mockery/mockery/zipball/bac1765cb52bbd3364a870e920cb69cd859ee302", + "reference": "bac1765cb52bbd3364a870e920cb69cd859ee302", "shasum": "" }, "require": { @@ -14380,7 +14384,9 @@ "phpunit/phpunit": "<8.0" }, "require-dev": { - "phpunit/phpunit": "^8.5 || ^9.3" + "phpunit/phpunit": "^8.5 || ^9.3", + "psalm/plugin-phpunit": "^0.18", + "vimeo/psalm": "^5.9" }, "type": "library", "extra": { @@ -14389,8 +14395,12 @@ } }, "autoload": { - "psr-0": { - "Mockery": "library/" + "files": [ + "library/helpers.php", + "library/Mockery.php" + ], + "psr-4": { + "Mockery\\": "library/Mockery" } }, "notification-url": "https://packagist.org/downloads/", @@ -14425,9 +14435,9 @@ ], "support": { "issues": "https://github.com/mockery/mockery/issues", - "source": "https://github.com/mockery/mockery/tree/1.5.1" + "source": "https://github.com/mockery/mockery/tree/1.6.0" }, - "time": "2022-09-07T15:32:08+00:00" + "time": "2023-05-03T12:55:29+00:00" }, { "name": "myclabs/deep-copy", -- 2.39.5