2005-01-16 13:49:30 +00:00
|
|
|
<?php /// $Id$
|
|
|
|
/// Search and replace strings throughout all texts in the whole database
|
|
|
|
|
2006-03-06 19:27:25 +00:00
|
|
|
require_once('../config.php');
|
2005-01-16 13:49:30 +00:00
|
|
|
|
2006-03-06 19:27:25 +00:00
|
|
|
$search = optional_param('search', '', PARAM_RAW);
|
|
|
|
$replace = optional_param('replace', '', PARAM_RAW);
|
2005-01-16 13:49:30 +00:00
|
|
|
|
|
|
|
require_login();
|
|
|
|
|
2006-08-25 08:27:27 +00:00
|
|
|
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID));
|
2005-01-16 13:49:30 +00:00
|
|
|
|
|
|
|
###################################################################
|
|
|
|
print_header('Search and replace throughout the whole database', 'Replace text within the whole database');
|
|
|
|
|
|
|
|
|
|
|
|
if (!$search or !$replace or !confirm_sesskey()) { /// Print a form
|
|
|
|
|
|
|
|
print_simple_box_start('center');
|
|
|
|
echo '<div align="center">';
|
|
|
|
echo '<form action="replace.php">';
|
|
|
|
echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'">';
|
|
|
|
echo 'Search whole database for: <input type="text" name="search"><br />';
|
|
|
|
echo 'Replace with this string: <input type="text" name="replace"><br /></br />';
|
|
|
|
echo '<input type="submit" value="Yes, do it now"><br />';
|
|
|
|
echo '</form>';
|
|
|
|
echo '</div>';
|
|
|
|
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;
|
2006-04-09 21:25:30 +00:00
|
|
|
execute_sql("UPDATE $table SET $column = REPLACE($column, '$search', '$replace');");
|
2005-01-16 13:49:30 +00:00
|
|
|
$db->debug = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print_simple_box_end();
|
|
|
|
|
|
|
|
print_continue('index.php');
|
|
|
|
|
|
|
|
?>
|