From bf0d6b6e9e6c75862ed5d9c366b61c1f8b905777 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 28 Nov 2023 13:18:49 +0100 Subject: [PATCH] wait #6524 @2.5 --- .../FluidbookCollection/PreviewOperation.php | 4 +- app/Jobs/FluidbookCollectionDownload.php | 73 ++++++++++--------- app/Models/FluidbookCollection.php | 4 +- 3 files changed, 44 insertions(+), 37 deletions(-) diff --git a/app/Http/Controllers/Admin/Operations/FluidbookCollection/PreviewOperation.php b/app/Http/Controllers/Admin/Operations/FluidbookCollection/PreviewOperation.php index 15247de26..ad92dc9a9 100644 --- a/app/Http/Controllers/Admin/Operations/FluidbookCollection/PreviewOperation.php +++ b/app/Http/Controllers/Admin/Operations/FluidbookCollection/PreviewOperation.php @@ -73,7 +73,7 @@ trait PreviewOperation $isScorm = $version === 'scorm'; - $dest = $collection->getFinalPath($theme, $isScorm); + $dest = $collection->getFinalPath() . $collection->type . '/online'; if ($path === 'index.html') { $collection->incrementPreviewVisit(); $compiler = new FluidbookCollectionDownload($collection, 'export', backpack_user()); @@ -104,7 +104,7 @@ trait PreviewOperation abort(404); } foreach ($collection->publications as $pub) { - $fluidbook = FluidbookPublication::withoutGlobalScopes()->find( $pub['fluidbook']); + $fluidbook = FluidbookPublication::withoutGlobalScopes()->find($pub['fluidbook']); if (null === $fluidbook) { continue; } diff --git a/app/Jobs/FluidbookCollectionDownload.php b/app/Jobs/FluidbookCollectionDownload.php index 6829c83d6..d9536b921 100644 --- a/app/Jobs/FluidbookCollectionDownload.php +++ b/app/Jobs/FluidbookCollectionDownload.php @@ -75,38 +75,31 @@ class FluidbookCollectionDownload extends DownloadBase protected function _compile() { - $compilepath = $this->entry->getFinalPath(); - $this->compile($compilepath, true); - return $compilepath; + return $this->compile(); } /** * @param $path - * @return void + * @return string * @throws \Exception */ - public function compile($path, $empty = true) + public function compile($forceVersion = null) { $data = $this->entry->getPageData(); - if ($empty) { - $path = Files::emptyDir($path); - } PHP::neverStop(); if ($data->type === 'scorm_multilang') { - $this->compileMultilang($data, $path, true); + return $this->compileMultilang('scorm'); } else if ($data->type === 'export_multilang') { - $this->compileMultilang($data, $path, false); + return $this->compileMultilang($forceVersion); } elseif ($data->type === 'export') { - $this->compileExport($data, $path); + return $this->compileExport(); } } public function compilePreview() { - $compilepath = $this->entry->getFinalPath(); - $this->compile($compilepath, false); - return $compilepath; + return $this->compile('online'); } protected function getCollectionGlobalSettings() @@ -125,12 +118,17 @@ class FluidbookCollectionDownload extends DownloadBase /** * @param $data PageData * @param $path string - * @return void + * @return string * @throws \Exception */ - protected function compileMultilang($data, $path, $scorm = false) + protected function compileMultilang($version = null) { + $data = $this->entry->getPageData(); $optionsFluidbooks = []; + if (null === $version) { + $version = $version ?? $data->version_multilang; + } + $basePath = Files::mkdir($this->entry->getFinalPath() . $data->type . '/' . $version); foreach ($data->publications as $publication) { $fbid = $publication['fluidbook']; @@ -145,7 +143,7 @@ class FluidbookCollectionDownload extends DownloadBase $multipleDevices = count(array_unique($this->devices)) > 1; $options = $this->getCollectionGlobalSettings(); - $options['scorm_enable'] = $scorm; + $options['scorm_enable'] = $version === 'scorm'; // We don't want an hybrid fluidbook in a collection $options['mobilefirstFluidbookId'] = ''; @@ -198,7 +196,7 @@ class FluidbookCollectionDownload extends DownloadBase $fbOptions += $optionsFluidbooks[$fbid]; } - $jobs[] = $this->_jobDownloadFluidbook($fbid, $scorm ? 'scorm' : 'online', $path . $this->dirs[$fbid], $fbOptions); + $jobs[] = $this->_jobDownloadFluidbook($fbid, $version, $basePath . $this->dirs[$fbid], $fbOptions); } $this->_waitJobs($jobs); @@ -208,10 +206,10 @@ class FluidbookCollectionDownload extends DownloadBase $default = $this->langs[0] ?? 'en'; } - if ($scorm) { - $manifestFile = $path . 'imsmanifest.xml'; + if ($version === 'scorm') { + $manifestFile = $basePath . 'imsmanifest.xml'; foreach ($allVersions as $k => $dir) { - $manifest = $path . $dir . '/imsmanifest.xml'; + $manifest = $basePath . $dir . '/imsmanifest.xml'; if ($k === 0) { rename($manifest, $manifestFile); } else if (file_exists($manifest)) { @@ -224,17 +222,21 @@ class FluidbookCollectionDownload extends DownloadBase file_put_contents($manifestFile, $manifestContent); } + $ext = $version === 'sharepoint' ? 'aspx' : 'html'; + if ($multipleDevices) { if ($data->redirection_algorithm === 'language') { - $redirectScript = self::getMultiDevicesRedirectScript($versionsByLanguage, $default, $data->redirection_algorithm); + $redirectScript = self::getMultiDevicesRedirectScript($versionsByLanguage, $default, $data->redirection_algorithm, $ext); } else { - $redirectScript = self::getMultiDevicesRedirectScript($versionsByDevice, $default, $data->redirection_algorithm); + $redirectScript = self::getMultiDevicesRedirectScript($versionsByDevice, $default, $data->redirection_algorithm, $ext); } } else { - $redirectScript = self::getRedirectScript($versionsByLanguage, $default); + $redirectScript = self::getRedirectScript($versionsByLanguage, $default, $ext); } - file_put_contents($path . '/index.html', $redirectScript); + + file_put_contents($basePath . '/index.' . $ext, $redirectScript); + return $basePath; } @@ -277,7 +279,7 @@ class FluidbookCollectionDownload extends DownloadBase protected function _getMultilangOptions($fluidbooks) { - $defaultFlags = ['en' => 'gb', 'sv' => 'se', 'zh' => 'cn', 'el' => 'gr', 'ja' => 'jp', 'ko' => 'kr']; + $defaultFlags = ['en' => 'gb', 'sv' => 'se', 'zh' => 'cn', 'el' => 'gr', 'ja' => 'jp', 'ko' => 'kr', 'vi' => 'vn', 'cs' => 'cz']; $multilang = []; foreach ($fluidbooks as $fbid => $publication) { @@ -404,11 +406,13 @@ class FluidbookCollectionDownload extends DownloadBase /** * @param $data PageData * @param $path string - * @return void + * @return string * @throws \Exception */ - protected function compileExport($data, $basePath) + protected function compileExport($data) { + $data = $this->entry->getPageData(); + $basePath = Files::mkdir($this->entry->getFinalPath() . $data->type . '/' . $data->version); $options = $this->getCollectionGlobalSettings(); $jobs = []; @@ -419,6 +423,7 @@ class FluidbookCollectionDownload extends DownloadBase } $this->_waitJobs($jobs); + return $basePath; } protected function getPublicationsPaths($data, $attr = 'dir') @@ -441,17 +446,17 @@ class FluidbookCollectionDownload extends DownloadBase } - public static function getRedirectScript($versions, $default = 'en') + public static function getRedirectScript($versions, $default = 'en', $ext = 'html') { - return self::_getRedirectScript("var dir=guessPreferredLanguageVersion(" . json_encode($versions) . ",'" . $default . "');"); + return self::_getRedirectScript("var dir=guessPreferredLanguageVersion(" . json_encode($versions) . ",'" . $default . "');", $ext); } - public static function getMultiDevicesRedirectScript($versions, $default = 'en', $priority = 'language') + public static function getMultiDevicesRedirectScript($versions, $default = 'en', $priority = 'language', $ext = 'html') { - return self::_getRedirectScript("var dir=guessPreferredVersion('" . $priority . "'," . json_encode($versions) . ",'" . $default . "');"); + return self::_getRedirectScript("var dir=guessPreferredVersion('" . $priority . "'," . json_encode($versions) . ",'" . $default . "');", $ext); } - protected static function _getRedirectScript($code) + protected static function _getRedirectScript($code, $ext = 'html') { return " @@ -529,7 +534,7 @@ function getLanguagesFromBrowser() { } $code -window.location='./' + dir + '/index.html'; +window.location='./' + dir + '/index." . $ext . "'; "; diff --git a/app/Models/FluidbookCollection.php b/app/Models/FluidbookCollection.php index fa4a74be1..4eb36035a 100644 --- a/app/Models/FluidbookCollection.php +++ b/app/Models/FluidbookCollection.php @@ -74,6 +74,8 @@ class FluidbookCollection extends ToolboxStatusModel ] ); $this->addField('version', FluidbookExportVersion::class, __('Version'), ['when' => ['type' => 'export']]); + $excluded = array_diff(array_keys(FluidbookExportVersion::getVersions()), ['online', 'sharepoint']); + $this->addField('version_multilang', FluidbookExportVersion::class, __('Version'), ['when' => ['type' => 'export_multilang'], 'excluded_options' => $excluded, 'default' => 'online']); $this->addField('publications', BunchOfFieldsMultiple::class, __('Publications'), ['bunch' => CollectionPublication::class, 'edit_label' => '%fluidbook > %dir']); $this->addField('install', ExternalPath::class, 'Installer sur un serveur externe', ['default' => '', 'fake' => true, 'translatable' => false, 'store_in' => 'settings', 'servers_model' => FluidbookExternalInstallServer::class, ['when' => ['type' => ['export', 'export_multilang']]]]); $this->addField('override_settings', BunchOfFieldsMultiple::class, __('Redéfinir les paramètres lors de l\'export'), ['bunch' => Fluidbook_Setting::class]); @@ -96,7 +98,7 @@ class FluidbookCollection extends ToolboxStatusModel return $res; } - public function getFinalPath() + public function getFinalPath($type = null, $version = null) { return Files::mkdir(protected_path('fluidbookcollection/final/' . $this->id)); } -- 2.39.5