From edfbe9e1d0d350de09f0884d2f7962d93621343a Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 2 Sep 2022 16:09:58 +0200 Subject: [PATCH] wait #5429 @0.5 --- .../FluidbookPublication/PreviewOperation.php | 33 ++++++++++++++----- app/Jobs/FluidbookCompiler.php | 19 ++++++----- app/Models/FluidbookPublication.php | 4 +-- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/app/Http/Controllers/Admin/Operations/FluidbookPublication/PreviewOperation.php b/app/Http/Controllers/Admin/Operations/FluidbookPublication/PreviewOperation.php index 25dd8b202..eed7572c1 100644 --- a/app/Http/Controllers/Admin/Operations/FluidbookPublication/PreviewOperation.php +++ b/app/Http/Controllers/Admin/Operations/FluidbookPublication/PreviewOperation.php @@ -16,15 +16,30 @@ trait PreviewOperation { protected function setupPreviewRoutes($segment, $routeName, $controller) { + Route::match(['get'], $segment . '/preview/{version}/{id}_{hash}', function ($version, $id, $hash) use ($segment) { + return $this->_preview($segment, $version, $id, $hash, null, 'index.html'); + })->where('id', '([0-9]+)(-[0-9]+)?') + ->whereAlpha('version') + ->where('hash', '[0-9a-f]{32}') + ->withoutMiddleware([CheckIfAdmin::class]); + + Route::match(['get'], $segment . '/preview/{version}/{id}_{hash}_{time}/{path?}', function ($version, $id, $hash, $time, $path = 'index.html') use ($segment, $controller) { + return $this->_preview($segment, $version, $id, $hash, $time, $path); + })->where('id', '([0-9]+)(-[0-9]+)?') + ->where('hash', '[0-9a-f]{32}') + ->where('path', '.*') + ->whereAlpha('version') + ->withoutMiddleware([CheckIfAdmin::class]); + // Redirect to the url with a timestamp to prevent cache Route::match(['get'], $segment . '/preview/{id}_{hash}', function ($id, $hash) use ($segment) { - return $this->_preview($segment, $id, $hash, null, 'index.html'); + return $this->_preview($segment, 'online', $id, $hash, null, 'index.html'); })->where('id', '([0-9]+)(-[0-9]+)?') ->where('hash', '[0-9a-f]{32}') ->withoutMiddleware([CheckIfAdmin::class]); Route::match(['get'], $segment . '/preview/{id}_{hash}_{time}/{path?}', function ($id, $hash, $time, $path = 'index.html') use ($segment, $controller) { - return $this->_preview($segment, $id, $hash, $time, $path); + return $this->_preview($segment, 'online', $id, $hash, $time, $path); })->where('id', '([0-9]+)(-[0-9]+)?') ->where('hash', '[0-9a-f]{32}') ->where('path', '.*') @@ -36,7 +51,7 @@ trait PreviewOperation $this->crud->addButtonFromView('line', 'preview', 'fluidbook_publication.preview', 'end'); } - protected function _preview($segment, $id, $hash, $time = null, $path = null) + protected function _preview($segment, $version, $id, $hash, $time = null, $path = null) { $q = request()->getQueryString(); if ($q) { @@ -46,17 +61,17 @@ trait PreviewOperation $shortLoading = !!request('shortLoading', false); if (null === $time || ((null === $path || $path === 'index.html') && $time < (time() - 60) && !$nointerface && !$shortLoading)) { - $url = backpack_url($segment . '/preview/' . $id . '_' . $hash . '_' . time()) . '/' . $q; + $v = ($version === 'online') ? '' : $version . '/'; + $url = backpack_url($segment . '/preview/' . $v . $id . '_' . $hash . '_' . time()) . '/' . $q; return $this->loadingCompile($url, $id, $hash); } - self::_getFluidbookAndTheme($id, $hash, $fluidbook, $theme); $check = $this->_checkDemoLinkAuth($fluidbook); if ($check !== true) { return $check; } - return $this->preview($fluidbook, $theme, $path); + return $this->preview($version, $fluidbook, $theme, $path); } /** @@ -151,14 +166,14 @@ html,body{height:100%;cursor: wait;font-family: "Open Sans", Arial;background-co /** * @throws \Exception */ - public function preview($fluidbook, $theme, $path = 'index.html') + public function preview($version, $fluidbook, $theme, $path = 'index.html') { $nointerface = !!request('nointerface', false); $shortLoading = !!request('shortLoading', false); - $dest = $fluidbook->getFinalPath($theme); + $dest = $fluidbook->getFinalPath($theme, $version); if ($path === 'index.html') { - $compiler = new FluidbookCompiler($fluidbook, theme: $theme); + $compiler = new FluidbookCompiler($fluidbook, version: $version, theme: $theme); $compiler->handle(); } return XSendFileController::sendfile($dest . '/' . $path); diff --git a/app/Jobs/FluidbookCompiler.php b/app/Jobs/FluidbookCompiler.php index 1663c7a1e..8280deaa9 100644 --- a/app/Jobs/FluidbookCompiler.php +++ b/app/Jobs/FluidbookCompiler.php @@ -200,7 +200,7 @@ class FluidbookCompiler extends Base implements CompilerInterface public $book; public $pages; public $theme; - public $version; + public $devversion; public $book_id; public $themeRoot; public $needToRecompileContents = true; @@ -282,7 +282,7 @@ class FluidbookCompiler extends Base implements CompilerInterface * @throws \Exception */ - function __construct(FluidbookPublication $book, $version = null, $phonegap = false, $phonegapVersion = 'latest', $dir = null, $standalone = false, $appcache = false, $home = false, FluidbookTheme $theme = null, $hybrid = false, Command $command = null) + function __construct(FluidbookPublication $book, $version = 'online', $phonegap = false, $phonegapVersion = 'latest', $dir = null, $standalone = false, $appcache = false, $home = false, FluidbookTheme $theme = null, $hybrid = false, Command $command = null) { parent::__construct(); @@ -292,12 +292,13 @@ class FluidbookCompiler extends Base implements CompilerInterface $this->phonegapVersion = self::getPhonegapVersion($phonegapVersion); $this->appcache = $appcache; $this->multiApp = $this->home = $home; - $this->version = $this->version ?? $this->getFluidbook()->mobileLVersion; + $this->devversion = $this->getFluidbook()->mobileLVersion; + $this->version = $version; $this->hybrid = $hybrid; - $this->assets = self::getSourcesPath($this->version); - $this->compiledAssets = self::getCompiledSourcesPath($this->version); + $this->assets = self::getSourcesPath($this->devversion); + $this->compiledAssets = self::getCompiledSourcesPath($this->devversion); $this->phonegap = $phonegap; $this->standalone = $standalone || $this->phonegap; @@ -311,7 +312,7 @@ class FluidbookCompiler extends Base implements CompilerInterface $this->book_id = $this->getFluidbook()->id; $this->log('Start compilation'); - $this->dir = $this->getFluidbook()->getFinalPath($theme); + $this->dir = $this->getFluidbook()->getFinalPath($theme, $version); $this->vdir = new VirtualDirectory($this->dir); $this->wdir = $this->getFluidbook()->getAssetDir(); @@ -468,6 +469,10 @@ class FluidbookCompiler extends Base implements CompilerInterface public function initConfig() { + if ($this->version !== 'scorm') { + $this->fluidbookSettings->scorm_enable = false; + } + $this->config = new Data(array_merge($this->fluidbookSettings->getRawData()['settings'], $this->themeSettings->getRawData())); $this->config->pages = count($this->getFluidbook()->composition); $this->config->bookmarkDisablePages = ArrayUtil::parseRange($this->config->bookmarkDisablePages); @@ -1261,7 +1266,6 @@ class FluidbookCompiler extends Base implements CompilerInterface protected function writeStats() { - if ($this->fluidbookSettings->stats) { $this->config->statsMatomo = $this->book_id; $this->config->statsMatomoServer = 3; @@ -1273,7 +1277,6 @@ class FluidbookCompiler extends Base implements CompilerInterface } if ($this->fluidbookSettings->tagcommander_id) { - $id = $this->fluidbookSettings->tagcommander_id; if (!$this->fluidbookSettings->tagcommander_prod) { $id .= '/uat'; diff --git a/app/Models/FluidbookPublication.php b/app/Models/FluidbookPublication.php index 6ee9e0e2f..b6015af20 100644 --- a/app/Models/FluidbookPublication.php +++ b/app/Models/FluidbookPublication.php @@ -279,7 +279,7 @@ class FluidbookPublication extends ToolboxSettingsModel return $this->getDocumentSize($page)[1]; } - public function getFinalPath($theme = null) + public function getFinalPath($theme = null, $version = 'online') { $dir = $this->id; if (null === $theme || ($theme instanceof FluidbookTheme && $theme->id != $this->theme)) { @@ -290,7 +290,7 @@ class FluidbookPublication extends ToolboxSettingsModel $dir .= $theme->id; } } - return protected_path('fluidbookpublication/final/' . $dir); + return protected_path('fluidbookpublication/final/' . $dir . '/' . $version); } public function getAssetDir() -- 2.39.5