MDL-29509 new admin tool manager UI
[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);
c3b5e829 14$sure = optional_param('sure', 0, PARAM_BOOL);
04337d75 15
04337d75 16###################################################################
61ef8f9f 17echo $OUTPUT->header();
04337d75 18
2fff8846 19echo $OUTPUT->heading('Search and replace text throughout the whole database');
04337d75 20
c3b5e829
PS
21if ($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;
26}
c9a49cea 27
c3b5e829 28if (!data_submitted() or !$search or !$replace or !confirm_sesskey() or !$sure) { /// Print a form
00801187 29 echo $OUTPUT->notification('This script is not supported, always make complete backup before proceeding!<br />This operation can not be reverted!');
04337d75 30
8fbce1c8 31 echo $OUTPUT->box_start();
85db96c5 32 echo '<div class="mdl-align">';
c3b5e829 33 echo '<form action="replace.php" method="post"><div>';
d4a1fcaf 34 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
c3b5e829
PS
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>';
04337d75 40 echo '</div>';
8fbce1c8 41 echo $OUTPUT->box_end();
73d6f52f 42 echo $OUTPUT->footer();
04337d75 43 die;
44}
45
8fbce1c8 46echo $OUTPUT->box_start();
c3b5e829 47db_replace($search, $replace);
8fbce1c8 48echo $OUTPUT->box_end();
04337d75 49
c9a49cea 50/// Rebuild course cache which might be incorrect now
8fbce1c8 51echo $OUTPUT->notification('Rebuilding course cache...', 'notifysuccess');
c9a49cea 52rebuild_course_cache();
8fbce1c8 53echo $OUTPUT->notification('...finished', 'notifysuccess');
c9a49cea 54
8fbce1c8 55echo $OUTPUT->continue_button('index.php');
04337d75 56
73d6f52f 57echo $OUTPUT->footer();
c9a49cea 58
20207b82 59