]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5399 @3
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 19 Aug 2022 16:47:54 +0000 (18:47 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 19 Aug 2022 16:47:54 +0000 (18:47 +0200)
app/Console/Commands/FluidbookCompile.php
app/Http/Controllers/Admin/Operations/FluidbookPublication/PreviewOperation.php
app/Jobs/FluidbookCompiler.php
app/Models/FluidbookTheme.php

index 9889c648c94b2947b12cf3e2bd84340f5ac94482..18d161227517f9ece7809c67e6c91b36282bfac9 100644 (file)
@@ -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();
     }
 }
index 73b2d160863d71c9a7d0f8490b7a2237c938d745..4f8426dd79ef5eeed6a27f0a5ab2da6420739035 100644 (file)
@@ -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()
index 8da4b638a5307a30bb7299b94bd54ad857470322..5a8470c68ae3c2a414482595d109fa1011c0a874 100644 (file)
@@ -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
index 37b4e9be894da47e6ced6ecc73a996624362693d..17fcdcb39686a07275a83c98cbb0e35e9bf15f7b 100644 (file)
@@ -628,7 +628,6 @@ class FluidbookTheme extends ToolboxSettingsModel
         $this->addMediaToField($fieldname, $path, true);
     }
 
-
     public static function _colorToWS3($data)
     {
         $data = trim($data);