MDL-20700 coding style cleanup - cvs keywords removed, closign php tag removed, trail...
[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');
1ae083e4 7
8admin_externalpage_setup('replace');
04337d75 9
a2eaae61 10$search = optional_param('search', '', PARAM_RAW);
11$replace = optional_param('replace', '', PARAM_RAW);
04337d75 12
04337d75 13###################################################################
1ae083e4 14admin_externalpage_print_header();
04337d75 15
2fff8846 16echo $OUTPUT->heading('Search and replace text throughout the whole database');
04337d75 17
c9a49cea 18
19if (!data_submitted() or !$search or !$replace or !confirm_sesskey()) { /// Print a form
04337d75 20
8fbce1c8 21 echo $OUTPUT->box_start();
85db96c5 22 echo '<div class="mdl-align">';
c9a49cea 23 echo '<form action="replace.php" method="post">';
d4a1fcaf 24 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
b1b5e868 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 />';
04337d75 28 echo '</form>';
29 echo '</div>';
8fbce1c8 30 echo $OUTPUT->box_end();
73d6f52f 31 echo $OUTPUT->footer();
04337d75 32 die;
33}
34
8fbce1c8 35echo $OUTPUT->box_start();
c9a49cea 36
1d8bf5f0 37if (!db_replace($search, $replace)) {
8e9d88f2 38 print_error('erroroccur', debug);
04337d75 39}
3f5edbdf 40
8fbce1c8 41echo $OUTPUT->box_end();
04337d75 42
36fa1785 43/// Try to replace some well-known serialised contents (html blocks)
8fbce1c8 44echo $OUTPUT->notification('Replacing in html blocks...');
f474a4e5 45$instances = $DB->get_recordset('block_instances', array('blockname' => 'html'));
46foreach ($instances as $instance) {
47 $blockobject = block_instance('html', $instance);
48 $blockobject->config->text = str_replace($search, $replace, $blockobject->config->text);
e92c286c 49 $blockobject->instance_config_commit();
36fa1785 50}
f474a4e5 51$instances->close();
36fa1785 52
c9a49cea 53/// Rebuild course cache which might be incorrect now
8fbce1c8 54echo $OUTPUT->notification('Rebuilding course cache...', 'notifysuccess');
c9a49cea 55rebuild_course_cache();
8fbce1c8 56echo $OUTPUT->notification('...finished', 'notifysuccess');
c9a49cea 57
8fbce1c8 58echo $OUTPUT->continue_button('index.php');
04337d75 59
73d6f52f 60echo $OUTPUT->footer();
c9a49cea 61
04337d75 62?>