From: vincent@cubedesigners.com Date: Tue, 15 Mar 2011 10:27:35 +0000 (+0000) Subject: (no commit message) X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=2a88a94bcbb8b50e852f293c239e040340ffe61b;p=cubeextranet.git --- diff --git a/inc/ws/Controlleur/class.ws.maintenance.php b/inc/ws/Controlleur/class.ws.maintenance.php index ccb6669a2..6cedf57fe 100644 --- a/inc/ws/Controlleur/class.ws.maintenance.php +++ b/inc/ws/Controlleur/class.ws.maintenance.php @@ -14,6 +14,11 @@ class wsMaintenance { public static function importFromOldWS($args) { global $core; + + self::importLangs(); + self::importThemes(); + self::importDocs(); + self::importBooks(); // Import des fluidbooks // Donc le dernier importé est le max dont le numéro est inférieur à 10000 $r = $core->con->select('SELECT MAX(book_id) FROM books WHERE book<10000'); @@ -24,17 +29,176 @@ class wsMaintenance { while ($r->fetch()) { $oldBooks[] = $r->bid; } + } + + protected static function _sqlIn($tab) + { + return ' IN(\'' . implode('\',\'', $tab) . '\') '; + } + + protected static function _getLangCode($lang) + { + $lang = strtolower($lang); + if ($lang == 'cz') { + $lang = 'cs'; + } + return $lang; + } + + public static function importLangs($oldBooks) + { + global $core; + // On regarde d'abord les langues que nous avons déjà + $r = $core->con->select('SELECT lang_id FROM langues'); + $already = array(); + while ($r->fetch()) { + $already[] = $r->lang_id; + } + + $toImport = array(); + $r = $core->con->select('SELECT DISTINCT lang FROM ws.book WHERE bid ' . self::_sqlIn($oldBooks)); + while ($r->fetch()) { + $idl = self::_getLangCode($r->lang); + if (in_array($idl, $already)) { + continue; + } + if (strlen($idl) > 2) { + continue; + } + $toImport[] = $r->lang; + } + + if (!count($toImport)) { + return; + } + + $allTrads = array(); + $trad = array(); + $r = $core->con->select('SELECT * FROM ws.lang_trad,ws.lang_ord WHERE lang_trad.idlt=lang_ord.idlt AND idl ' . self::_sqlIn($toImport) . ' '); + while ($r->fetch()) { + $idl = getLangCode($r->idl); + if (!isset($trad[$idl])) { + $trad[$idl] = array(); + } + $trad[$idl][$r->ord] = $r->text; + } + + foreach($toImport as $idl) { + $idl = getLangCode($idl); + + $traductions = wsLang::getTraductionWithId($trad[$idl]); + $allTrads[$idl] = $traductions; + + $c = $core->con->openCursor('langues'); + $c->lang_id = $idl; + $c->charset = 'Latin1'; + $c->font = 'Fluidbook.otf'; + $c->traductions = json_encode($traductions); + $c->insert(); + } + } + + public static function importThemes($oldBooks) + { + // Import des thèmes + $r = $core->con->select('SELECT * FROM ws.theme WHERE tid IN (SELECT * FROM ws.book WHERE bid ' . self::_sqlIn($oldBooks) . ')'); + $theme = new wsTheme(); + while ($r->fetch()) { + $c = $core->con->openCursor('themes'); + $c->theme_id = $r->tid; + $c->proprietaire = self::_getWsUser($r->proprietaire); + $c->date = $r->date; + $c->nom = $r->titre; + + $parametres = new wsThemeParametres($theme); + $parametres->fromRecord($r); + $c->icones = self::_oldIconesToColor($r->iid, $parametres); + $c->parametres = serialize($parametres); + $c->insert(); + } + $r = $core->con->select('SELECT * FROM ws.theme_user'); + $c = $core->con->openCursor('themes_droits'); + while ($r->fetch()) { + $c->utilisateur_id = $r->uid; + $c->theme_id = $r->tid; + try { + $c->insert(); + } + catch(Exception $e) { + } + } + } + + public static function importDocs($oldBooks) + { // On cherche maintenant à savoir si l'on doit importer de nouveaux documents associés $oldDocuments = array(); - $r = $core->con->select('SELECT DISTINCT did FROM ws.book_pages WHERE bid IN(' . implode(',', $oldBooks) . ')'); + $r = $core->con->select('SELECT DISTINCT did FROM ws.book_pages WHERE bid ' . self::_sqlIn($oldBooks) . ''); + while ($r->fetch()) { + $oldDocuments[] = $r->did; + } + + if (!count($oldDocuments)) { + return; + } + + $r = $core->con->select('SELECT * FROM ws.document ORDER BY did WHERE did ' . self::_sqlIn($oldDocuments)); while ($r->fetch()) { - $oldDocument[] = $r->did; + $c = $core->con->openCursor('documents'); + $c->document_id = $r->did; + $c->pages = $r->pages; + $c->version = 1; + try { + $c->insert(); + } + catch(Exception $e) { + } + $docs[$r->did] = true; } } - public function importOldBook($r) + public static function importBooks($oldBook) { } + + public static function _oldIconesToColor($iid, &$parametres) + { + global $oldIconesColors; + if (!isset($oldIconesColors)) { + $oldIconesColors = array(); + $fp = fopen(dirname(__FILE__) . '/../../icones.csv', 'rb'); + $i = 1; + while ($line = fgetcsv($fp, 1000, ';', '"')) { + $oldIconesColors[$i] = array('color' => trim($line[0]), 'iid' => trim($line[1])); + $i++; + } + } + $line = $oldIconesColors[$iid]; + if ($line['iid'] != '') { + $parametres->iconSet = $line['iid']; + $parametres->iconsHMargin = $line['iid'] == 1?20:0; + $parametres->menuHeight = 39; + $parametres->colorizeIcons = false; + $parametres->couleurI = 'ffffff'; + return $line['iid']; + } + $parametres->iconSet = 1; + $parametres->colorizeIcons = 1; + $parametres->iconsHMargin = 20; + $parametres->menuHeight = 39; + $parametres->couleurI = $line['color']; + + return 1; + } + + public static function _getWsUser($oldid) + { + global $ws2ext; + if (!isset($ws2ext[$oldid])) { + $ws2ext[$oldid] = 5; + } + return $ws2ext[$oldid]; + } } ?> \ No newline at end of file