MDL-26825 do not return any form data if form cancelled
[moodle.git] / admin / replace.php
blob8217876de049c6bf2d67e31aadb0741f01bd6259
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);
14 $sure = optional_param('sure', 0, PARAM_BOOL);
16 ###################################################################
17 echo $OUTPUT->header();
19 echo $OUTPUT->heading('Search and replace text throughout the whole database');
21 if ($DB->get_dbfamily() !== 'mysql' and $DB->get_dbfamily() !== 'postgres') {
22 //TODO: add $DB->text_replace() to DML drivers
23 echo $OUTPUT->notification('Sorry, this feature is implemented only for MySQL and PostgreSQL databases.');
24 echo $OUTPUT->footer();
25 die;
28 if (!data_submitted() or !$search or !$replace or !confirm_sesskey() or !$sure) { /// Print a form
29 echo $OUTPUT->notification('This script is not supported, always make complete backup before proceeding!<br />This operation can not be reverted!');
31 echo $OUTPUT->box_start();
32 echo '<div class="mdl-align">';
33 echo '<form action="replace.php" method="post"><div>';
34 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
35 echo '<div><label for="search">Search whole database for: </label><input id="search" type="text" name="search" size="40" /> (usually previous server URL)</div>';
36 echo '<div><label for="replace">Replace with this string: </label><input type="text" id="replace" name="replace" size="40" /> (usually new server URL)</div>';
37 echo '<div><label for="sure">I understand the risks of this operation: </label><input type="checkbox" id="sure" name="sure" value="1" /></div>';
38 echo '<div class="buttons"><input type="submit" class="singlebutton" value="Yes, do it now" /></div>';
39 echo '</div></form>';
40 echo '</div>';
41 echo $OUTPUT->box_end();
42 echo $OUTPUT->footer();
43 die;
46 echo $OUTPUT->box_start();
47 db_replace($search, $replace);
48 echo $OUTPUT->box_end();
50 /// Rebuild course cache which might be incorrect now
51 echo $OUTPUT->notification('Rebuilding course cache...', 'notifysuccess');
52 rebuild_course_cache();
53 echo $OUTPUT->notification('...finished', 'notifysuccess');
55 echo $OUTPUT->continue_button('index.php');
57 echo $OUTPUT->footer();