From f2e7c55918f6597d7a19d21d6eb81e07bd1587b9 Mon Sep 17 00:00:00 2001 From: "Committo,Ergo:sum" <esj@rezo.net> Date: Thu, 18 Oct 2007 08:48:16 +0000 Subject: [PATCH] =?UTF-8?q?Scories=20dans=20la=20s=C3=A9rie=20des=20mises?= =?UTF-8?q?=20=C3=A0=20jour,=20blindage=20de=20la=20fonction=20qui=20les?= =?UTF-8?q?=20g=C3=A8re=20pour=20qu'on=20en=20soit=20pr=C3=A9venu,=20et=20?= =?UTF-8?q?compl=C3=A9ment=20au=20portage=20de=20l'instruction=20ALTER=20e?= =?UTF-8?q?n=20PG.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ecrire/base/db_pg.php | 30 ++++++++++++++++-------------- ecrire/base/upgrade.php | 15 +++++++++------ ecrire/maj/v019.php | 4 ++-- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/ecrire/base/db_pg.php b/ecrire/base/db_pg.php index 2fd88d4ecb..8dd975ed51 100644 --- a/ecrire/base/db_pg.php +++ b/ecrire/base/db_pg.php @@ -151,35 +151,37 @@ function spip_pg_alter_change($table, $arg, $serveur='') // http://doc.spip.org/@spip_pg_alter_add function spip_pg_alter_add($table, $arg, $serveur='') { - if (!preg_match('/^(INDEX|KEY|PRIMARY\s+KEY|)\s*`?(\w+)`?(.*)$/', $arg, $r)) - spip_log("drop $arg incompris", 'pg'); - else { - if (!$r[1]) - return spip_pg_query("ALTER TABLE $table ADD " . $r[2] . ' ' . mysql2pg_type($r[3]), $serveur); - elseif ($r[1][0] = 'P') - return spip_pg_query("ALTER TABLE $table ADD PRIMARY KEY " . $r[2], $serveur); - else { - return spip_pg_query("CREATE INDEX " . $table . '_' . $r[2] . "ON $table", $serveur); - } + if (!preg_match('/^(INDEX|KEY|PRIMARY\s+KEY|)\s*(.*)$/', $arg, $r)) { + spip_log("alter add $arg incompris", 'pg'); + return NULL; + } + if (!$r[1]) { + preg_match('/`?(\w+)`?(.*)/',$r[2], $m); + return spip_pg_query("ALTER TABLE $table ADD " . $m[1] . ' ' . mysql2pg_type($m[2]), $serveur); + } elseif ($r[1][0] == 'P') { + preg_match('/\(`?(\w+)`?\)/',$r[2], $m); + return spip_pg_query("ALTER TABLE $table ADD CONSTRAINT $table" .'_pkey PRIMARY KEY (' . $m[1] . ')', $serveur); + } else { + preg_match('/`?(\w+)`?\s*(\([^)]*\))/',$r[2], $m); + return spip_pg_query("CREATE INDEX " . $table . '_' . $m[1] . " ON $table " . str_replace("`","",$m[2]), $serveur); } } // http://doc.spip.org/@spip_pg_alter_drop function spip_pg_alter_drop($table, $arg, $serveur='') { - if (!preg_match('/^(INDEX|KEY|PRIMARY\s+KEY|)\s*`?(\w+)`?/', $arg, $r)) + if (!preg_match('/^(INDEX|KEY|PRIMARY\s+KEY|)\s*`?(\w*)`?/', $arg, $r)) spip_log("alter drop: $arg incompris", 'pg'); else { if (!$r[1]) return spip_pg_query("ALTER TABLE $table DROP " . $r[2], $serveur); - elseif ($r[1][0] = 'P') - return spip_pg_query("ALTER TABLE $table DROP CONSTRAINT PRIMARY", $serveur); + elseif ($r[1][0] == 'P') + return spip_pg_query("ALTER TABLE $table DROP CONSTRAINT $table" . '_pkey', $serveur); else { return spip_pg_query("DROP INDEX " . $table . '_' . $r[2], $serveur); } } } - // http://doc.spip.org/@spip_pg_explain function spip_pg_explain($query, $serveur=''){ if (strpos($query, 'SELECT') !== 0) return array(); diff --git a/ecrire/base/upgrade.php b/ecrire/base/upgrade.php index 81a1b504d2..4136964fcd 100644 --- a/ecrire/base/upgrade.php +++ b/ecrire/base/upgrade.php @@ -104,13 +104,16 @@ function maj_while($version_installee, $version_cible) // http://doc.spip.org/@serie_alter function serie_alter($serie, $q = array()) { $etape = intval(@$GLOBALS['meta']['upgrade_etape_'.$serie]); - foreach ($q as $i => $req) { + foreach ($q as $i => $r) { if ($i >= $etape) { - $f = array_shift($req); - spip_log("maj $serie etape $i: $f ".join(',',$req),'maj'); - if (function_exists($f)) { - call_user_func_array($f, $req); - ecrire_meta('upgrade_etape_'.$serie, $i+1); + if (is_array($r) + AND function_exists($f = array_shift($r))) { + spip_log("$serie/$i: $f " . join(',',$r),'maj'); + call_user_func_array($f, $r); + ecrire_meta('upgrade_etape_'.$serie, $i+1); + } else { + echo "maj $serie etape $i incorrecte"; + exit; } } } diff --git a/ecrire/maj/v019.php b/ecrire/maj/v019.php index c11c080d08..9fc5c0f9c6 100644 --- a/ecrire/maj/v019.php +++ b/ecrire/maj/v019.php @@ -378,7 +378,7 @@ function maj_1_952() { if (!$ok) die('echec sur maj_1_952()'); } -$GLOBALS['maj'][1][952] = array('maj_1_952'); +$GLOBALS['maj'][1][952] = array(array('maj_1_952')); function maj_1_953() { @@ -387,7 +387,7 @@ function maj_1_953() creer_base_types_doc($tables_principales['spip_types_documents']); } -$GLOBALS['maj'][1][953] = array('maj_1_953'); +$GLOBALS['maj'][1][953] = array(array('maj_1_953')); $GLOBALS['maj'][1][954] = array( -- GitLab