From 601061b2fe22b967d0302a7919580086e724ec39 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Mon, 26 Dec 2011 12:41:48 +0000 Subject: [PATCH] --- inc/commons/class.common.core.php | 1 + inc/ws/Controlleur/class.ws.maintenance.php | 41 ++++++++++++ inc/ws/DAO/class.ws.dao.book.php | 63 ++++++++++++++----- inc/ws/Util/html5/class.ws.html5.compiler.php | 4 +- 4 files changed, 92 insertions(+), 17 deletions(-) diff --git a/inc/commons/class.common.core.php b/inc/commons/class.common.core.php index b201fc487..e1890bb8d 100644 --- a/inc/commons/class.common.core.php +++ b/inc/commons/class.common.core.php @@ -375,6 +375,7 @@ class commonCore extends cubeCore { $db->books->composition_update('integer', 0, false); $db->books->dir_references('varchar', 256, false); $db->books->dir_hosting('varchar', 256, false); + $db->books->lucene_time('integer',0,false); // Clés $db->books->primary('pk_books', 'book_id'); $db->books->index('index_books_nom', 'BTREE', 'nom'); diff --git a/inc/ws/Controlleur/class.ws.maintenance.php b/inc/ws/Controlleur/class.ws.maintenance.php index 1fd6e251c..71380f5aa 100644 --- a/inc/ws/Controlleur/class.ws.maintenance.php +++ b/inc/ws/Controlleur/class.ws.maintenance.php @@ -572,6 +572,47 @@ 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); + } + } + } ?> \ No newline at end of file diff --git a/inc/ws/DAO/class.ws.dao.book.php b/inc/ws/DAO/class.ws.dao.book.php index 22587e2e6..0d77dd91f 100644 --- a/inc/ws/DAO/class.ws.dao.book.php +++ b/inc/ws/DAO/class.ws.dao.book.php @@ -83,6 +83,18 @@ class wsDAOBook extends commonDAO { return $this->singleton($r); } + public function selectLuceneToDo() { + $sql = 'SELECT * FROM books_vue WHERE lucene_timecon->select($sql); + return $this->factory($r); + } + + public function selectLuceneTimeNotSet() { + $sql = 'SELECT * FROM books_vue WHERE lucene_time=0 AND version=2'; + $r = $this->con->select($sql); + return $this->factory($r); + } + /** * wsDAOBook::sauve() * @@ -123,7 +135,7 @@ class wsDAOBook extends commonDAO { return $this->selectById($book_id); } - public function duplicate($book_id, $createur, $nom, $pages=false) { + public function duplicate($book_id, $createur, $nom, $pages = false) { $r = $this->con->select('SELECT * FROM books_vue WHERE book_id=\'' . $this->con->escape($book_id) . '\''); $old_id = $book_id; @@ -443,7 +455,7 @@ class wsDAOBook extends commonDAO { $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); } - public function saveCompositionVersion($book_id, $time=null) { + public function saveCompositionVersion($book_id, $time = null) { $time = is_null($time) ? TIME : $time; @@ -532,7 +544,7 @@ class wsDAOBook extends commonDAO { $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); } - public function isUpToDate($book_id, $html=false) { + public function isUpToDate($book_id, $html = false) { $r = $this->con->select('SELECT changedate,compiledate FROM books WHERE book_id=\'' . $this->con->escape($book_id) . '\''); if ($r->compiledate < $r->changedate) { return false; @@ -704,17 +716,20 @@ class wsDAOBook extends commonDAO { foreach ($filesToCopy as $local => $source) { $localPath = $finalDir . $local; - // if (!file_exists($localPath) || filemtime($localPath) < filemtime($source) || filesize($localPath) != filesize($source)) { - if (is_dir($source)) { - continue; + if (!file_exists($localPath) || filemtime($localPath) < filemtime($source) || filesize($localPath) != filesize($source) || filemtime($localPath) < $book->composition_update) { + if (is_dir($source)) { + continue; + } + copy($source, $localPath); } - copy($source, $localPath); - // } } + $this->compilePDF($book, $pages); - $this->indexPDF($book, $pages); - $this->compileHTML5($book_id); + //$this->indexPDF($book, $pages); + if ($book->parametres->mobileVersion != 'pdf') { + $this->compileHTML5($book_id); + } $this->compileWidget($book, $pages); $this->touchCompile($book_id); @@ -822,7 +837,7 @@ class wsDAOBook extends commonDAO { $poster = $link['to']; $e = explode('.', $poster); array_pop($e); - array_push($e,'jpg'); + array_push($e, 'jpg'); $poster = implode('.', $e); $workingFile = $workingDir . '/' . $poster; @@ -1052,10 +1067,6 @@ class wsDAOBook extends commonDAO { public function indexPDF($book, $pages) { $indexPath = WS_BOOKS . '/search/' . $book->book_id; - if (file_exists($indexPath) && filemtime($indexPath) > $book->composition_update) { - return; - } - Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive()); if (file_exists($indexPath)) { @@ -1069,6 +1080,10 @@ class wsDAOBook extends commonDAO { $doc->addField(Zend_Search_Lucene_Field::UnStored('contents', file_get_contents(WS_DOCS . '/' . $infos['document_id'] . '/p' . $infos['document_page'] . '.txt'))); $index->addDocument($doc); } + + $c = $this->con->openCursor('books'); + $c->lucene_time = TIME; + $c->update('WHERE book_id=' . $book->book_id); } public function compilePDF($book, $pages) { @@ -1103,7 +1118,13 @@ class wsDAOBook extends commonDAO { $nb_pages = array(); $j = 0; $k = 0; + $original = true; + foreach ($pages as $i => $infos) { + if (!isset($firstDoc)) { + $firstDoc = $infos['document_id']; + } + $doc = WS_DOCS . '/' . $infos['document_id'] . '/crop.pdf'; if (!isset($pdfList[$doc])) { $pdfList[$doc] = $j; @@ -1114,7 +1135,19 @@ class wsDAOBook extends commonDAO { $k = $pdfList[$doc]; } $pagesList[$i] = array($k, $infos['document_page']); + + if ($i != $infos['document_page'] || $infos['document_id'] != $firstDoc) { + $original = false; + } + } + + if ($original) { + copy(WS_DOCS . '/' . $firstDoc . '/crop.pdf', $finalPDF); + fb('Original'); + return; } + fb('Composite'); + exit; $args = ''; foreach ($pdfList as $doc => $index) { diff --git a/inc/ws/Util/html5/class.ws.html5.compiler.php b/inc/ws/Util/html5/class.ws.html5.compiler.php index ba929d7b0..ed949aead 100644 --- a/inc/ws/Util/html5/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/class.ws.html5.compiler.php @@ -73,6 +73,8 @@ class wsHTML5Compiler { function __construct($book_id) { global $core; + + cubePHP::set_memory('4G'); if (trim($book_id) == '') { return; @@ -914,8 +916,6 @@ class wsHTML5Compiler { } $this->fontDocs[$font][$document_id] = true; - - $idx= $this->getIndex($font, $this->cssFont, array('oblique' => $oblique)); return $idx; -- 2.39.5