From: Vincent Vanwaelscappel Date: Fri, 10 Feb 2023 13:44:26 +0000 (+0100) Subject: wip #5721 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=8031dcd18d087c161ec8bc99db41f8f8f7405bc1;p=fluidbook-toolbox.git wip #5721 @0.5 --- diff --git a/app/Fluidbook/Links.php b/app/Fluidbook/Links.php index 8943c5a84..c94a86f8e 100644 --- a/app/Fluidbook/Links.php +++ b/app/Fluidbook/Links.php @@ -2,11 +2,13 @@ namespace App\Fluidbook; +use App\Models\FluidbookPublication; use App\Models\User; use App\Util\wsDAOBook; use App\Util\wsDocument; use Cubist\Util\ArrayUtil; use Cubist\Util\Files\Files; +use Cubist\Util\Gzip; use Cubist\Util\Str; use Fluidbook\Tools\Links\Link; use PhpOffice\PhpSpreadsheet\Cell\DataType; @@ -388,28 +390,18 @@ class Links public static function addLinksFromPDF($book_id) { - global $core; - - $daoBook = new wsDAOBook($core->con); - $pages = $daoBook->getPagesOfBook($book_id); + /** @var FluidbookPublication $book */ + $book = FluidbookPublication::withoutGlobalScopes()->find($book_id); $booleans = array('video_loop', 'video_auto_start', 'video_controls', 'video_sound_on'); $numbers = ['left', 'top', 'width', 'height']; $links = []; - foreach ($pages as $page => $info) { - $csv = wsDocument::getDir($info['document_id']) . '/p' . $info['document_page'] . '.csv'; - if (!file_exists($csv) && file_exists($csv . '.gz')) { - $csv = 'compress.zlib://' . $csv . '.gz'; - } elseif (!file_exists($csv)) { - continue; - } - - $newformat = (filemtime($csv) > 1363685416); - - $fp = fopen($csv, 'rb'); + $pages = $book->getComposition(); + foreach ($pages as $page => $doc) { + $fp = Gzip::fopen($book->getDocument($doc[0])->path('p' . $doc[1] . '.csv')); while (true) { $line = fgetcsv($fp, 512, ';', '"'); // End of file @@ -423,13 +415,7 @@ class Links } $link = []; - if ($newformat) { - $cols = array('page' => '', 'left' => '', 'top' => '', 'width' => '', 'height' => '', 'type' => '', 'to' => '', 'target' => '_blank', 'video_loop' => true, 'video_auto_start' => true, 'video_controls' => true, 'video_sound_on' => true, 'infobulle' => '', 'numerotation' => 'physical', "inline" => true); - } else { - $cols = array('page' => '', 'type' => '', 'to' => '', 'left' => '', 'top' => '', 'width' => '', 'height' => '', 'target' => '_blank', 'video_loop' => true, 'video_auto_start' => true, 'video_controls' => true, 'video_sound_on' => true, 'infobulle' => '', 'numerotation' => 'physical'); - } - - + $cols = array('page' => '', 'left' => '', 'top' => '', 'width' => '', 'height' => '', 'type' => '', 'to' => '', 'target' => '_blank', 'video_loop' => true, 'video_auto_start' => true, 'video_controls' => true, 'video_sound_on' => true, 'infobulle' => '', 'numerotation' => 'physical', "inline" => true); $k = 0; foreach ($cols as $col => $default) { if (isset($line[$k])) { @@ -438,7 +424,7 @@ class Links } else if (in_array($k, $booleans)) { $link[$col] = ($line[$k] == '1'); } else { - $link[$col] = utf8_encode($line[$k]); + $link[$col] = $line[$k]; } } else { $link[$col] = $default; @@ -453,12 +439,13 @@ class Links $link['display_area'] = '1'; $link['page'] = $page; + $link['uid'] = self::generateUID(); $links[] = $link; } - + fclose($fp); } - self::saveLinksInFile($book_id, $core->user->utilisateur_id, 'Links imported from PDF', $links, []); + self::saveLinksInFile($book_id, backpack_user()->id, 'Links imported from PDF', $links); } public static function getLinksAndRulersFromExcelFile($path, &$links, &$rulers) diff --git a/app/Jobs/FluidbookDocumentUpload.php b/app/Jobs/FluidbookDocumentUpload.php index 09a028262..e66790bdb 100644 --- a/app/Jobs/FluidbookDocumentUpload.php +++ b/app/Jobs/FluidbookDocumentUpload.php @@ -2,6 +2,7 @@ namespace App\Jobs; +use App\Fluidbook\Links; use App\Models\FluidbookDocument; use App\Models\User; use Illuminate\Support\Facades\Cache; @@ -39,6 +40,7 @@ class FluidbookDocumentUpload extends Base try { 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) { error_log($e); } diff --git a/composer.lock b/composer.lock index 6dae228e0..9d2e41d64 100644 --- a/composer.lock +++ b/composer.lock @@ -2223,13 +2223,13 @@ "source": { "type": "git", "url": "git://git.cubedesigners.com/cubist_util.git", - "reference": "8ca0e77316c93612593605ede9b457208fe1ae1f" + "reference": "9c379ada28a41672fdaeae328c5d4ab1d1579ddc" }, "dist": { "type": "tar", - "url": "https://composer.cubedesigners.com/dist/cubist/util/cubist-util-dev-master-dc542c.tar", - "reference": "8ca0e77316c93612593605ede9b457208fe1ae1f", - "shasum": "e61ff95f8167d578a732deeae83f8117cdbe11a6" + "url": "https://composer.cubedesigners.com/dist/cubist/util/cubist-util-dev-master-54b85e.tar", + "reference": "9c379ada28a41672fdaeae328c5d4ab1d1579ddc", + "shasum": "8c7bf70c044f4493e179137292b0f59d79d57fcd" }, "require": { "cubist/net": "dev-master", @@ -2261,7 +2261,7 @@ } ], "description": "Utilities class", - "time": "2023-01-30T10:26:43+00:00" + "time": "2023-02-10T13:34:52+00:00" }, { "name": "cviebrock/eloquent-sluggable",