From 7c4a321b360a59615615dc1ac759de709ad1e37f Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Mon, 28 Nov 2016 12:24:56 +0000 Subject: [PATCH] done #928 @1 --- inc/commons/class.common.core.php | 4 ++++ inc/ws/Controlleur/class.ws.maintenance.php | 17 +++++++++++++++++ inc/ws/DAO/class.ws.dao.book.php | 20 +++++++++++++++++--- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/inc/commons/class.common.core.php b/inc/commons/class.common.core.php index bd9bef979..badefc77e 100644 --- a/inc/commons/class.common.core.php +++ b/inc/commons/class.common.core.php @@ -438,6 +438,10 @@ class commonCore extends cubeCore { $db->book_short_url->index('index_book_short_url_long_url', 'BTREE', 'long_url'); $db->book_short_url->index('index_book_short_url_book_id', 'BTREE', 'book_id'); // . + // Books + $db->books_chapters_versions->book_id('integer', 0, false); + $db->books_chapters_versions->time('integer', 0, false); + $db->books_chapters_versions->chapters('text', 0, false); // Table des collections de fluidbooks $db->book_collection->collection_id('integer', 0, false); $db->book_collection->nom('varchar', 64, false); diff --git a/inc/ws/Controlleur/class.ws.maintenance.php b/inc/ws/Controlleur/class.ws.maintenance.php index 625db5717..d12407c0b 100644 --- a/inc/ws/Controlleur/class.ws.maintenance.php +++ b/inc/ws/Controlleur/class.ws.maintenance.php @@ -938,6 +938,22 @@ class wsMaintenance { `gzip /home/extranet/www/fluidbook/docs/*/*.txt`; } + + public static function restoreChapters($args) { + global $core; + + $book_id = $args[0]; + $r = $core->con->select('SELECT chapters FROM books_chapters_versions WHERE book_id=\'' . $core->con->escape($book_id) . '\' ORDER BY `time` DESC LIMIT 1'); + while ($r->fetch()) { + $c = $core->con->openCursor('books'); + $c->chapters = $r->chapters; + $c->changedate = TIME; + $c->update('WHERE book_id=\'' . $core->con->escape($book_id) . '\''); + break; + } + echo $r->chapters; + } + public static function offsetLinksPos($args) { global $core; $book_id = $args[0]; @@ -1111,4 +1127,5 @@ class wsMaintenance { echo '
OK
'; } + } diff --git a/inc/ws/DAO/class.ws.dao.book.php b/inc/ws/DAO/class.ws.dao.book.php index 557d8f9e2..f4e6cbf6a 100644 --- a/inc/ws/DAO/class.ws.dao.book.php +++ b/inc/ws/DAO/class.ws.dao.book.php @@ -527,10 +527,25 @@ class wsDAOBook extends commonDAO { $res[] = $c; } + $json_chapters = json_encode($res); + $c = $this->con->openCursor('books'); - $c->chapters = json_encode($res); + $c->chapters = $json_chapters; $c->changedate = TIME; $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); + + if ($json_chapters && $json_chapters != '[]') { + if(count($res)==1){ + if($res[0]['label']=='' && $res[0]['page']==''){ + return; + } + } + $c = $this->con->openCursor('books_chapters_versions'); + $c->book_id = $book_id; + $c->chapters = $json_chapters; + $c->time = TIME; + $c->insert(); + } } public function setSpecialLinksAndRulers($book_id, $links, $rulers) { @@ -1484,14 +1499,13 @@ class wsDAOBook extends commonDAO { } - public static function getWorkingFile($path, $book_id, $dir = "") { if (substr($path, 0, 1) == '/' && file_exists($path)) { return $path; } $workingDir = WS_BOOKS . '/working/' . $book_id . '/'; - return $workingDir . trim($dir,'/') . '/' . $path; + return $workingDir . trim($dir, '/') . '/' . $path; } public function compileWidget($book, $pages) { -- 2.39.5