Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / admin / replace.php
blobb47d26a3c72d2f4decfdfb7a1766f4756a0d4803
1 <?php /// $Id$
2 /// Search and replace strings throughout all texts in the whole database
4 require_once('../config.php');
5 require_once($CFG->dirroot.'/course/lib.php');
6 require_once($CFG->libdir.'/adminlib.php');
8 admin_externalpage_setup('replace');
10 $search = optional_param('search', '', PARAM_RAW);
11 $replace = optional_param('replace', '', PARAM_RAW);
13 ###################################################################
14 admin_externalpage_print_header();
16 print_heading('Search and replace text throughout the whole database');
19 if (!data_submitted() or !$search or !$replace or !confirm_sesskey()) { /// Print a form
21 print_simple_box_start('center');
22 echo '<div align="center">';
23 echo '<form action="replace.php" method="post">';
24 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
25 echo 'Search whole database for: <input type="text" name="search" /><br />';
26 echo 'Replace with this string: <input type="text" name="replace" /><br />';
27 echo '<input type="submit" value="Yes, do it now" /><br />';
28 echo '</form>';
29 echo '</div>';
30 print_simple_box_end();
31 admin_externalpage_print_footer();
32 die;
36 if (!$tables = $db->Metatables() ) { // No tables yet at all.
37 error("no tables");
40 print_simple_box_start('center');
42 /// Turn off time limits, sometimes upgrades can be slow.
44 @set_time_limit(0);
45 @ob_implicit_flush(true);
46 while(@ob_end_flush());
48 foreach ($tables as $table) {
49 if (in_array($table, array($CFG->prefix.'config'))) { // Don't process these
50 continue;
52 if ($columns = $db->MetaColumns($table, false)) {
53 foreach ($columns as $column => $data) {
54 if (in_array($data->type, array('text','mediumtext','longtext','varchar'))) { // Text stuff only
55 $db->debug = true;
56 execute_sql("UPDATE $table SET $column = REPLACE($column, '$search', '$replace');");
57 $db->debug = false;
63 print_simple_box_end();
65 /// Rebuild course cache which might be incorrect now
66 notify('Rebuilding course cache...');
67 rebuild_course_cache();
68 notify('...finished');
70 print_continue('index.php');
72 admin_externalpage_print_footer();