MDL-7861, adding missing tag
[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');
c9a49cea 5require_once($CFG->dirroot.'/course/lib.php');
6require_once($CFG->libdir.'/adminlib.php');
7$adminroot = admin_get_root();
8admin_externalpage_setup('replace', $adminroot);
04337d75 9
a2eaae61 10$search = optional_param('search', '', PARAM_RAW);
11$replace = optional_param('replace', '', PARAM_RAW);
04337d75 12
13require_login();
14
41d7209c 15require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID));
04337d75 16
17###################################################################
c9a49cea 18admin_externalpage_print_header($adminroot);
04337d75 19
c9a49cea 20print_heading('Search and replace text throughout the whole database');
04337d75 21
c9a49cea 22
23if (!data_submitted() or !$search or !$replace or !confirm_sesskey()) { /// Print a form
04337d75 24
25 print_simple_box_start('center');
26 echo '<div align="center">';
c9a49cea 27 echo '<form action="replace.php" method="post">';
04337d75 28 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'">';
29 echo 'Search whole database for: <input type="text" name="search"><br />';
30 echo 'Replace with this string: <input type="text" name="replace"><br /></br />';
31 echo '<input type="submit" value="Yes, do it now"><br />';
32 echo '</form>';
33 echo '</div>';
34 print_simple_box_end();
c9a49cea 35 admin_externalpage_print_footer($adminroot);
04337d75 36 die;
37}
38
39
40if (!$tables = $db->Metatables() ) { // No tables yet at all.
41 error("no tables");
42}
43
44print_simple_box_start('center');
c9a49cea 45
46/// Turn off time limits, sometimes upgrades can be slow.
47
48@set_time_limit(0);
49@ob_implicit_flush(true);
50while(@ob_end_flush());
51
04337d75 52foreach ($tables as $table) {
53 if (in_array($table, array($CFG->prefix.'config'))) { // Don't process these
54 continue;
55 }
56 if ($columns = $db->MetaColumns($table, false)) {
57 foreach ($columns as $column => $data) {
58 if (in_array($data->type, array('text','mediumtext','longtext','varchar'))) { // Text stuff only
59 $db->debug = true;
a37b4c5b 60 execute_sql("UPDATE $table SET $column = REPLACE($column, '$search', '$replace');");
04337d75 61 $db->debug = false;
62 }
63 }
64 }
65}
3f5edbdf 66
04337d75 67print_simple_box_end();
68
c9a49cea 69/// Rebuild course cache which might be incorrect now
70notify('Rebuilding course cache...');
71rebuild_course_cache();
72notify('...finished');
73
04337d75 74print_continue('index.php');
75
c9a49cea 76admin_externalpage_print_footer($adminroot);
77
04337d75 78?>