From 25251f8a27078cc7e8a01ec12fb7ef8b8a866945 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 20 Dec 2023 11:01:40 +0100 Subject: [PATCH] fix #6585 @0.75 --- app/Fluidbook/Compiler/Compiler.php | 21 ++++++++++++++++++++- app/Models/FluidbookHealthIssues.php | 10 ++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/Fluidbook/Compiler/Compiler.php b/app/Fluidbook/Compiler/Compiler.php index c34a0b78c..f2e3449c9 100644 --- a/app/Fluidbook/Compiler/Compiler.php +++ b/app/Fluidbook/Compiler/Compiler.php @@ -555,6 +555,7 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError $this->checkConfig(); $this->checkPageLabels(); + $this->checkChapters(); // We need to be able to reference both navOrder and navOrderH so convert both to arrays // We also make sure there are no empty items in the arrays (see: http://php.net/manual/en/function.array-filter.php#111091) @@ -585,6 +586,21 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError } + protected function checkChapters() + { + $num = $this->_fluidbook->chaptersPagesNumber; + foreach ($this->_fluidbook->getChapters() as $chapter) { + if (in_array($chapter['decoration'], ['nocut', 'forcecut', 'column_head', 'separator'])) { + continue; + } + $error = ($num === 'virtual' && !$this->virtualToPhysical($chapter['page'], true)) || ($num === 'physical' && $chapter['page'] > $this->_fluidbook->getPagesNumber()); + if ($error) { + FluidbookHealthIssues::addIssue($this->book_id, FluidbookHealthIssues::TYPE_CHAPTER_PAGE_NOT_EXIST, ['chapter' => $chapter['label'], 'page' => $chapter['page']]); + } + + } + } + protected function checkConfig() { if ($this->isMobileFirst() && $this->fluidbookSettings->mobilefirstFluidbookId) { @@ -673,12 +689,15 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError return $this->linkScale; } - public function virtualToPhysical($virtual): string|int + public function virtualToPhysical($virtual, $returnFalseIfNotExist = false): string|int { if (isset($this->pageLabels[$virtual])) { return $virtual; } if (!in_array($virtual, $this->numerotation)) { + if ($returnFalseIfNotExist) { + return false; + } return $virtual; } $p = array_search($virtual, $this->numerotation); diff --git a/app/Models/FluidbookHealthIssues.php b/app/Models/FluidbookHealthIssues.php index e3a598818..8b3fb46c4 100644 --- a/app/Models/FluidbookHealthIssues.php +++ b/app/Models/FluidbookHealthIssues.php @@ -16,6 +16,7 @@ class FluidbookHealthIssues extends ToolboxModel const TYPE_MOBILEFIRST_CONFIG = 3; const TYPE_TTS_VOICE_INVALID = 4; const TYPE_COMPILE_FILES = 5; + const TYPE_CHAPTER_PAGE_NOT_EXIST=6; const CRIT_ERROR = 5; const CRIT_WARNING = 3; @@ -69,6 +70,7 @@ class FluidbookHealthIssues extends ToolboxModel * __('Ce fluidbook mobile first a le paramètre "Identifiant du fluidbook Mobile first" défini. Ce paramètre est réservé aux fluidbooks Desktop') * __('La voix d\'audiodescription :voice est invalide') * __('L\'erreur suivante s\'est produite lors de la compilation du fluidbook : :error') + * __('Page introuvable pour le chapitre intitulé :chapter (Page :page). L\'élement ne sera pas affiché dans la publication') * */ return [ @@ -107,6 +109,14 @@ class FluidbookHealthIssues extends ToolboxModel 'criticality' => self::CRIT_ERROR, 'text' => 'L\'erreur suivante s\'est produite lors de la compilation du fluidbook : :error', ], + static::TYPE_CHAPTER_PAGE_NOT_EXIST => + [ + 'summary' => __('Page de sommaire introuvable'), + 'criticality' => self::CRIT_ERROR, + 'text' => 'Page introuvable pour le chapitre intitulé :chapter (Page :page). L\'élement ne sera pas affiché dans la publication.', + 'fixText' => __('Editer le sommaire'), + 'fixURL' => route('fluidbook-publication.edit', ['id' => $fluidbookId]) . '#s_section_chapters', + ], ]; } -- 2.39.5