]> _ Git - fluidbook-toolbox.git/commitdiff
wait #6667 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 23 Jan 2024 18:15:07 +0000 (19:15 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 23 Jan 2024 18:15:07 +0000 (19:15 +0100)
app/Fluidbook/Compiler/Compiler.php

index e74533751d6b6062fdda80352c2a2264e02a0cf4..a870f5a333019fac3063a865dcd5e1cd4d230861 100644 (file)
@@ -34,6 +34,7 @@ use DOMElement;
 use DOMXPath;
 use Fluidbook\Tools\Compiler\CompilerInterface;
 use Fluidbook\Tools\SVG\SVGTools;
+use Illuminate\Cache\Lock;
 use Illuminate\Console\Command;
 use SplFileInfo;
 
@@ -50,6 +51,9 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError
     use Search;
     use Accessibility;
 
+    /** @var Lock */
+    protected $lock;
+
     protected static $uaPrefixes = array('-moz-', '-webkit-', '-o-', '-ms-', '');
 
     /**
@@ -288,6 +292,9 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError
         parent::__construct();
 
         $this->setFluidbook($book);
+        $this->book_id = $this->getFluidbook()->id;
+
+
         $this->setCommand($command);
 
         $this->phonegapVersion = self::getPhonegapVersion($phonegapVersion);
@@ -310,7 +317,7 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError
 
         PHP::memoryAllocate('12G');
 
-        $this->book_id = $this->getFluidbook()->id;
+
         $this->log('Start compilation');
 
         $this->dir = $this->getFluidbook()->getFinalPath($theme, $scormVariant);
@@ -703,79 +710,87 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError
 
     public function handle()
     {
-        if (!$this->compositionCached()) {
-            $this->log('Preprocess images');
-            (new FluidbookImagesPreprocess($this->book_id))->handle();
-        }
-        $this->log('Start compile process');
-
-        // Raw copy of some directories
-        $directories = array('style/fonts/OpenSans', 'images', 'sound');
-        foreach ($directories as $directory) {
-            $from = $this->assets . '/' . $directory;
-            $this->vdir->copyDirectory($from, $directory);
-        }
-
-        if ($this->fluidbookSettings->scorm_enable || $this->fluidbookSettings->secureClientSidePassword) {
-            $this->fluidbookSettings->seoVersion = false;
-        }
-        if ($this->fluidbookSettings->embedAllLibraries) {
-            $this->addVideoJs();
-            $this->addSlideshowLibrary(false);
-            $this->addSlideshowLibrary(true);
-        }
-
-        $this->log('Copied assets');
-        $this->writeSecure();
-        $this->loadPlugins();
-        $this->log('Plugins loaded');
-        $this->writeImages();
-        $this->log('Images written');
-        $this->writeCartConfig();
-        $this->log('Cart written');
-        $this->writeXMLArticles();
-        $this->log('XML Articles written');
-        $this->writeSlider();
-        $this->log('Slider written');
-        $linksCSS = $this->writeLinks();
-        $this->log('Links written');
-        $this->writeArticles();
-        $this->log('Articles written');
-        $this->writeStats();
-        $this->log('Stats written');
-        $this->writeLangs();
-        $this->log('Langs written');
-        $this->writeSEO();
-        $this->log('SEO written');
-        $this->writeSounds();
-        $this->writeAmbientSound();
-        $this->log('Sound written');
-        $this->writeSearch();
-        $this->log('Search written');
-        $this->writeAccessibility();
-        $this->log('Accessibility written');
-        $this->writeExtras();
-        $this->log('Extras written');
-        $this->populateConfig();
-        $this->log('Config populated');
-        $this->writeCSS($linksCSS);
-        $this->log('CSS written');
-        $this->writeIndex();
-        $this->log('Index written');
-        if ($this->fluidbookSettings->scorm_enable) {
-            $this->writeScorm();
-            $this->log('SCORM written');
-        }
-        $this->writeJs();
-        $this->log('Js written');
-        $this->vdir->sync(true, $this);
-        `chmod -R 775 $this->dir`;
-        $this->log('Files Synced');
+        $this->lock = \Illuminate\Support\Facades\Cache::lock('fluidbook_compile_' . $this->book_id, 1800);
+        if ($this->lock->get()) {
+            try {
+                if (!$this->compositionCached()) {
+                    $this->log('Preprocess images');
+                    (new FluidbookImagesPreprocess($this->book_id))->handle();
+                }
+                $this->log('Start compile process');
+
+                // Raw copy of some directories
+                $directories = array('style/fonts/OpenSans', 'images', 'sound');
+                foreach ($directories as $directory) {
+                    $from = $this->assets . '/' . $directory;
+                    $this->vdir->copyDirectory($from, $directory);
+                }
+
+                if ($this->fluidbookSettings->scorm_enable || $this->fluidbookSettings->secureClientSidePassword) {
+                    $this->fluidbookSettings->seoVersion = false;
+                }
+                if ($this->fluidbookSettings->embedAllLibraries) {
+                    $this->addVideoJs();
+                    $this->addSlideshowLibrary(false);
+                    $this->addSlideshowLibrary(true);
+                }
+
+                $this->log('Copied assets');
+                $this->writeSecure();
+                $this->loadPlugins();
+                $this->log('Plugins loaded');
+                $this->writeImages();
+                $this->log('Images written');
+                $this->writeCartConfig();
+                $this->log('Cart written');
+                $this->writeXMLArticles();
+                $this->log('XML Articles written');
+                $this->writeSlider();
+                $this->log('Slider written');
+                $linksCSS = $this->writeLinks();
+                $this->log('Links written');
+                $this->writeArticles();
+                $this->log('Articles written');
+                $this->writeStats();
+                $this->log('Stats written');
+                $this->writeLangs();
+                $this->log('Langs written');
+                $this->writeSEO();
+                $this->log('SEO written');
+                $this->writeSounds();
+                $this->writeAmbientSound();
+                $this->log('Sound written');
+                $this->writeSearch();
+                $this->log('Search written');
+                $this->writeAccessibility();
+                $this->log('Accessibility written');
+                $this->writeExtras();
+                $this->log('Extras written');
+                $this->populateConfig();
+                $this->log('Config populated');
+                $this->writeCSS($linksCSS);
+                $this->log('CSS written');
+                $this->writeIndex();
+                $this->log('Index written');
+                if ($this->fluidbookSettings->scorm_enable) {
+                    $this->writeScorm();
+                    $this->log('SCORM written');
+                }
+                $this->writeJs();
+                $this->log('Js written');
+                $this->vdir->sync(true, $this);
+                `chmod -R 775 $this->dir`;
+                $this->log('Files Synced');
 //        $f=rtrim(str_replace('/html5/', '/compiletime/', $this->dir));
 //        touch($f);
 
-        $this->setCompiledCacheDate();
-        cache()->forget('fluidbook_auditing_' . $this->book_id);
+                $this->setCompiledCacheDate();
+                cache()->forget('fluidbook_auditing_' . $this->book_id);
+            } finally {
+                $this->lock?->release();
+            }
+
+        }
     }
 
     protected function writeSlider()
@@ -2371,7 +2386,11 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError
 
     public function __destruct()
     {
+        try {
+            $this->lock->release();
+        } catch (\Exception $e) {
 
+        }
     }
 
     public function unzipFile($file, $moveAssets = false, $baseDir = null, $junkPaths = false)