From 4c2a3df278260b392966f6a6b38a27b5d9d271b9 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Thu, 24 Jun 2021 15:34:42 +0000 Subject: [PATCH] wait #4554 @3 --- inc/ws/Controlleur/class.ws.services.php | 50 ++++++++++++++---------- inc/ws/Controlleur/class.ws.url.php | 2 - inc/ws/DAO/class.ws.dao.book.php | 10 +++++ 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/inc/ws/Controlleur/class.ws.services.php b/inc/ws/Controlleur/class.ws.services.php index 6515221b4..6ef003a92 100644 --- a/inc/ws/Controlleur/class.ws.services.php +++ b/inc/ws/Controlleur/class.ws.services.php @@ -183,13 +183,13 @@ class wsServices extends cubeFlashGateway } $id = $book->book_id; - $wid=$book->getAssetDir(); + $wid = $book->getAssetDir(); if (isset($this->args['image'])) { $cover = $wid . $this->args['image']; } else { if (isset($book->parametres->facebook_image) && $book->parametres->facebook_image != '') { - $c =$wid. $book->parametres->facebook_image; + $c = $wid . $book->parametres->facebook_image; if (file_exists($c)) { $cover = $c; } @@ -197,19 +197,24 @@ class wsServices extends cubeFlashGateway if (!isset($cover)) { $cover = WS_FILES . '/social_image/' . $id . '.jpg'; - $limit = TIME - (3600 * 24 * 5); + $limit = TIME - (3600 * 24 * 30); $minsize = 20 * 1024; if (isset($_GET['force']) || !file_exists($cover) || filemtime($cover) < $limit || filesize($cover) < $minsize) { - $url = 'https://workshop.fluidbook.com/viewerh/' . $id . '_' . $book->hash . '_' . TIME . '/?nointerface=1'; - if (isset($_GET['forcecompile'])) { - $url .= '&force=1'; - } - $url .= '#/page/0'; + $lock = WS_BOOKS . '/locks/' . $id . '.social_screenshot'; + if (!file_exists($lock) || filemtime($lock) < time() - 3600) { + touch($lock); + + $url = 'https://workshop.fluidbook.com/viewerh/' . $id . '_' . $book->hash . '_' . TIME . '/?nointerface=1'; + if (isset($_GET['forcecompile'])) { + $url .= '&force=1'; + } + $url .= '#/page/0'; - $w = 1200; - $h = 628; + + $w = 1200; + $h = 628; // $tmp = CubeIT_Files::tempnam() . '.svg'; // $cl = new CubeIT_CommandLine('xvfb-run'); // $cl->setArg('a'); @@ -228,16 +233,19 @@ class wsServices extends cubeFlashGateway // `convert $tmp -crop $geo+0+0 +repage -resize $geo -flatten $cover`; // unlink($tmp); - $cl = new CubeIT_CommandLine('node'); - $cl->setArg(null, WS_TOOLS . '/social_screenshot/social_screenshot.js'); - $cl->setArg('width', $w); - $cl->setArg('height', $h); - $cl->setArg('delay', 10); - $cl->setArg('scale', 0.5); - $cl->setArg('dest', $cover); - $cl->setArg('url', $url); - $cl->execute(); - $cl->debug(); + $cl = new CubeIT_CommandLine('node'); + $cl->setArg(null, WS_TOOLS . '/social_screenshot/social_screenshot.js'); + $cl->setArg('width', $w); + $cl->setArg('height', $h); + $cl->setArg('delay', 10); + $cl->setArg('scale', 0.5); + $cl->setArg('dest', $cover); + $cl->setArg('url', $url); + $cl->execute(); + $cl->debug(); + + unlink($lock); + } } } } @@ -448,7 +456,7 @@ class wsServices extends cubeFlashGateway { global $core; $mode = $force ? $force : $book->parametres->bookmarkUsePDF; - $wid=$book->getAssetDir(); + $wid = $book->getAssetDir(); switch ($mode) { case 'download': $res = $wid . $book->parametres->pdfReplace; diff --git a/inc/ws/Controlleur/class.ws.url.php b/inc/ws/Controlleur/class.ws.url.php index d3b2ea8c0..c70675b22 100644 --- a/inc/ws/Controlleur/class.ws.url.php +++ b/inc/ws/Controlleur/class.ws.url.php @@ -1250,8 +1250,6 @@ html,body{height:100%;cursor: wait;font-family: "Open Sans", Arial;background-co $r = $_SERVER['HTTP_REFERER']; } - fb($r, $id); - global $core; $rr = $core->con->select('SELECT * FROM books_referer WHERE book_id=\'' . $core->con->escape($id) . '\' AND referer=\'' . $core->con->escape($r) . '\''); $c = $core->con->openCursor('books_referer'); diff --git a/inc/ws/DAO/class.ws.dao.book.php b/inc/ws/DAO/class.ws.dao.book.php index 5cbc58506..76849c3c4 100644 --- a/inc/ws/DAO/class.ws.dao.book.php +++ b/inc/ws/DAO/class.ws.dao.book.php @@ -1195,6 +1195,14 @@ class wsDAOBook extends commonDAO return; } + $compileLock = WS_BOOKS . '/locks/' . $book_id . '.lock'; + + while (file_exists($compileLock) && filemtime($compileLock) > time() - 3600) { + sleep(10); + } + + touch($compileLock); + if (null === $book) { $book = $this->selectById($book_id); } @@ -1205,6 +1213,8 @@ class wsDAOBook extends commonDAO $res .= $this->compileHTML5($book_id, $book, $dev, $delete); $this->touchCompile($book_id, 'html5'); + unlink($compileLock); + return $res; } -- 2.39.5