From bc5a116dcb544df2418e8d11e53e657d352d9254 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Thu, 11 Jun 2020 17:51:41 +0000 Subject: [PATCH] wip #3667 @6 --- inc/ws/Controlleur/class.ws.maintenance.php | 227 +++++++++--------- inc/ws/DAO/class.ws.dao.book.php | 15 +- inc/ws/DAO/class.ws.dao.document.php | 3 + inc/ws/Metier/class.ws.document.php | 15 +- inc/ws/Util/class.ws.pdf.convert.php | 4 +- inc/ws/Util/class.ws.util.php | 5 + .../html5/master/class.ws.html5.compiler.php | 3 +- .../html5/master/class.ws.html5.links.php | 10 +- 8 files changed, 158 insertions(+), 124 deletions(-) diff --git a/inc/ws/Controlleur/class.ws.maintenance.php b/inc/ws/Controlleur/class.ws.maintenance.php index 5a0d93621..af9c93966 100644 --- a/inc/ws/Controlleur/class.ws.maintenance.php +++ b/inc/ws/Controlleur/class.ws.maintenance.php @@ -540,74 +540,8 @@ class wsMaintenance { global $core; cubePHP::neverStop(); -// $r = $core->con->select('SELECT document_id FROM documents WHERE document_id NOT IN (SELECT document_id FROM book_pages)'); -// while ($r->fetch()) { -// if (file_exists(WS_DOCS . '/' . $r->document_id)) { -// $rm = new cubeCommandLine('rm'); -// $rm->setPath(CONVERTER_PATH); -// $rm->setArg('r'); -// $rm->setArg('f'); -// $rm->setArg(null, WS_DOCS . '/' . $r->document_id . '/'); -// $rm->execute(); -// echo $rm->commande . "
"; -// } -// } - -// self::_moveDocs(WS_DOCS, '/data/extranet/www/fluidbook/docs1', 150); -// self::_moveDocs('/data/extranet/www/fluidbook/docs1', '/data/extranet/www/fluidbook/docs2', 500); -// self::_moveDocs('/data/extranet/www/fluidbook/docs2', '/data/extranet/www/fluidbook/docs3', 100000); } - protected static function _moveDocs($from, $to, $keep, $batch = 250) - { - $docs = array(); - $dr = opendir($from); - while ($d = readdir($dr)) { - if ($d == '.' || $d == '..') { - continue; - } - $d = intval($d); - if (!$d) { - continue; - } - $docs[] = intval($d); - } - - sort($docs); - $docs = array_splice($docs, 0, count($docs) - $keep); - if (count($docs)) { - $toMove = array_slice($docs, 0, $batch); - - foreach ($toMove as $d) { - if (trim($d) == '') { - continue; - } - $source = $from . '/' . $d . '/'; - $dest = $to . '/' . $d . '/'; - if (!file_exists($dest)) { - mkdir($dest, 0777, true); - } - $rsync = "rsync -av $source $dest"; - $rm = "rm -rf $source"; - `$rsync;$rm`; - echo $rsync . "\n"; - echo $rm . "\n"; - } - } - } - - public static function moveFluidbookDatas() - { - $dir = WS_BOOKS . '/final/'; - $dr = opendir($dir); - while ($d = readdir($dr)) { - if ($d == '.' || $d == '..' || !is_dir($dir . $d)) { - continue; - } - rename($dir . $d . '/FluidbookDatas.swf', $dir . $d . '/data/fd.swf'); - rename($dir . $d . '/FluidbookDatasLight.swf', $dir . $d . '/data/fdl.swf'); - } - } public static function mergeEntreprise($args) { @@ -625,49 +559,6 @@ class wsMaintenance $core->refreshWSUsersTree(); } - public static function updateLuceneTime() - { - global $core; - $dao = new wsDAOBook($core->con); - $books = $dao->selectLuceneTimeNotSet(); - foreach ($books as $book) { - $index = WS_BOOKS . '/search/' . $book->book_id; - if (!file_exists($index)) { - fb($book->book_id, 'Skip'); - continue; - } - - $mtime = 0; - $dr = opendir($index); - while ($file = readdir($dr)) { - if ($file == '.' || $file == '..') { - continue; - } - $mtime = max($mtime, filemtime($index . '/' . $file)); - } - - $c = $core->con->openCursor('books'); - $c->lucene_time = $mtime; - $c->update('WHERE book_id=' . $book->book_id); - - fb($book->book_id, 'Update : ' . $mtime); - } - } - - public static function makeLuceneIndexes() - { - global $core; - - cubePHP::neverStop(); - - $dao = new wsDAOBook($core->con); - $books = $dao->selectLuceneToDo(); - foreach ($books as $book) { - $pages = $dao->getPagesOfBook($book->book_id); - $dao->indexPDF($book, $pages); - } - } - public static function exportSommaire($args) { global $core; @@ -767,7 +658,7 @@ class wsMaintenance $r = $core->con->select('SELECT * FROM book_pages_versions WHERE book_id=\'' . $core->con->escape($book_id) . '\' AND composition!=\'a:0:{}\' AND `update`<=' . $date . ' ORDER BY `update` DESC LIMIT 1'); if (!$r->count()) { - return; + return false; } $comp = unserialize($r->composition); @@ -780,6 +671,18 @@ class wsMaintenance $c->document_page = $infos['document_page']; $c->insert(); } + + $daoBook = new wsDAOBook($core->con); + $book = $daoBook->selectById($book_id); + $parametres = $book->parametres; + $parametres->pages = count($comp); + + $c = $core->con->openCursor('books'); + $c->parametres = serialize($parametres); + $c->changedate = TIME; + $c->update('WHERE book_id=\'' . $core->con->escape($book_id) . '\''); + + return true; } public static function getV1Translations() @@ -1661,6 +1564,110 @@ class wsMaintenance $exporter->export($id, $x, 'install_hosting', 'online', "/airtahitiexport/" . $id, ''); } } + + public static function restoreAllCompositions() + { + global $core; + $dao = new wsDAOBook($core->con); + $books = $dao->selectAll(); + foreach ($books as $book) { + if (!$book->parametres->pages) { + self::restoreComposition([$book->book_id]); + echo 'restored ' . $book->book_id . '
'; + } + } + } + + public static function fixMissingDocs() + { + global $core; + $r = $core->con->select('SELECT DISTINCT `document_id`,`book_id` FROM `book_pages`'); + $fixed = []; + $unfixed = []; + while ($r->fetch()) { + if (file_exists(WS_DOCS . '/' . $r->document_id . '/original.pdf')) { + continue; + } + if (!isset($fixed[$r->book_id]) && !isset($unfixed[$r->book_id])) { + if (self::fixMissing([$r->book_id])) { + $fixed[$r->book_id] = true; + } else { + $unfixed[$r->book_id] = true; + continue; + } + } + break; + } + + echo 'fixed : ' . print_r($fixed, true) . "
"; + echo 'unfixed : ' . print_r($unfixed, true) . "
"; + } + + protected static function fixMissing($args) + { + global $core; + + $book_id = $args[0]; + + $places = [ + WS_BOOKS . '/pdf/' . $book_id . '/original.pdf', + WS_BOOKS . '/pdf/' . $book_id . '/normal.pdf', + WS_BOOKS . '/final/' . $book_id . '/data/document.pdf', + WS_BOOKS . '/html5/' . $book_id . '/data/document.pdf', + ]; + + $ok = false; + foreach ($places as $place) { + if (!file_exists($place) || filesize($place) === 0) { + continue; + } + $ok = true; + break; + } + + if (!$ok) { + echo 'backup pdf not found'; + return false; + } + + + set_time_limit(0); + ignore_user_abort(true); + + $daoBook = new wsDAOBook($core->con); + /** @var wsBook $book */ + $dao = new wsDAODocument($core->con); + + // Create a new doc + $data = array(); + $data['proprietaire'] = $core->user->utilisateur_id; + $data['pages'] = 0; + $data['version'] = 2; + $data['file'] = cubeFiles::tidyName('original.pdf'); + $li = new wsDocumentLocalInfos(); + $li->fileName = 'original.pdf'; + $li->fileSize = filesize($place); + $li->creationDate = filemtime($place); + $li->modificationDate = filemtime($place); + $data['localInfos'] = $li; + $data['conversionInfos'] = new wsDocumentConversionInfos(); + $document = $dao->sauve($data); + $document->copyOriginalFromFile($place); + $document->globalOperations(); + $document->processAllPages(); + $dao->updateFromObject($document); + + $n = $document->getPagesNumber(); + $did = $document->document_id; + $pages = []; + for ($i = 1; $i <= $n; $i++) { + $p = new stdClass(); + $p->document_id = $did; + $p->document_page = $i; + $pages[$i] = $p; + } + $daoBook->setComposition($book_id, $pages, false); + } } diff --git a/inc/ws/DAO/class.ws.dao.book.php b/inc/ws/DAO/class.ws.dao.book.php index 2292a2276..426baa213 100644 --- a/inc/ws/DAO/class.ws.dao.book.php +++ b/inc/ws/DAO/class.ws.dao.book.php @@ -142,7 +142,8 @@ class wsDAOBook extends commonDAO return $res; } - public function selectAll(){ + public function selectAll() + { $table = 'books_vue'; $sql = 'SELECT * FROM ' . $table; $r = $this->con->select($sql); @@ -874,12 +875,14 @@ class wsDAOBook extends commonDAO return true; } - public function setComposition($book_id, $pages) + public function setComposition($book_id, $pages, $setNumerotation = true) { $numerotation = array(); $nb_pages = 0; foreach ($pages as $p) { - $numerotation[] = $p->virtual; + if($setNumerotation) { + $numerotation[] = $p->virtual; + } $nb_pages++; } @@ -889,7 +892,9 @@ class wsDAOBook extends commonDAO $c = $this->con->openCursor('books'); $c->parametres = serialize($parametres); - $c->numerotation = implode(',', $numerotation); + if($setNumerotation) { + $c->numerotation = implode(',', $numerotation); + } $c->changedate = TIME; // Check if composition need to be updated @@ -1283,7 +1288,7 @@ class wsDAOBook extends commonDAO public function copy($source, $dest) { - if(!file_exists($source)){ + if (!file_exists($source)) { return; } copy($source, $dest); diff --git a/inc/ws/DAO/class.ws.dao.document.php b/inc/ws/DAO/class.ws.dao.document.php index 355a4e8e6..8139da5e8 100644 --- a/inc/ws/DAO/class.ws.dao.document.php +++ b/inc/ws/DAO/class.ws.dao.document.php @@ -63,6 +63,9 @@ class wsDAODocument extends commonDAO return $this->factory($r); } + /** + * @return wsDocument + */ public function cree() { $document = new wsDocument(); diff --git a/inc/ws/Metier/class.ws.document.php b/inc/ws/Metier/class.ws.document.php index 38fdd394b..f4e69dc2d 100644 --- a/inc/ws/Metier/class.ws.document.php +++ b/inc/ws/Metier/class.ws.document.php @@ -102,6 +102,11 @@ class wsDocument extends cubeMetier move_uploaded_file($tmp_file, $this->in); } + public function copyOriginalFromFile($file) + { + copy($file, $this->in); + } + public function copyOriginalFromOlderVersion() { if (!file_exists($this->in)) { @@ -668,7 +673,7 @@ class wsDocument extends cubeMetier $this->makeShotPNM($page, 'html/h' . $r . '-', $r * $rratio, $q, 4, null, false); $this->makeShotPNM($page, 'html/t' . $r . '-', $r * $rratio, $q); } - $this->makeSVGFile($page); + $this->makeSVGFile($page, false); } public function makeMobileFirstFiles($page) @@ -682,9 +687,12 @@ class wsDocument extends cubeMetier } } - public function makeSVGFile($page) + public function makeSVGFile($page, $force = true) { $svgFile = $this->out . '/html/fp' . $page . '.svg'; + if (!$force && file_exists($svgFile) && filesize($svgFile) > 0) { + return; + } $pdftocairo = new cubeCommandLine('pdftocairo'); $pdftocairo->setPath(CONVERTER_PATH); @@ -868,8 +876,9 @@ class wsDocument extends cubeMetier $program = 'pdf2swf'; } - $pdf2swf = new cubeCommandLine($program, null, true); + $pdf2swf = new CubeIT_CommandLine($program, null, true); $pdf2swf->setPath(CONVERTER_PATH); + $pdf2swf->setTimeout(120); $pdf2swf->setArg('p', 1); $flashversion = 10; diff --git a/inc/ws/Util/class.ws.pdf.convert.php b/inc/ws/Util/class.ws.pdf.convert.php index 1c22e933c..aa7ed7c4b 100644 --- a/inc/ws/Util/class.ws.pdf.convert.php +++ b/inc/ws/Util/class.ws.pdf.convert.php @@ -43,7 +43,7 @@ class wsPDFConvert { } } - protected function makeShotGS($in, $out, $page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $width = null, $height = null) { + protected static function makeShotGS($in, $out, $page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $width = null, $height = null) { // Fabrication des thumbanails avec ghostscript $gs = new cubeCommandLine('gs', null, true); @@ -77,7 +77,7 @@ class wsPDFConvert { $gs->execute(); } - protected function makeShotPNM($in, $out, $page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $texts = true, $width = null, $height = null) { + protected static function makeShotPNM($in, $out, $page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $texts = true, $width = null, $height = null) { $tmp = cubeFiles::tempnam(); $antialiasing = $antialiasing ? 'yes' : 'no'; diff --git a/inc/ws/Util/class.ws.util.php b/inc/ws/Util/class.ws.util.php index 63873f17d..c0d8b5b37 100644 --- a/inc/ws/Util/class.ws.util.php +++ b/inc/ws/Util/class.ws.util.php @@ -203,6 +203,11 @@ class wsUtil if ($invalid) { + + if (file_exists($originalPDF)) { + self::copy($originalPDF, $cacheDir . '/original.' . TIME . '.pdf'); + } + $pdfList = array(); $pagesList = array(); $nb_pages = array(); diff --git a/inc/ws/Util/html5/master/class.ws.html5.compiler.php b/inc/ws/Util/html5/master/class.ws.html5.compiler.php index 2503360cc..2c1881e33 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -1622,7 +1622,8 @@ class wsHTML5Compiler protected function writeConfig() { - return 'var SETTINGS=' . json_encode($this->config) . ';' . "\n"; + $c = json_encode($this->config); + return 'var SETTINGS=' . $c . ';' . "\n"; } protected function writeCountries() diff --git a/inc/ws/Util/html5/master/class.ws.html5.links.php b/inc/ws/Util/html5/master/class.ws.html5.links.php index 66044c464..f85517cf4 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.links.php +++ b/inc/ws/Util/html5/master/class.ws.html5.links.php @@ -1378,12 +1378,16 @@ class htmlMultimediaLink extends wsHTML5Link $this->compiler->htmlmultimedia[] = $i; } - foreach ($this->_config['injectcss'] as $i) { + if (isset($this->_config['injectcss'])) { + foreach ($this->_config['injectcss'] as $i) { + } } - foreach ($this->_config['injectjs'] as $i) { - $this->compiler->pluginJs[] = $d['fdir'] . '/' . $i; + if (isset($this->_config['injectjs'])) { + foreach ($this->_config['injectjs'] as $i) { + $this->compiler->pluginJs[] = $d['fdir'] . '/' . $i; + } } -- 2.39.5