MDL-19101 scale selection validated on category edit form; merged from MOODLE_19_STABLE
[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
c9a49cea 16print_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
21 print_simple_box_start('center');
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>';
30 print_simple_box_end();
1ae083e4 31 admin_externalpage_print_footer();
04337d75 32 die;
33}
34
04337d75 35print_simple_box_start('center');
c9a49cea 36
1d8bf5f0 37if (!db_replace($search, $replace)) {
8e9d88f2 38 print_error('erroroccur', debug);
04337d75 39}
3f5edbdf 40
04337d75 41print_simple_box_end();
42
36fa1785 43/// Try to replace some well-known serialised contents (html blocks)
44notify('Replacing in html blocks...');
45$sql = "SELECT bi.*
66b10689 46 FROM {block_instance_old} bi
ffdd703a 47 JOIN {block} b ON b.id = bi.blockid
36fa1785 48 WHERE b.name = 'html'";
49if ($instances = $DB->get_records_sql($sql)) {
50 foreach ($instances as $instance) {
51 $blockobject = block_instance('html', $instance);
52 $blockobject->config->text = str_replace($search, $replace, $blockobject->config->text);
53 $blockobject->instance_config_commit($blockobject->pinned);
54 }
55}
56
c9a49cea 57/// Rebuild course cache which might be incorrect now
f33e1ed4 58notify('Rebuilding course cache...', 'notifysuccess');
c9a49cea 59rebuild_course_cache();
f33e1ed4 60notify('...finished', 'notifysuccess');
c9a49cea 61
04337d75 62print_continue('index.php');
63
1ae083e4 64admin_externalpage_print_footer();
c9a49cea 65
04337d75 66?>