Some more strings added...related with the View PHP utility
[moodle.git] / admin / replace.php
CommitLineData
04337d75 1<?php /// $Id$
2 /// Search and replace strings throughout all texts in the whole database
3
a2eaae61 4require_once('../config.php');
04337d75 5
a2eaae61 6$search = optional_param('search', '', PARAM_RAW);
7$replace = optional_param('replace', '', PARAM_RAW);
04337d75 8
9require_login();
10
41d7209c 11require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID));
04337d75 12
13###################################################################
14print_header('Search and replace throughout the whole database', 'Replace text within the whole database');
15
16
17if (!$search or !$replace or !confirm_sesskey()) { /// Print a form
18
19 print_simple_box_start('center');
20 echo '<div align="center">';
21 echo '<form action="replace.php">';
22 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'">';
23 echo 'Search whole database for: <input type="text" name="search"><br />';
24 echo 'Replace with this string: <input type="text" name="replace"><br /></br />';
25 echo '<input type="submit" value="Yes, do it now"><br />';
26 echo '</form>';
27 echo '</div>';
28 print_simple_box_end();
29 die;
30}
31
32
33if (!$tables = $db->Metatables() ) { // No tables yet at all.
34 error("no tables");
35}
36
37print_simple_box_start('center');
38foreach ($tables as $table) {
39 if (in_array($table, array($CFG->prefix.'config'))) { // Don't process these
40 continue;
41 }
42 if ($columns = $db->MetaColumns($table, false)) {
43 foreach ($columns as $column => $data) {
44 if (in_array($data->type, array('text','mediumtext','longtext','varchar'))) { // Text stuff only
45 $db->debug = true;
a37b4c5b 46 execute_sql("UPDATE $table SET $column = REPLACE($column, '$search', '$replace');");
04337d75 47 $db->debug = false;
48 }
49 }
50 }
51}
3f5edbdf 52
53/// Clear course cache which might be corrupted now
54execute_sql("UPDATE ".$CFG->prefix."course SET modinfo = '' WHERE id <> ".SITEID);
55
04337d75 56print_simple_box_end();
57
58print_continue('index.php');
59
60?>