From 0a23c2e7ad4cd205e9c5fadf8768175a1a0d5076 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 15 Jan 2026 18:23:03 +0100 Subject: [PATCH] #7898 @1 --- app/Fluidbook/Compiler/Links.php | 49 +++++++++++++++----------- app/Jobs/FluidbookImagesPreprocess.php | 23 +++++++++++- app/Jobs/OCR.php | 1 + 3 files changed, 51 insertions(+), 22 deletions(-) diff --git a/app/Fluidbook/Compiler/Links.php b/app/Fluidbook/Compiler/Links.php index 5d52c5b9f..7252b66dd 100644 --- a/app/Fluidbook/Compiler/Links.php +++ b/app/Fluidbook/Compiler/Links.php @@ -7,8 +7,6 @@ use App\Fluidbook\Link\Link; use App\Fluidbook\Link\LinksData; use App\Jobs\OCR; use App\SubForms\Link\Base; -use Cubist\Util\CommandLine\Docling; -use Cubist\Util\Graphics\Color; use Cubist\Util\Text; use Cubist\Util\Url; use Fluidbook\Tools\Links\AnchorLink; @@ -531,30 +529,39 @@ trait Links $this->config->push('triggersLinks', ['page' => $page, 'link' => $link, 'delay' => $delay]); } - public function getLinkAlternativeText($link, $returnJob = false) + public function getLinkAlternativeText($link, $returnJobs = false) { - if (!$link->getOCR()) { - return ''; + $ocr = $link->getOCR(); + if ($returnJobs) { + $res = []; + } else { + $res = ''; } - - if (Url::isDistant($link->to)) { - return ''; + if (!$ocr) { + return $res; } - $file = $this->wdir . '/' . $link->to; - if (!file_exists($file)) { - return ''; - } - $ext = ['jpg', 'jpeg', 'png', 'svg', 'pdf']; - $f = new \SplFileInfo($file); - if (!in_array($f->getExtension(), $ext)) { - return ''; - } + foreach ($ocr as $attr) { + if (Url::isDistant($link->$attr)) { + continue; + } + $file = $this->wdir . '/' . $link->$attr; - if ($returnJob) { - return new OCR($file, $this->getFluidbook()->locale); + if (!file_exists($file)) { + continue; + } + $ext = ['jpg', 'jpeg', 'png', 'svg', 'pdf']; + $f = new \SplFileInfo($file); + if (!in_array($f->getExtension(), $ext)) { + continue; + } + + if ($returnJobs) { + $res[] = new OCR($file, $this->getFluidbook()->locale); + } else { + $res .= Farm::OCR($file, $this->getFluidbook()->locale); + } } - return Farm::OCR($file, $this->getFluidbook()->locale); + return $res; } - } diff --git a/app/Jobs/FluidbookImagesPreprocess.php b/app/Jobs/FluidbookImagesPreprocess.php index 381d5bfea..d039d8d83 100644 --- a/app/Jobs/FluidbookImagesPreprocess.php +++ b/app/Jobs/FluidbookImagesPreprocess.php @@ -5,6 +5,7 @@ namespace App\Jobs; use App\Fluidbook\Compiler\Compiler; use App\Models\FluidbookPublication; use Cubist\Util\ArrayUtil; +use Fluidbook\Tools\Links\Link; use Illuminate\Support\Facades\Log; class FluidbookImagesPreprocess extends Base @@ -81,7 +82,27 @@ class FluidbookImagesPreprocess extends Base } $this->book->getLinksAndRulers($links, $rulers); - + $compiler = new Compiler($this->book); + $i = 0; + foreach ($links as $link) { + $l = Link::getInstance($i, $link, $compiler); + if (null === $l) { + continue; + } + $jobs = $compiler->getLinkAlternativeText($l, true); + if (!$jobs) { + continue; + } + $this->jobs += $jobs; + foreach ($jobs as $job) { + if ($this->_sync) { + $job->handle(); + } else { + dispatch($job); + } + } + $i++; + } while (true) { if ($this->_checkJobs()) { diff --git a/app/Jobs/OCR.php b/app/Jobs/OCR.php index e886c0855..ffe713db4 100644 --- a/app/Jobs/OCR.php +++ b/app/Jobs/OCR.php @@ -11,6 +11,7 @@ class OCR extends BaseStatus public function __construct($file, $locale = null) { + $this->onQueue('fluidbookprocess'); $this->file = $file; $this->locale = $locale; } -- 2.39.5