diff --git a/ecrire/base/db_mysql.php b/ecrire/base/db_mysql.php index d6686f9f8439c33f85761e2c1baaaef88d375a15..8c36d4163995a753817330144debfa0b83c9b547 100644 --- a/ecrire/base/db_mysql.php +++ b/ecrire/base/db_mysql.php @@ -256,7 +256,7 @@ function spip_mysql_create($nom, $champs, $cles, $autoinc=false, $temporary=fals $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ")". ($character_set?" DEFAULT $character_set":"") ."\n"; - spip_mysql_query($q); + return spip_mysql_query($q); } // http://doc.spip.org/@spip_mysql_showtable diff --git a/ecrire/base/db_pg.php b/ecrire/base/db_pg.php index c6254aaf451e3cc20e025c215deebd580ca96606..07e3bc6a2dc1adee2ff0fc83e75c45af21086c40 100644 --- a/ecrire/base/db_pg.php +++ b/ecrire/base/db_pg.php @@ -374,19 +374,10 @@ function spip_pg_updateq($table, $champs, $where='', $desc=array()) { $fields = $desc['field']; $r = ''; foreach ($champs as $champ => $val) { - $t = $fields[$champ]; - if (!test_sql_int($t)) { - if ((strpos($t, 'datetime')!==0) - AND (strpos($t, 'TIMESTAMP')!==0)) - $val = _q($val); - elseif (strpos("012345678", $val[0]) !==false) - $val = "date '$val'"; - else $val = spip_pg_frommysql($val); - } - $r .= ',' . $champ . '=' . $val; + $r .= ',' . $champ . '=' . spip_pg_cite($val, $fields[$champ]); } $r = "UPDATE $table SET " . substr($r, 1) . ($where ? " WHERE $where" : ''); - pg_query($r); + return pg_query($r); } @@ -401,7 +392,6 @@ function spip_pg_replace($table, $values, $desc) { $prim = $desc['key']['PRIMARY KEY']; $ids = preg_split('/,\s*/', $prim); $noprims = $prims = array(); - foreach($values as $k=>$v) { $values[$k] = $v = spip_pg_cite($v, $desc['field'][$k]); @@ -416,24 +406,23 @@ function spip_pg_replace($table, $values, $desc) { return 0; } $set = join(',', $noprims); - if ($set) { - $r = pg_query($spip_pg_link, $q = "UPDATE $table SET $set WHERE $where"); - if (!$r) { + $set = pg_query($spip_pg_link, $q = "UPDATE $table SET $set WHERE $where"); + if (!$set) { $n = spip_pg_errno(); $m = spip_pg_error($q); } else { - $r = pg_affected_rows($r); + $set = pg_affected_rows($set); } } - if (!$r) { - $r = pg_query($spip_pg_link, $q = "INSERT INTO $table (" . join(',',array_keys($values)) . ') VALUES (' .join(',', $values) . ')'); - if (!$r) { + if (!$set) { + $set = pg_query($spip_pg_link, $q = "INSERT INTO $table (" . join(',',array_keys($values)) . ') VALUES (' .join(',', $values) . ')'); + if (!$set) { $n = spip_pg_errno(); $m = spip_pg_error($q); } } - return $r; + return $set; } // Explicite les conversions de Mysql d'une valeur $v de type $t @@ -443,9 +432,13 @@ function spip_pg_replace($table, $values, $desc) { function spip_pg_cite($v, $t) { if ((strpos($t, 'datetime')===0) OR (strpos($t, 'TIMESTAMP')===0)) { - if (strpos($v, "-00-00") === 4) - return _q(substr($v,0,4)."-01-01".substr($v,10)); - else return spip_pg_frommysql($v); + if (strpos("0123456789", $v[0]) === false) + return spip_pg_frommysql($v); + else { + if (strpos($v, "-00-00") === 4) + $v = substr($v,0,4)."-01-01".substr($v,10); + return "date '$v'"; + } } elseif (test_sql_int($t)) return intval($v); @@ -553,9 +546,10 @@ function spip_pg_create($nom, $champs, $cles, $autoinc=false, $temporary=false) ($character_set?" DEFAULT $character_set":"") ."\n"; - @pg_query($spip_pg_link, $q); + $r = @pg_query($spip_pg_link, $q); foreach($keys as $index) {@pg_query($spip_pg_link, $index);} + return $r; } // Selectionner la sous-chaine dans $objet diff --git a/ecrire/base/import_all.php b/ecrire/base/import_all.php index a2e7defce799ac451ed9258bdd3b46075ced24dd..0570681ccb493d9f45096fe05772c34b5a3ac5b9 100644 --- a/ecrire/base/import_all.php +++ b/ecrire/base/import_all.php @@ -61,11 +61,9 @@ function base_import_all_dist($titre, $reprise=false) echo debut_droite('', true); - import_all_milieu($request); + $res = import_all_milieu($request); - echo "</body></html>\n"; - - if ($request['insertion'] == 'on') { + if (!$res AND $request['insertion'] == 'on') { $request['insertion'] = 'passe2'; if ($request['url_site'] AND substr($request['url_site'],-1) != '/') @@ -75,6 +73,8 @@ function base_import_all_dist($titre, $reprise=false) $res = import_all_milieu($request); } + echo $res, "</body></html>\n"; + if ($charset = $GLOBALS['meta']['charset_restauration']) { ecrire_meta('charset', $charset); ecrire_metas(); diff --git a/ecrire/exec/import_all.php b/ecrire/exec/import_all.php index 46a64923813e03da91b8212f5195ab6bf0adcee1..ea81a48a10319ae1756576d82455ad05933dd7d9 100644 --- a/ecrire/exec/import_all.php +++ b/ecrire/exec/import_all.php @@ -67,8 +67,8 @@ function verifier_sauvegarde ($archive) { global $spip_version; $g = preg_match(",\.gz$,", $archive); - $_fopen = ($g) ? gzopen : fopen; - $_fread = ($g) ? gzread : fread; + $_fopen = $g ? 'gzopen' : 'fopen'; + $_fread = $g ? 'gzread' : 'fread'; $buf_len = 1024; // la version doit etre dans le premier ko if (!(@file_exists($archive) AND $f = $_fopen($archive, "rb"))) diff --git a/ecrire/inc/import.php b/ecrire/inc/import.php index c69ee4e5ff0338e154e3ee2d47cefef715cc9d3b..678300827e62e8d6e606a8886462d07987ddfff7 100644 --- a/ecrire/inc/import.php +++ b/ecrire/inc/import.php @@ -303,13 +303,13 @@ function import_init_meta($tag, $atts, $charset, $request) // faire la conversion de charset en php :( effacer_meta('restauration_charset_sql_connexion'); # precaution spip_log("charset de restauration inconnu de sql : $charset"); - if ( $i = $request['insertion']) + if ($request['insertion']) ecrire_meta('charset_insertion', $charset,'non'); else ecrire_meta('charset_restauration', $charset,'non'); } } ecrire_metas(); - spip_log("Debut de l'importation (charset: $charset, format: $version_archive)" . ($i ? " insertion $i" : '')); + spip_log("Debut de l'importation (charset: $charset, format: $version_archive)" . ($request['insertion'] ? " insertion $i" : '')); return $version_archive; } diff --git a/ecrire/inc/import_1_3.php b/ecrire/inc/import_1_3.php index bf16247d07a03f587e23619bb9411a2e2d90f4bc..02db1de8e768043a738ab28ed8228e95c20605cf 100644 --- a/ecrire/inc/import_1_3.php +++ b/ecrire/inc/import_1_3.php @@ -25,6 +25,7 @@ function inc_import_1_3_dist($lecteur, $request, $gz='fread', $atts=array()) { if (!$tables OR $trans) { $init = $request['init']; $tables = $init($request); + if (!$tables) return ($import_ok = false); $phpmyadmin = preg_match("{^phpmyadmin::}is", $GLOBALS['meta']['version_archive_restauration']) ? array(array('"','>'),array('"','>')) @@ -55,7 +56,8 @@ function inc_import_1_3_dist($lecteur, $request, $gz='fread', $atts=array()) { list($nom,$desc) = description_table($table); if (!isset($desc['field'])) $desc = $defaut; - elseif ($request['insertion']=='on') + elseif (isset($request['insertion']) + AND $request['insertion']=='on') $desc['field'] = import_collecte($desc); $field_desc[$boucle][$table] = $desc; } @@ -115,37 +117,31 @@ function import_replace($values, $table, $desc, $request, $atts='') { // impt=oui : la ligne est surchargeable par import // impt=non : la ligne ne doit pas etre ecrasee par un import // il faut gerer l'existence de la primary, et l'autorisation ou non de mettre a jour - $where = ""; if (!isset($desc['key']["PRIMARY KEY"])) $GLOBALS['erreur_restauration'] = "champ impt sans cle primaire sur la table $table"; else { $keys = $desc['key']["PRIMARY KEY"]; $keys = explode(",",$keys); if (!is_array($keys)) $keys = array($keys); - $w = ""; + $where = ""; foreach($keys as $key){ if (!isset($values[$key])){ $GLOBALS['erreur_restauration'] = "champ $key manquant a l'import sur la table $table"; - $w .= " AND 0=1"; - continue; + $where .= ""; + break; } - $w .= " AND $key="._q($values[$key]); + $where .= " AND $key="._q($values[$key]); } - $where = strlen($w)?substr($w,5):"0=1"; - } - if ($where!="") { - $res = spip_query("SELECT * FROM $table WHERE ".$where." AND impt='oui'"); - if (spip_num_rows($res)){ - $set = ""; - foreach($values as $key=>$value) $set .= ",$key="._q($value); - $set = substr($set,1); - if (!spip_query("UPDATE $table SET $set WHERE ".$where." AND impt='oui'")) { - $GLOBALS['erreur_restauration'] = sql_error(); + if ($where) { + $where = "impt='oui' $where"; + if (sql_countsel($table, $where,'',1)) { + if (!sql_updateq($table, $values, $where)) { + $GLOBALS['erreur_restauration'] = sql_error(); + } + }else{ + sql_insert($table, "(".join(',',array_keys($values)).")", "(".join(',',array_map('_q', $values)).")"); } } - else{ - sql_insert($table, "(".join(',',array_keys($values)).")", "(".join(',',array_map('_q', $values)).")"); - } } } } diff --git a/ecrire/inc/import_insere.php b/ecrire/inc/import_insere.php index 3656db2314d5d3363ce15a3b4b0dfbff5518a4d5..ef1d92674c07912d73f18bfbf5ae6563dcdbe58c 100644 --- a/ecrire/inc/import_insere.php +++ b/ecrire/inc/import_insere.php @@ -28,14 +28,17 @@ $spip_translate_key = array( // La rajouter ici car sql_insert en a besoin global $tables_principales;; $tables_principales['spip_translate'] = - array('field' => &$spip_translate, 'key' => &$spip_translate_key, 'join' => &$spip_signatures_join); + array('field' => &$spip_translate, 'key' => &$spip_translate_key); // http://doc.spip.org/@insere_1_init function insere_1_init($request) { global $tables_principales; $v = $tables_principales['spip_translate']; - sql_create('spip_translate', $v['field'], $v['key'], true); - + $v = sql_create('spip_translate', $v['field'], $v['key'], true); + if (!$v) { + spip_log("echec de la creation de la table de fusion"); + return false; + } // au cas ou la derniere fois ce serait terminee anormalement spip_query("DELETE FROM spip_translate"); return insere_1bis_init($request); diff --git a/ecrire/inc/rubriques.php b/ecrire/inc/rubriques.php index 8a36d3c6a5f048538a8318a59f53a4058769bd4e..a71ca84bbc6fb4608c6a0a5ed4912aa6295708d6 100644 --- a/ecrire/inc/rubriques.php +++ b/ecrire/inc/rubriques.php @@ -134,8 +134,7 @@ function calculer_rubriques() { function calculer_rubriques_publiees() { // Mettre les compteurs a zero - spip_query("UPDATE spip_rubriques - SET date_tmp='0000-00-00 00:00:00', statut_tmp='prive'"); + sql_updateq('spip_rubriques', array('date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prive')); // // Publier et dater les rubriques qui ont un article publie