From: Vincent Vanwaelscappel Date: Wed, 20 Dec 2023 12:20:45 +0000 (+0100) Subject: wait #6586 @0.75 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=ca6d2491dc17730955b231308e0a4d22c11e431c;p=fluidbook-toolbox.git wait #6586 @0.75 --- diff --git a/app/Models/FluidbookDocument.php b/app/Models/FluidbookDocument.php index 295ae0d3e..c95e2bbdc 100644 --- a/app/Models/FluidbookDocument.php +++ b/app/Models/FluidbookDocument.php @@ -191,7 +191,7 @@ class FluidbookDocument extends ToolboxModel public function fixPDF() { - $fixed = $this->getPDFSource('fixed'); + $fixed = $this->getPDFSource('fixed',false); $original = $this->getPDFSource('original'); if (!file_exists($fixed) || filesize($fixed) === 0 || filemtime($fixed) < filemtime($original)) { PDFTools::fixPDF($original, $fixed); @@ -396,9 +396,6 @@ class FluidbookDocument extends ToolboxModel $path = $this->_getTextPath($page, $type, $mode, $extractionMethod, $ignoreSeparators); if (!$this->_checkTextFile($path)) { PDFTools::extractTexts($this->getPDFSource(), $this->path(), $mode, $extractionMethod, $ignoreSeparators); - if (!Gzip::file_exists($path)) { - throw new \Exception('An error occured while producing file ' . $path); - } } return Gzip::path($path); } @@ -452,9 +449,19 @@ class FluidbookDocument extends ToolboxModel return $this->path('texts/' . $dir . $sepFolder) . $prefix . $type . $page . '.txt'; } - public function getPDFSource($type = 'crop'): string + public function getPDFSource($type = 'crop', $checkIfExists = true): string { - return $this->path() . $type . '.pdf'; + $res = $this->path() . $type . '.pdf'; + if ($checkIfExists && !file_exists($res)) { + if ($type === 'original') { + throw new \Exception('Missing original PDF file ' . $res); + } else if ($type === 'fixed') { + $this->fixPDF(); + } else if ($type === 'crop') { + $this->cropAndCut(); + } + } + return $res; } public function cutDocument($mode) @@ -462,7 +469,7 @@ class FluidbookDocument extends ToolboxModel $fwstk = new FWSTK(); $fwstk->setArg('--input ' . $this->getPDFSource('fixed')); $fwstk->setArg('--cut ' . $mode); - $fwstk->setArg('--output ' . $this->getPDFSource()); + $fwstk->setArg('--output ' . $this->getPDFSource('crop', false)); $fwstk->execute(); } @@ -472,13 +479,13 @@ class FluidbookDocument extends ToolboxModel $fwstk = new FWSTK(); $fwstk->setArg('--input ' . $this->getPDFSource('fixed')); $fwstk->setArg('--trim'); - $fwstk->setArg('--output ' . $this->getPDFSource()); + $fwstk->setArg('--output ' . $this->getPDFSource('crop', false)); $fwstk->execute(); } public function lnCrop() { - link($this->getPDFSource('fixed'), $this->getPDFSource()); + link($this->getPDFSource('fixed'), $this->getPDFSource('crop', false)); } protected function isCropped() diff --git a/app/Models/FluidbookPublication.php b/app/Models/FluidbookPublication.php index ebee1962b..18ecc9f5d 100644 --- a/app/Models/FluidbookPublication.php +++ b/app/Models/FluidbookPublication.php @@ -210,7 +210,7 @@ class FluidbookPublication extends ToolboxStatusModel 'searchLogic' => false, 'can' => 'fluidbook-publication:admin', ]); - + $this->addField('section_composition', FormBigSection::class, __('Composition')); $this->addField('composition_fluidbook', Checkbox::class, __('Utiliser la composition d\'un autre fluidbook'), ['default' => false]); $this->addField('composition_fluidbook_id', FluidbookV3ID::class, __('Utiliser la composition d\'un autre fluidbook'), ['excluded_options' => $this->id, 'when' => ['composition_fluidbook' => 1]]); @@ -604,11 +604,11 @@ class FluidbookPublication extends ToolboxStatusModel return $this->composition_updated_at->getTimestamp(); } - public function getPDFSource($page, $type = 'crop'): string + public function getPDFSource($page, $type = 'crop', $checkIfExist = true): string { $compo = $this->getComposition()[$page]; if ($type == 'crop') { - return self::_getDocument($compo[0])->getPDFSource($type); + return self::_getDocument($compo[0])->getPDFSource($type, $checkIfExist); } }