From: moodler Date: Sun, 16 Jan 2005 13:49:30 +0000 (+0000) Subject: A little utility script to perform search and replace on the whole database. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=04337d7531e6d048a24d4a9ffe93ff60f3e68e2a;p=moodle.git A little utility script to perform search and replace on the whole database. It's not linked from anywhere yet. I'm not sure if this will work on PostgreSQL ... can someone test that? --- diff --git a/admin/replace.php b/admin/replace.php new file mode 100644 index 0000000000..33d9c8d65d --- /dev/null +++ b/admin/replace.php @@ -0,0 +1,58 @@ +'; + echo '
'; + echo ''; + echo 'Search whole database for:
'; + echo 'Replace with this string:

'; + echo '
'; + echo '
'; + echo ''; + print_simple_box_end(); + die; +} + + +if (!$tables = $db->Metatables() ) { // No tables yet at all. + error("no tables"); +} + +print_simple_box_start('center'); +foreach ($tables as $table) { + if (in_array($table, array($CFG->prefix.'config'))) { // Don't process these + continue; + } + if ($columns = $db->MetaColumns($table, false)) { + foreach ($columns as $column => $data) { + if (in_array($data->type, array('text','mediumtext','longtext','varchar'))) { // Text stuff only + $db->debug = true; + execute_sql("UPDATE {$CFG->prefix}$table SET $column = REPLACE($column, '$search', '$replace');"); + $db->debug = false; + } + } + } +} +print_simple_box_end(); + +print_continue('index.php'); + +?>