]> _ Git - cubeextranet.git/commitdiff
(no commit message)
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Fri, 15 Apr 2011 20:02:29 +0000 (20:02 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Fri, 15 Apr 2011 20:02:29 +0000 (20:02 +0000)
inc/commons/class.common.core.php
inc/ws/Controlleur/class.ws.maintenance.php
inc/ws/DAO/class.ws.dao.book.php
inc/ws/DAO/class.ws.dao.document.php

index 726c31cfe2d1528a2a80aa510052fa6e67cc5399..89f5f416be97ff541599b859c4848ec592bb4ac4 100644 (file)
@@ -336,6 +336,14 @@ class commonCore extends cubeCore {
                $db->document_links->index('index_document_links_date', 'BTREE', 'update');\r
                $db->document_links->index('index_document_links_document_id', 'BTREE', 'document_id');\r
                // .\r
+               // Tables versions des liens\r
+               $db->document_links_versions->document_id('integer', 0, false);\r
+               $db->document_links_versions->links('text', 0, false);\r
+               $db->document_links_versions->rulers('text', 0, false);\r
+               $db->document_links_versions->update('integer', 0, false);\r
+               // .\r
+               $db->document_links_versions->primary('pk_document_links_version', 'document_id', 'update');\r
+               $db->document_links_versions->index('idx_document_links_version_update', 'BTREE', 'update');\r
                // Table Books\r
                $db->books->book_id('integer', 0, false);\r
                $db->books->nom('varchar', 256, false);\r
index 0ea55f72e5353a67a6a8733b85af820a3a3b8c1f..083a865282324d34cc70eeef2962d2a28536b673 100644 (file)
@@ -11,6 +11,50 @@ class wsMaintenance {
                }\r
        }\r
 \r
+       public static function resetLinks($args)\r
+       {\r
+               global $core;\r
+               $book_id = $args[0];\r
+               fb($book_id);\r
+               $dao = new wsDAODocument($core->con);\r
+               $dao->setLinksFromOldFluidbook($book_id);\r
+       }\r
+\r
+       public static function moveLinksToVersionDB()\r
+       {\r
+               global $core;\r
+               $r = $core->con->select('SELECT * FROM document_links');\r
+               $d = array();\r
+               while ($r->fetch()) {\r
+                       if (!isset($d[$r->document_id])) {\r
+                               $d[$r->document_id] = array();\r
+                       }\r
+                       if (!isset($d[$r->document_id][$r->update])) {\r
+                               $d[$r->document_id][$r->update] = array();\r
+                       }\r
+                       if (!isset($d[$r->document_id][$r->update][$r->document_page])) {\r
+                               $d[$r->document_id][$r->update]['links'][$r->document_page] = json_decode($r->links);\r
+                               $d[$r->document_id][$r->update]['rulers'][$r->document_page] = json_encode($r->rulers);\r
+                       }\r
+               }\r
+\r
+               $c = $core->con->openCursor('document_links_versions');\r
+               foreach($d as $document_id => $updates) {\r
+                       $c->document_id = $document_id;\r
+                       foreach($updates as $date => $dummy) {\r
+                               $c->update = $date;\r
+                               $c->links = serialize($d[$document_id][$date]['links']);\r
+                               $c->rulers = serialize($d[$document_id][$date]['rulers']);\r
+                               try {\r
+                                       $c->insert();\r
+                               }\r
+                               catch(Exception $e) {\r
+                                       // fb($e);\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
        public static function importFromOldWS($args)\r
        {\r
                global $core;\r
index d563659a69879eb7a49c53c5cf9dd7789b453c30..19b612440bd6d8d09512e26a11a14762ddb3ae61 100644 (file)
@@ -647,8 +647,6 @@ class wsDAOBook extends commonDAO {
                $flex->addVariable('index', $index, false, true, 'JSONObject');\r
                $flex->addVariable('textes', $textes, false, true, 'JSONObject');\r
 \r
-               fb($pages);\r
-\r
                foreach($pages as $i => $infos) {\r
                        $base = WS_DOCS . '/' . $infos['document_id'] . '/p' . $infos['document_page'];\r
                        $swffile = $base . '.swf';\r
index 60c95ec4f85ba8c6669e491e4180921c4af7d9b7..dff100b60bc6145d44cbf6f0baf3ae9e9642b1c3 100644 (file)
@@ -109,20 +109,39 @@ class wsDAODocument extends commonDAO {
                        $t[$ruler->page]['rulers'][] = $ruler;\r
                }\r
 \r
-               $c = $this->con->openCursor('document_links');\r
-               $c->update = TIME;\r
+               $links = array();\r
+               $rulers = array();\r
 \r
-               foreach($pages as $page => $infos) {\r
-                       $c->document_id = $infos['document_id'];\r
-                       $c->document_page = $infos['document_page'];\r
-                       if (isset($t[$page])) {\r
-                               $elements = $t[$page];\r
-                               $c->links = json_encode($elements['links']);\r
-                               $c->rulers = json_encode($elements['rulers']);\r
-                       } else {\r
-                               $c->links = json_encode(array());\r
-                               $c->rulers = json_encode(array());\r
+               foreach($t as $page => $tt) {\r
+                       $infos = $pages[$page];\r
+                       $doc_id = $infos['document_id'];\r
+                       $doc_page = $infos['document_page'];\r
+\r
+                       if (!isset($links[$doc_id])) {\r
+                               $links[$doc_id] = array();\r
+                               $rulers[$doc_id] = array();\r
+                       }\r
+                       if (!isset($links[$doc_id][$doc_page])) {\r
+                               $links[$doc_id][$doc_page] = array();\r
+                               $rulers[$doc_id][$doc_page] = array();\r
+                       }\r
+\r
+                       foreach($tt['links'] as $link) {\r
+                               $links[$doc_id][$doc_page][] = $link;\r
+                       }\r
+\r
+                       foreach($tt['rulers'] as $ruler) {\r
+                               $rulers[$doc_id][$doc_page][] = $link;\r
                        }\r
+               }\r
+\r
+               $c = $this->con->openCursor('document_links_versions');\r
+               $c->update = TIME;\r
+\r
+               foreach($links as $document_id => $dummy) {\r
+                       $c->document_id = $document_id;\r
+                       $c->links = json_encode($links[$document_id]);\r
+                       $c->rulers = json_encode($rulers[$document_id]);\r
                        $c->insert();\r
                }\r
 \r
@@ -196,18 +215,27 @@ class wsDAODocument extends commonDAO {
                        $lpages[$page][] = $link;\r
                }\r
 \r
-               $c = $this->con->openCursor('document_links');\r
+               $links = array();\r
+               foreach($pages as $p => $infos) {\r
+                       if (!isset($links[$infos['document_id']])) {\r
+                               $links[$infos['document_id']] = array();\r
+                       }\r
+                       if (isset($lpages[$p])) {\r
+                               $links[$infos['document_id']][$infos['document_page']] = $lpages[$p];\r
+                               //fb($lpages[$p]);\r
+                       }\r
+               }\r
+\r
+               $c = $this->con->openCursor('document_links_versions');\r
                $c->update = TIME;\r
-               foreach($pages as $page => $infos) {\r
+\r
+               foreach($links as $document_id => $l) {\r
                        $c->document_id = $infos['document_id'];\r
-                       $c->document_page = $infos['document_page'];\r
-                       if (isset($lpages[$page])) {\r
-                               $c->links = json_encode($lpages[$page]);\r
-                       } else {\r
-                               $c->links = json_encode(array());\r
-                       }\r
+                       $c->links = json_encode($l);\r
+\r
                        $c->rulers = json_encode(array());\r
                        $c->insert();\r
+                       fb($c->getInsert());\r
                }\r
 \r
                $c = $this->con->openCursor('books');\r
@@ -220,32 +248,36 @@ class wsDAODocument extends commonDAO {
                $daoBook = new wsDAOBook($this->con);\r
                $pages = $daoBook->getPagesOfBook($book_id);\r
 \r
-               $couples = array();\r
-               $couples_order = array();\r
                foreach($pages as $p => $infos) {\r
-                       $couples[$p] = '(' . $infos['document_id'] . ',' . $infos['document_page'] . ')';\r
-                       $couples_order[] = "'" . $infos['document_id'] . ',' . $infos['document_page'] . "'";\r
+                       $documents[] = $infos['document_id'];\r
                }\r
+               $documents = array_unique($documents);\r
 \r
-               $links = array();\r
-               $rulers = array();\r
+               $tlinks = array();\r
+               $trulers = array();\r
 \r
-               $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);\r
+               foreach($documents as $d) {\r
+                       $r = $this->con->select('SELECT * FROM document_links_versions WHERE document_id=' . $d . ' ORDER BY `update` DESC LIMIT 1');\r
+                       $tlinks[$d] = json_decode($r->links, true);\r
+                       $trulers[$d] = json_decode($r->rulers, true);\r
+               }\r
 \r
-               $r = $this->con->select($sql);\r
                $i = 1;\r
-               while ($r->fetch()) {\r
-                       $l = json_decode($r->links);\r
-                       foreach($l as $link) {\r
-                               $link->page = $i;\r
-                               $links[] = $link;\r
+               foreach ($pages as $p => $infos) {\r
+                       if (isset($tlinks[$infos['document_id']][$infos['document_page']])) {\r
+                               $l = $tlinks[$infos['document_id']][$infos['document_page']];\r
+                               foreach($l as $link) {\r
+                                       $link['page'] = $p;\r
+                                       $links[] = $link;\r
+                               }\r
                        }\r
-                       $ru = json_decode($r->rulers);\r
-                       foreach($ru as $ruler) {\r
-                               $ruler->page = $i;\r
-                               $rulers[] = $ruler;\r
+                       if (isset($trulers[$infos['document_id']][$infos['document_page']])) {\r
+                               $ru = $trulers[$infos['document_id']][$infos['document_page']];\r
+                               foreach($ru as $ruler) {\r
+                                       $ruler['page'] = $p;\r
+                                       $rulers[] = $ruler;\r
+                               }\r
                        }\r
-                       $i++;\r
                }\r
        }\r
 \r