weekly release
[moodle.git] / admin / replace.php
CommitLineData
20207b82 1<?php
04337d75 2 /// Search and replace strings throughout all texts in the whole database
3
cbad562e
PS
4define('NO_OUTPUT_BUFFERING', true);
5
a2eaae61 6require_once('../config.php');
c9a49cea 7require_once($CFG->dirroot.'/course/lib.php');
8require_once($CFG->libdir.'/adminlib.php');
1ae083e4 9
10admin_externalpage_setup('replace');
04337d75 11
a2eaae61 12$search = optional_param('search', '', PARAM_RAW);
13$replace = optional_param('replace', '', PARAM_RAW);
04337d75 14
04337d75 15###################################################################
61ef8f9f 16echo $OUTPUT->header();
04337d75 17
2fff8846 18echo $OUTPUT->heading('Search and replace text throughout the whole database');
04337d75 19
c9a49cea 20
21if (!data_submitted() or !$search or !$replace or !confirm_sesskey()) { /// Print a form
04337d75 22
8fbce1c8 23 echo $OUTPUT->box_start();
85db96c5 24 echo '<div class="mdl-align">';
c9a49cea 25 echo '<form action="replace.php" method="post">';
d4a1fcaf 26 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
b1b5e868 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 />';
04337d75 30 echo '</form>';
31 echo '</div>';
8fbce1c8 32 echo $OUTPUT->box_end();
73d6f52f 33 echo $OUTPUT->footer();
04337d75 34 die;
35}
36
8fbce1c8 37echo $OUTPUT->box_start();
c9a49cea 38
1d8bf5f0 39if (!db_replace($search, $replace)) {
8e9d88f2 40 print_error('erroroccur', debug);
04337d75 41}
3f5edbdf 42
8fbce1c8 43echo $OUTPUT->box_end();
04337d75 44
36fa1785 45/// Try to replace some well-known serialised contents (html blocks)
8fbce1c8 46echo $OUTPUT->notification('Replacing in html blocks...');
f474a4e5 47$instances = $DB->get_recordset('block_instances', array('blockname' => 'html'));
48foreach ($instances as $instance) {
49 $blockobject = block_instance('html', $instance);
50 $blockobject->config->text = str_replace($search, $replace, $blockobject->config->text);
e92c286c 51 $blockobject->instance_config_commit();
36fa1785 52}
f474a4e5 53$instances->close();
36fa1785 54
c9a49cea 55/// Rebuild course cache which might be incorrect now
8fbce1c8 56echo $OUTPUT->notification('Rebuilding course cache...', 'notifysuccess');
c9a49cea 57rebuild_course_cache();
8fbce1c8 58echo $OUTPUT->notification('...finished', 'notifysuccess');
c9a49cea 59
8fbce1c8 60echo $OUTPUT->continue_button('index.php');
04337d75 61
73d6f52f 62echo $OUTPUT->footer();
c9a49cea 63
20207b82 64