From 450e4d05255bf339136ff07f8bd96c69749acb35 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Tue, 29 Jun 2021 09:55:37 +0000 Subject: [PATCH] wip #4563 @0.5 --- inc/commons/_common.php | 2 -- inc/ws/Controlleur/class.ws.maintenance.php | 5 ++++ inc/ws/DAO/class.ws.dao.book.php | 30 ++++++++++++++++----- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/inc/commons/_common.php b/inc/commons/_common.php index 063410d4c..19014e74c 100644 --- a/inc/commons/_common.php +++ b/inc/commons/_common.php @@ -17,5 +17,3 @@ $core->monitoring=true; $core->url->registerDefault(array('commonUrl', 'hub')); $core->url->register('ajax', 'ajax', '^ajax(.*)$', array('cubeAjax', 'ajax')); $core->url->register('tools', 'tools', '^tools(.*)$', array('commonTools', 'hub')); - -?> \ No newline at end of file diff --git a/inc/ws/Controlleur/class.ws.maintenance.php b/inc/ws/Controlleur/class.ws.maintenance.php index f0c2f65e1..64d48e268 100644 --- a/inc/ws/Controlleur/class.ws.maintenance.php +++ b/inc/ws/Controlleur/class.ws.maintenance.php @@ -1505,6 +1505,11 @@ class wsMaintenance exit; } + public static function clearLocks(){ + $dir=WS_BOOKS.'/locks/*'; + `rm $dir`; + } + public static function processPage($args) { CubeIT_Util_PHP::neverStop(); diff --git a/inc/ws/DAO/class.ws.dao.book.php b/inc/ws/DAO/class.ws.dao.book.php index 74bef09bd..d053c1233 100644 --- a/inc/ws/DAO/class.ws.dao.book.php +++ b/inc/ws/DAO/class.ws.dao.book.php @@ -8,6 +8,8 @@ class wsDAOBook extends commonDAO /** @var wsHTML5Compiler */ public static $lastHTML5Compiler = null; + protected $_compileLock = null; + /** * wsDAOBook::singleton() * @@ -1191,17 +1193,19 @@ class wsDAOBook extends commonDAO public function compile($book_id, $version = 'all', $complete = false, $force = false, $dev = false, $book = null, $delete = true) { + if (is_null($book_id) || !$book_id) { return; } - $compileLock = WS_BOOKS . '/locks/' . $book_id . '.lock'; + $this->_compileLock = WS_BOOKS . '/locks/' . $book_id . '.lock'; + - while (file_exists($compileLock) && filemtime($compileLock) > time() - 3600) { + while (file_exists($this->_compileLock) && filemtime($this->_compileLock) > (time() - 900)) { sleep(10); } cubePHP::neverStop(); - touch($compileLock); + touch($this->_compileLock); if (null === $book) { $book = $this->selectById($book_id); @@ -1209,11 +1213,15 @@ class wsDAOBook extends commonDAO $pages = $this->getPagesOfBook($book_id); $res = ''; - $this->compilePDF($book, $pages); - $res .= $this->compileHTML5($book_id, $book, $dev, $delete); - $this->touchCompile($book_id, 'html5'); + try { + $this->compilePDF($book, $pages); + $res .= $this->compileHTML5($book_id, $book, $dev, $delete); + $this->touchCompile($book_id, 'html5'); + } catch (Exception $e) { + + } - unlink($compileLock); + unlink($this->_compileLock); return $res; } @@ -1296,4 +1304,12 @@ class wsDAOBook extends commonDAO return $str; } + public function __destruct() + { + if (null !== $this->_compileLock && file_exists($this->_compileLock)) { + unlink($this->_compileLock); + $this->_compileLock = null; + } + } + } -- 2.39.5