use DOMXPath;
use Fluidbook\Tools\Compiler\CompilerInterface;
use Fluidbook\Tools\SVG\SVGTools;
+use Illuminate\Cache\Lock;
use Illuminate\Console\Command;
use SplFileInfo;
use Search;
use Accessibility;
+ /** @var Lock */
+ protected $lock;
+
protected static $uaPrefixes = array('-moz-', '-webkit-', '-o-', '-ms-', '');
/**
parent::__construct();
$this->setFluidbook($book);
+ $this->book_id = $this->getFluidbook()->id;
+
+
$this->setCommand($command);
$this->phonegapVersion = self::getPhonegapVersion($phonegapVersion);
PHP::memoryAllocate('12G');
- $this->book_id = $this->getFluidbook()->id;
+
$this->log('Start compilation');
$this->dir = $this->getFluidbook()->getFinalPath($theme, $scormVariant);
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()
public function __destruct()
{
+ try {
+ $this->lock->release();
+ } catch (\Exception $e) {
+ }
}
public function unzipFile($file, $moveAssets = false, $baseDir = null, $junkPaths = false)