Fix a possible race condition in the PaintWeb DML code.
[moodle/mihaisucan.git] / admin / replace.php
blob4c0ec39c510b9cdb8e46f104ebee8fd99d36d0be
1 <?php /// $Id$
2 /// Search and replace strings throughout all texts in the whole database
4 require_once('../config.php');
5 require_once($CFG->dirroot.'/course/lib.php');
6 require_once($CFG->libdir.'/adminlib.php');
8 // workaround for problems with compression
9 if (ini_get('zlib.output_compression')) {
10 @ini_set('zlib.output_compression', 'Off');
13 admin_externalpage_setup('replace');
15 $search = optional_param('search', '', PARAM_RAW);
16 $replace = optional_param('replace', '', PARAM_RAW);
18 ###################################################################
19 admin_externalpage_print_header();
21 print_heading('Search and replace text throughout the whole database');
24 if (!data_submitted() or !$search or !$replace or !confirm_sesskey()) { /// Print a form
26 print_simple_box_start('center');
27 echo '<div class="mdl-align">';
28 echo '<form action="replace.php" method="post">';
29 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
30 echo 'Search whole database for: <input type="text" name="search" /><br />';
31 echo 'Replace with this string: <input type="text" name="replace" /><br />';
32 echo '<input type="submit" value="Yes, do it now" /><br />';
33 echo '</form>';
34 echo '</div>';
35 print_simple_box_end();
36 admin_externalpage_print_footer();
37 die;
40 print_simple_box_start('center');
42 if (!db_replace($search, $replace)) {
43 error('An error has occured during this process');
46 print_simple_box_end();
48 /// Try to replace some well-known serialised contents (html blocks)
49 notify('Replacing in html blocks...');
50 $sql = "SELECT bi.*
51 FROM {$CFG->prefix}block_instance bi
52 JOIN {$CFG->prefix}block b ON b.id = bi.blockid
53 WHERE b.name = 'html'";
54 if ($instances = get_records_sql($sql)) {
55 foreach ($instances as $instance) {
56 $blockobject = block_instance('html', $instance);
57 $blockobject->config->text = str_replace($search, $replace, $blockobject->config->text);
58 $blockobject->instance_config_commit($blockobject->pinned);
62 /// Rebuild course cache which might be incorrect now
63 notify('Rebuilding course cache...');
64 rebuild_course_cache();
65 notify('...finished');
67 print_continue('index.php');
69 admin_externalpage_print_footer();