From de5815bdca100a30125e43a98315c13854ccdf03 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 2 Mar 2023 17:47:37 +0100 Subject: [PATCH] wait #5770 @1 --- app/Fluidbook/Links.php | 13 +++++++------ app/Jobs/FluidbookDocumentUpload.php | 3 ++- app/Models/FluidbookDocument.php | 26 +++++++------------------- 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/app/Fluidbook/Links.php b/app/Fluidbook/Links.php index 0f76aa7e5..030a6d041 100644 --- a/app/Fluidbook/Links.php +++ b/app/Fluidbook/Links.php @@ -147,13 +147,14 @@ class Links if ($time === 'latest' && !file_exists($file)) { $versions = self::getLinksVersions($book_id); foreach ($versions as $version => $m) { - try { - copy(Files::firstThatExists($dir . '/' . $version . '.links3.gz', $dir . '/' . $version . '.links.gz'), $dir . '/latest.links3.gz'); - copy(Files::firstThatExists($dir . '/' . $version . '.meta3.gz', $dir . '/' . $version . '.meta.gz'), $dir . '/latest.meta3.gz'); - break; - } catch (\Exception $e) { - + $lf = Files::firstThatExists($dir . '/' . $version . '.links3.gz', $dir . '/' . $version . '.links.gz'); + $mf = Files::firstThatExists($dir . '/' . $version . '.meta3.gz', $dir . '/' . $version . '.meta.gz'); + if (!file_exists($lf) || !file_exists($mf)) { + continue; } + copy($lf, $dir . '/latest.links3.gz'); + copy($mf, $dir . '/latest.meta3.gz'); + break; } } if (!file_exists($file)) { diff --git a/app/Jobs/FluidbookDocumentUpload.php b/app/Jobs/FluidbookDocumentUpload.php index e66790bdb..6fb7507ca 100644 --- a/app/Jobs/FluidbookDocumentUpload.php +++ b/app/Jobs/FluidbookDocumentUpload.php @@ -41,8 +41,9 @@ class FluidbookDocumentUpload extends Base FluidbookDocumentUpload::updateProgression($this->uploadID, $this->document->id, __('Début du traitement du document'), 1.25); $this->document->processUpload($this->uploadID, $sync); Links::addLinksFromPDF($this->fluidbook_id); - } catch (\Exception $e) { + } catch (\Throwable $e) { error_log($e); + FluidbookDocumentUpload::updateProgression($this->uploadID, $this->document->id, __('Une erreur s\'est produite :error', ['error' => $e->getMessage()]), -1); } } diff --git a/app/Models/FluidbookDocument.php b/app/Models/FluidbookDocument.php index 6e6c72474..ec9d0a375 100644 --- a/app/Models/FluidbookDocument.php +++ b/app/Models/FluidbookDocument.php @@ -15,6 +15,7 @@ use Cubist\PDF\PDFTools; use Cubist\Util\Gzip; use Cubist\Util\Math; use Illuminate\Support\Facades\Cache; + // __('!!Paramètres des fluidbooks') class FluidbookDocument extends ToolboxModel { @@ -159,11 +160,11 @@ class FluidbookDocument extends ToolboxModel } - public function checkInfos($force = false) { if ($force || null === $this->pdf_data) { $infos = $this->_getInfos(); + $this->pages = $infos->pages; $this->pdf_data = $infos->pdf_data; $this->bookmarks = $infos->bookmarks; @@ -401,6 +402,8 @@ class FluidbookDocument extends ToolboxModel public function cutDocument($mode) { + + $fwstk = new FWSTK(); $fwstk->setArg('--input ' . $this->getPDFSource('fixed')); $fwstk->setArg('--cut ' . $mode); @@ -410,6 +413,7 @@ class FluidbookDocument extends ToolboxModel public function trimDocument() { + $fwstk = new FWSTK(); $fwstk->setArg('--input ' . $this->getPDFSource('fixed')); $fwstk->setArg('--trim'); @@ -419,8 +423,7 @@ class FluidbookDocument extends ToolboxModel public function lnCrop() { - $root = $this->path(); - `cd $root;ln -s fixed.pdf crop.pdf`; + link($this->getPDFSource('crop'), $this->getPDFSource('fixed')); } protected function isCropped() @@ -446,6 +449,7 @@ class FluidbookDocument extends ToolboxModel if ($this->autocrop == 'trim') { $this->trimDocument(); } + return false; } @@ -501,22 +505,6 @@ class FluidbookDocument extends ToolboxModel } } - if ($first == $last && $last == $second) { - $ratio = $first[0] / $first[1]; - $this->autocut = false; - if ($ratio <= 1) { - $this->manualcut = false; - } elseif ($ratio >= 6) { - $this->manualcut = 'L8'; - } elseif ($ratio >= 3) { - $this->manualcut = 'L4'; - } elseif ($ratio >= 2) { - $this->manualcut = 'L3'; - } else { - $this->manualcut = '14-23'; - } - return; - } $this->manualcut = false; if (self::compareSizes($last, $first) && Math::compare($first[0] * 2, $second[0], 0.9)) { $this->autocut = '1-23-4'; -- 2.39.5