From ef764b9c4b96d0131ccdfd00c807ee1c0b38979e Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Fri, 15 Apr 2011 20:02:29 +0000 Subject: [PATCH] --- inc/commons/class.common.core.php | 8 ++ inc/ws/Controlleur/class.ws.maintenance.php | 44 ++++++++ inc/ws/DAO/class.ws.dao.book.php | 2 - inc/ws/DAO/class.ws.dao.document.php | 108 +++++++++++++------- 4 files changed, 122 insertions(+), 40 deletions(-) diff --git a/inc/commons/class.common.core.php b/inc/commons/class.common.core.php index 726c31cfe..89f5f416b 100644 --- a/inc/commons/class.common.core.php +++ b/inc/commons/class.common.core.php @@ -336,6 +336,14 @@ class commonCore extends cubeCore { $db->document_links->index('index_document_links_date', 'BTREE', 'update'); $db->document_links->index('index_document_links_document_id', 'BTREE', 'document_id'); // . + // Tables versions des liens + $db->document_links_versions->document_id('integer', 0, false); + $db->document_links_versions->links('text', 0, false); + $db->document_links_versions->rulers('text', 0, false); + $db->document_links_versions->update('integer', 0, false); + // . + $db->document_links_versions->primary('pk_document_links_version', 'document_id', 'update'); + $db->document_links_versions->index('idx_document_links_version_update', 'BTREE', 'update'); // Table Books $db->books->book_id('integer', 0, false); $db->books->nom('varchar', 256, false); diff --git a/inc/ws/Controlleur/class.ws.maintenance.php b/inc/ws/Controlleur/class.ws.maintenance.php index 0ea55f72e..083a86528 100644 --- a/inc/ws/Controlleur/class.ws.maintenance.php +++ b/inc/ws/Controlleur/class.ws.maintenance.php @@ -11,6 +11,50 @@ class wsMaintenance { } } + public static function resetLinks($args) + { + global $core; + $book_id = $args[0]; + fb($book_id); + $dao = new wsDAODocument($core->con); + $dao->setLinksFromOldFluidbook($book_id); + } + + public static function moveLinksToVersionDB() + { + global $core; + $r = $core->con->select('SELECT * FROM document_links'); + $d = array(); + while ($r->fetch()) { + if (!isset($d[$r->document_id])) { + $d[$r->document_id] = array(); + } + if (!isset($d[$r->document_id][$r->update])) { + $d[$r->document_id][$r->update] = array(); + } + if (!isset($d[$r->document_id][$r->update][$r->document_page])) { + $d[$r->document_id][$r->update]['links'][$r->document_page] = json_decode($r->links); + $d[$r->document_id][$r->update]['rulers'][$r->document_page] = json_encode($r->rulers); + } + } + + $c = $core->con->openCursor('document_links_versions'); + foreach($d as $document_id => $updates) { + $c->document_id = $document_id; + foreach($updates as $date => $dummy) { + $c->update = $date; + $c->links = serialize($d[$document_id][$date]['links']); + $c->rulers = serialize($d[$document_id][$date]['rulers']); + try { + $c->insert(); + } + catch(Exception $e) { + // fb($e); + } + } + } + } + public static function importFromOldWS($args) { global $core; diff --git a/inc/ws/DAO/class.ws.dao.book.php b/inc/ws/DAO/class.ws.dao.book.php index d563659a6..19b612440 100644 --- a/inc/ws/DAO/class.ws.dao.book.php +++ b/inc/ws/DAO/class.ws.dao.book.php @@ -647,8 +647,6 @@ class wsDAOBook extends commonDAO { $flex->addVariable('index', $index, false, true, 'JSONObject'); $flex->addVariable('textes', $textes, false, true, 'JSONObject'); - fb($pages); - foreach($pages as $i => $infos) { $base = WS_DOCS . '/' . $infos['document_id'] . '/p' . $infos['document_page']; $swffile = $base . '.swf'; diff --git a/inc/ws/DAO/class.ws.dao.document.php b/inc/ws/DAO/class.ws.dao.document.php index 60c95ec4f..dff100b60 100644 --- a/inc/ws/DAO/class.ws.dao.document.php +++ b/inc/ws/DAO/class.ws.dao.document.php @@ -109,20 +109,39 @@ class wsDAODocument extends commonDAO { $t[$ruler->page]['rulers'][] = $ruler; } - $c = $this->con->openCursor('document_links'); - $c->update = TIME; + $links = array(); + $rulers = array(); - foreach($pages as $page => $infos) { - $c->document_id = $infos['document_id']; - $c->document_page = $infos['document_page']; - if (isset($t[$page])) { - $elements = $t[$page]; - $c->links = json_encode($elements['links']); - $c->rulers = json_encode($elements['rulers']); - } else { - $c->links = json_encode(array()); - $c->rulers = json_encode(array()); + foreach($t as $page => $tt) { + $infos = $pages[$page]; + $doc_id = $infos['document_id']; + $doc_page = $infos['document_page']; + + if (!isset($links[$doc_id])) { + $links[$doc_id] = array(); + $rulers[$doc_id] = array(); + } + if (!isset($links[$doc_id][$doc_page])) { + $links[$doc_id][$doc_page] = array(); + $rulers[$doc_id][$doc_page] = array(); + } + + foreach($tt['links'] as $link) { + $links[$doc_id][$doc_page][] = $link; + } + + foreach($tt['rulers'] as $ruler) { + $rulers[$doc_id][$doc_page][] = $link; } + } + + $c = $this->con->openCursor('document_links_versions'); + $c->update = TIME; + + foreach($links as $document_id => $dummy) { + $c->document_id = $document_id; + $c->links = json_encode($links[$document_id]); + $c->rulers = json_encode($rulers[$document_id]); $c->insert(); } @@ -196,18 +215,27 @@ class wsDAODocument extends commonDAO { $lpages[$page][] = $link; } - $c = $this->con->openCursor('document_links'); + $links = array(); + foreach($pages as $p => $infos) { + if (!isset($links[$infos['document_id']])) { + $links[$infos['document_id']] = array(); + } + if (isset($lpages[$p])) { + $links[$infos['document_id']][$infos['document_page']] = $lpages[$p]; + //fb($lpages[$p]); + } + } + + $c = $this->con->openCursor('document_links_versions'); $c->update = TIME; - foreach($pages as $page => $infos) { + + foreach($links as $document_id => $l) { $c->document_id = $infos['document_id']; - $c->document_page = $infos['document_page']; - if (isset($lpages[$page])) { - $c->links = json_encode($lpages[$page]); - } else { - $c->links = json_encode(array()); - } + $c->links = json_encode($l); + $c->rulers = json_encode(array()); $c->insert(); + fb($c->getInsert()); } $c = $this->con->openCursor('books'); @@ -220,32 +248,36 @@ class wsDAODocument extends commonDAO { $daoBook = new wsDAOBook($this->con); $pages = $daoBook->getPagesOfBook($book_id); - $couples = array(); - $couples_order = array(); foreach($pages as $p => $infos) { - $couples[$p] = '(' . $infos['document_id'] . ',' . $infos['document_page'] . ')'; - $couples_order[] = "'" . $infos['document_id'] . ',' . $infos['document_page'] . "'"; + $documents[] = $infos['document_id']; } + $documents = array_unique($documents); - $links = array(); - $rulers = array(); + $tlinks = array(); + $trulers = array(); - $sql = 'SELECT *,CONCAT(document_id,\',\',document_page) AS doc_page FROM document_links WHERE (document_id,document_page) IN(' . implode(',', $couples) . ') ORDER BY `update` DESC, FIELD(doc_page,' . implode(',', $couples_order) . ') LIMIT ' . count($pages); + foreach($documents as $d) { + $r = $this->con->select('SELECT * FROM document_links_versions WHERE document_id=' . $d . ' ORDER BY `update` DESC LIMIT 1'); + $tlinks[$d] = json_decode($r->links, true); + $trulers[$d] = json_decode($r->rulers, true); + } - $r = $this->con->select($sql); $i = 1; - while ($r->fetch()) { - $l = json_decode($r->links); - foreach($l as $link) { - $link->page = $i; - $links[] = $link; + foreach ($pages as $p => $infos) { + if (isset($tlinks[$infos['document_id']][$infos['document_page']])) { + $l = $tlinks[$infos['document_id']][$infos['document_page']]; + foreach($l as $link) { + $link['page'] = $p; + $links[] = $link; + } } - $ru = json_decode($r->rulers); - foreach($ru as $ruler) { - $ruler->page = $i; - $rulers[] = $ruler; + if (isset($trulers[$infos['document_id']][$infos['document_page']])) { + $ru = $trulers[$infos['document_id']][$infos['document_page']]; + foreach($ru as $ruler) { + $ruler['page'] = $p; + $rulers[] = $ruler; + } } - $i++; } } -- 2.39.5