From fba1e668eaa49570cd846ebddbc42a7e09f00cba Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 19 Aug 2022 18:47:54 +0200 Subject: [PATCH] wip #5399 @3 --- app/Console/Commands/FluidbookCompile.php | 9 ++- .../FluidbookPublication/PreviewOperation.php | 34 ++++----- app/Jobs/FluidbookCompiler.php | 71 +++++++++++++++---- app/Models/FluidbookTheme.php | 1 - 4 files changed, 82 insertions(+), 33 deletions(-) diff --git a/app/Console/Commands/FluidbookCompile.php b/app/Console/Commands/FluidbookCompile.php index 9889c648c..18d161227 100644 --- a/app/Console/Commands/FluidbookCompile.php +++ b/app/Console/Commands/FluidbookCompile.php @@ -12,11 +12,14 @@ class FluidbookCompile extends CubistCommand protected $signature = 'fluidbook:compile {id}'; protected $description = 'Compile a fluidbook'; + /** + * @throws \Exception + */ public function handle() { PHP::neverStop(true); - FluidbookCompiler::dispatchSync( - FluidbookPublication::find($this->argument('id')) - ); + $fluidbook = FluidbookPublication::find($this->argument('id')); + $compiler = new FluidbookCompiler($fluidbook, command: $this); + $compiler->handle(); } } diff --git a/app/Http/Controllers/Admin/Operations/FluidbookPublication/PreviewOperation.php b/app/Http/Controllers/Admin/Operations/FluidbookPublication/PreviewOperation.php index 73b2d1608..4f8426dd7 100644 --- a/app/Http/Controllers/Admin/Operations/FluidbookPublication/PreviewOperation.php +++ b/app/Http/Controllers/Admin/Operations/FluidbookPublication/PreviewOperation.php @@ -10,23 +10,23 @@ trait PreviewOperation { protected function setupPreviewRoutes($segment, $routeName, $controller) { - // Redirect to the url with a timestamp to prevent cache - Route::match(['get'], $segment . '/preview/{id}_{hash}', function ($id, $hash) use ($segment) { - return redirect(backpack_url($segment . '/preview/' . $id . '_' . $hash . '_' . time())); - })->whereNumber('id') - ->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) { - // If timestamp is too old, redirect to a more recent one - if ($path === 'index.html' && (time() - $time) > 30) { - return redirect(backpack_url($segment . '/preview/' . $id . '_' . $hash . '_' . time() . '/')); - } - return $this->preview($id, $hash, $path); - })->whereNumber('id') - ->where('hash', '[0-9a-f]{32}') - ->where('path', '.*') - ->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 redirect(backpack_url($segment . '/preview/' . $id . '_' . $hash . '_' . time())); +// })->whereNumber('id') +// ->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) { +// // If timestamp is too old, redirect to a more recent one +// if ($path === 'index.html' && (time() - $time) > 30) { +// return redirect(backpack_url($segment . '/preview/' . $id . '_' . $hash . '_' . time() . '/')); +// } +// return $this->preview($id, $hash, $path); +// })->whereNumber('id') +// ->where('hash', '[0-9a-f]{32}') +// ->where('path', '.*') +// ->withoutMiddleware([CheckIfAdmin::class]); } protected function setupPreviewDefaults() diff --git a/app/Jobs/FluidbookCompiler.php b/app/Jobs/FluidbookCompiler.php index 8da4b638a..5a8470c68 100644 --- a/app/Jobs/FluidbookCompiler.php +++ b/app/Jobs/FluidbookCompiler.php @@ -17,6 +17,7 @@ use Cubist\Util\Url; use DOMDocument; use DOMElement; use DOMXPath; +use Illuminate\Console\Command; use SimpleXMLElement; class FluidbookCompiler extends Base @@ -239,12 +240,32 @@ class FluidbookCompiler extends Base */ public $themeSettings; + /** + * @var Command + */ + protected $_command = null; + + /** + * @param FluidbookPublication $book + * @param $version + * @param $phonegap + * @param $phonegapVersion + * @param $dir + * @param $standalone + * @param $appcache + * @param $home + * @param $forceTheme + * @param $hybrid + * @param Command|null $command + * @throws \Exception + */ - function __construct(FluidbookPublication $book, $version = 'stable', $phonegap = false, $phonegapVersion = 'latest', $dir = null, $standalone = false, $appcache = false, $home = false, $forceTheme = false, $hybrid = false) + function __construct(FluidbookPublication $book, $version = 'stable', $phonegap = false, $phonegapVersion = 'latest', $dir = null, $standalone = false, $appcache = false, $home = false, $forceTheme = false, $hybrid = false, Command $command = null) { parent::__construct(); $this->setFluidbook($book); + $this->setCommand($command); $this->phonegapVersion = self::getPhonegapVersion($phonegapVersion); $this->appcache = $appcache; @@ -367,6 +388,22 @@ class FluidbookCompiler extends Base $this->_fluidbook = $fluidbook; } + /** + * @return Command|null + */ + public function getCommand(): ?Command + { + return $this->_command; + } + + /** + * @param Command|null $command + */ + public function setCommand(?Command $command): void + { + $this->_command = $command; + } + public function isMobileFirst() { return $this->fluidbookSettings->mobileNavigationType === 'mobilefirst'; @@ -892,19 +929,26 @@ class FluidbookCompiler extends Base $this->addJsLib('cart', 'js/libs/fluidbook/fluidbook.cart.js'); switch ($this->config->basketManager) { case 'Thiriet': - return $this->writeThirietCart(); + $this->writeThirietCart(); + return; case 'Flexipan': - return $this->writeFlexipanCart(); + $this->writeFlexipanCart(); + return; case 'Puma': - return $this->writePumaCart(); + $this->writePumaCart(); + return; case 'MIF': - return $this->writeMIFCart(); + $this->writeMIFCart(); + return; case 'GrandVision': - return $this->writeGrandVisionCart(); + $this->writeGrandVisionCart(); + return; case 'GrandPavois': - return $this->writeGrandPavoisCart(); + $this->writeGrandPavoisCart(); + return; case 'JoueclubWishlist2021': - return $this->writeJoueClub2021Cart(); + $this->writeJoueClub2021Cart(); + return; case 'Remarkable': $this->addJsLib('parsley', 'js/libs/parsley.min.js'); $this->addJsLib('cookie', 'js/libs/jquery/jquery.cookie.js'); @@ -937,8 +981,7 @@ class FluidbookCompiler extends Base $referencesFile = $this->wdir . '/commerce/' . $this->config->product_zoom_references; } if (file_exists($referencesFile) || Url::isDistant($referencesFile)) { - $function = 'excelToArrayKeyValMulti'; - $this->config->product_zoom_references = wsUtil::$function($referencesFile, 'Excel2007', true); + $this->config->product_zoom_references = wsUtil::excelToArrayKeyValMulti($referencesFile, 'Excel2007', true); } } @@ -982,6 +1025,8 @@ class FluidbookCompiler extends Base public function log($step) { + + $currenttime = microtime(true); if (null === $this->logfp) { $this->logfp = fopen('/var/log/extranet/htmlconversions/' . $this->book_id . '.log', 'w+'); @@ -994,6 +1039,10 @@ class FluidbookCompiler extends Base fwrite($this->logfp, $log); fflush($this->logfp); $this->logtime = $currenttime; + + if (null !== $this->getCommand()) { + $this->getCommand()->info(trim($log)); + } } public function addFacebookSDK() @@ -1069,8 +1118,6 @@ class FluidbookCompiler extends Base public function handle() { - return; - $this->log('Start compile process'); // Raw copy of some directories diff --git a/app/Models/FluidbookTheme.php b/app/Models/FluidbookTheme.php index 37b4e9be8..17fcdcb39 100644 --- a/app/Models/FluidbookTheme.php +++ b/app/Models/FluidbookTheme.php @@ -628,7 +628,6 @@ class FluidbookTheme extends ToolboxSettingsModel $this->addMediaToField($fieldname, $path, true); } - public static function _colorToWS3($data) { $data = trim($data); -- 2.39.5