MDL-26271 fix borked sql parameters in forum_search_posts and add missing modinfo...
[moodle.git] / admin / replace.php
blobe77070b11d990eb4197e2aa58b3781bcbee210c0
1 <?php
2 /// Search and replace strings throughout all texts in the whole database
4 define('NO_OUTPUT_BUFFERING', true);
6 require_once('../config.php');
7 require_once($CFG->dirroot.'/course/lib.php');
8 require_once($CFG->libdir.'/adminlib.php');
10 admin_externalpage_setup('replace');
12 $search = optional_param('search', '', PARAM_RAW);
13 $replace = optional_param('replace', '', PARAM_RAW);
15 ###################################################################
16 echo $OUTPUT->header();
18 echo $OUTPUT->heading('Search and replace text throughout the whole database');
21 if (!data_submitted() or !$search or !$replace or !confirm_sesskey()) { /// Print a form
23 echo $OUTPUT->box_start();
24 echo '<div class="mdl-align">';
25 echo '<form action="replace.php" method="post">';
26 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
27 echo 'Search whole database for: <input type="text" name="search" /><br />';
28 echo 'Replace with this string: <input type="text" name="replace" /><br />';
29 echo '<input type="submit" value="Yes, do it now" /><br />';
30 echo '</form>';
31 echo '</div>';
32 echo $OUTPUT->box_end();
33 echo $OUTPUT->footer();
34 die;
37 echo $OUTPUT->box_start();
39 if (!db_replace($search, $replace)) {
40 print_error('erroroccur', debug);
43 echo $OUTPUT->box_end();
45 /// Try to replace some well-known serialised contents (html blocks)
46 echo $OUTPUT->notification('Replacing in html blocks...');
47 $instances = $DB->get_recordset('block_instances', array('blockname' => 'html'));
48 foreach ($instances as $instance) {
49 $blockobject = block_instance('html', $instance);
50 $blockobject->config->text = str_replace($search, $replace, $blockobject->config->text);
51 $blockobject->instance_config_commit();
53 $instances->close();
55 /// Rebuild course cache which might be incorrect now
56 echo $OUTPUT->notification('Rebuilding course cache...', 'notifysuccess');
57 rebuild_course_cache();
58 echo $OUTPUT->notification('...finished', 'notifysuccess');
60 echo $OUTPUT->continue_button('index.php');
62 echo $OUTPUT->footer();