diff --git a/ecrire/inc/import.php b/ecrire/inc/import.php index f70a48a8d958d4d7814658c6682cf8c7c96904f5..034225834fe1541505a1e73cfdcdf44c51d6828f 100644 --- a/ecrire/inc/import.php +++ b/ecrire/inc/import.php @@ -85,7 +85,7 @@ function import_debut($f, $gz=false) { // function import_objet_1_2($f, $gz=false) { - global $import_ok, $pos, $abs_pos; + global $import_ok; static $time_javascript; if (time() - $time_javascript > 3) { // 3 secondes @@ -93,36 +93,24 @@ function import_objet_1_2($f, $gz=false) { $time_javascript = time(); } - static $tables; - if (!$tables) $tables = array( - 'article' => 'spip_articles', - 'auteur' => 'spip_auteurs', - 'breve' => 'spip_breves', - 'document' => 'spip_documents', - 'forum' => 'spip_forum', - 'groupe_mots' => 'spip_groupes_mots', - 'message' => 'spip_messages', - 'mot' => 'spip_mots', - 'petition' => 'spip_petitions', - 'rubrique' => 'spip_rubriques', - 'signature' => 'spip_signatures', - 'syndic' => 'spip_syndic', - 'syndic_article' => 'spip_syndic_articles', - 'type_document' => 'spip_types_documents' - ); - - $import_ok = false; + $b = ''; // Lire le type d'objet - if (!($type = xml_fetch_tag($f, $b, $gz))) return false; + if (!($type = xml_fetch_tag($f, $b, $gz))) return ($import_ok = false); if ($type == '/SPIP') return !($import_ok = true); + return ($import_ok = import_objet_1_2_boucle($type, $f, $gz)); +} + +function import_objet_1_2_boucle($type, $f, $gz) { + global $pos, $abs_pos; + $id = "id_$type"; $id_objet = 0; + $liens = array(); // Lire les champs de l'objet for (;;) { - $b = ''; - if (!($col = xml_fetch_tag($f, $b, $gz))) return false; + if (!($col = xml_fetch_tag($f, $value, $gz))) return false; if ($col == '/'.$type) break; $value = ''; if (!xml_fetch_tag($f, $value, $gz)) return false; @@ -139,7 +127,7 @@ function import_objet_1_2($f, $gz=false) { echo "--><br><font color='red'><b>"._T('avis_erreur_sauvegarde', array('type' => $type, 'id_objet' => $id_objet))."</b></font>\n<font color='black'>"._T('avis_colonne_inexistante', array('col' => $col)); if ($col == 'images') echo _T('info_verifier_image'); echo "</font>\n<!--"; - $GLOBALS['erreur_restauration'] = true; + $GLOBALS['erreur_restauration']= true; } } else { @@ -149,14 +137,40 @@ function import_objet_1_2($f, $gz=false) { } } } - - $table = $tables[$type]; - - if (!spip_query("REPLACE $table (" . join(',', $cols) . ') VALUES (' . join(',', $values) . ')')) { + $table = table_objet($type); + if ($table) + $table = "spip_$table"; + else { + $table = $type; + // Table non Spip, on accepte. + // Si c'est vraiment n'importe quoi le test suivant le dira + echo "\nTable externe: $type"; + } + $n = spip_query("REPLACE " . $table . "(" . join(',', $cols) . ') VALUES (' . join(',', $values) . ')'); + if(!$n) { echo "--><br><font color='red'><b>"._T('avis_erreur_mysql')."</b></font>\n<font color='black'><tt>".spip_sql_error()."</tt></font>\n<!--"; $GLOBALS['erreur_restauration'] = true; } + supprime_anciens_liens($type, $id_objet); + $sens = ($type == 'auteur' OR $type == 'mot' OR $type == 'document'); + $type .= 's'; + foreach($liens as $type_lien => $t) { + if (!$sens) + $table_lien = $type_lien.'s_'.$type; + else + $table_lien = $type.'_'.$type_lien . + (($type_lien == 'syndic' OR $type_lien == 'forum') ? '' : 's'); + spip_abstract_insert('spip_' . $table_lien, "($id, id_$type_lien)", join(',', $t)); + } + + ecrire_meta("status_restauration", strval($pos + $abs_pos)); + + return true; +} + +function supprime_anciens_liens($type, $id_objet) +{ if ($type == 'article') { spip_query("DELETE FROM spip_auteurs_articles WHERE id_article=$id_objet"); spip_query("DELETE FROM spip_documents_articles WHERE id_article=$id_objet"); @@ -181,25 +195,8 @@ function import_objet_1_2($f, $gz=false) { else if ($type == 'message') { spip_query("DELETE FROM spip_auteurs_messages WHERE id_message=$id_objet"); } - if ($liens) { - reset($liens); - while (list($type_lien, $t) = each($liens)) { - if ($type == 'auteur' OR $type == 'mot' OR $type == 'document') - if ($type_lien == 'syndic' OR $type_lien == 'forum') $table_lien = 'spip_'.$type.'s_'.$type_lien; - else $table_lien = 'spip_'.$type.'s_'.$type_lien.'s'; - else - $table_lien = 'spip_'.$type_lien.'s_'.$type.'s'; - spip_abstract_insert($table_lien, "($id, id_$type_lien)", join(',', $t)); - } - } - - $p = $pos + $abs_pos; - ecrire_meta("status_restauration", "$p"); - - return $import_ok = true; } - function import_objet_0_0($f, $gz=false) { global $import_ok, $pos, $abs_pos; diff --git a/ecrire/inc/utils.php b/ecrire/inc/utils.php index 780bcaa7381e436f7c29178b6cf37edfa5c01263..990bfdb3cc2fb374a6ab068899242795c92a051c 100644 --- a/ecrire/inc/utils.php +++ b/ecrire/inc/utils.php @@ -411,13 +411,26 @@ function _L($text, $args=array()) { // Nommage bizarre des tables d'objets function table_objet($type) { - if ($type == 'site' OR $type == 'syndic') - return 'syndic'; - else if ($type == 'forum') - return 'forum'; - else - return $type.'s'; + static $surnoms = array( + 'article' => 'articles', + 'auteur' => 'auteurs', + 'breve' => 'breves', + 'document' => 'documents', + 'forum' => 'forum', # hum + 'groupe_mots' => 'groupes_mots', # hum + 'message' => 'messages', + 'mot' => 'mots', + 'petition' => 'petitions', + 'rubrique' => 'rubriques', + 'signature' => 'signatures', + 'syndic' => 'syndic', + 'site' => 'syndic', # hum hum + 'syndic_article' => 'syndic_articles', + 'type_document' => 'types_documents' # hum + ); + return $surnoms[$type]; } + function id_table_objet($type) { if ($type == 'site' OR $type == 'syndic') return 'id_syndic';