mirrored from git://git.moodle.org/moodle.git
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A little utility script to perform search and replace on the whole da…
…tabase. It's not linked from anywhere yet. I'm not sure if this will work on PostgreSQL ... can someone test that?
- Loading branch information
moodler
committed
Jan 16, 2005
1 parent
713492e
commit 04337d7
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php /// $Id$ | ||
/// Search and replace strings throughout all texts in the whole database | ||
|
||
require('../config.php'); | ||
|
||
$search = optional_param('search', ''); | ||
$replace = optional_param('replace', ''); | ||
|
||
require_login(); | ||
|
||
if (!isadmin()) { | ||
error("Admins only"); | ||
} | ||
|
||
################################################################### | ||
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; | ||
execute_sql("UPDATE {$CFG->prefix}$table SET $column = REPLACE($column, '$search', '$replace');"); | ||
$db->debug = false; | ||
} | ||
} | ||
} | ||
} | ||
print_simple_box_end(); | ||
|
||
print_continue('index.php'); | ||
|
||
?> |