|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00026 define('NO_OUTPUT_BUFFERING', true); 00027 00028 require_once('../../../config.php'); 00029 require_once($CFG->dirroot.'/course/lib.php'); 00030 require_once($CFG->libdir.'/adminlib.php'); 00031 00032 admin_externalpage_setup('toolreplace'); 00033 00034 $search = optional_param('search', '', PARAM_RAW); 00035 $replace = optional_param('replace', '', PARAM_RAW); 00036 $sure = optional_param('sure', 0, PARAM_BOOL); 00037 00038 ################################################################### 00039 echo $OUTPUT->header(); 00040 00041 echo $OUTPUT->heading('Search and replace text throughout the whole database'); 00042 00043 if ($DB->get_dbfamily() !== 'mysql' and $DB->get_dbfamily() !== 'postgres') { 00044 //TODO: add $DB->text_replace() to DML drivers 00045 echo $OUTPUT->notification('Sorry, this feature is implemented only for MySQL and PostgreSQL databases.'); 00046 echo $OUTPUT->footer(); 00047 die; 00048 } 00049 00050 if (!data_submitted() or !$search or !$replace or !confirm_sesskey() or !$sure) { 00051 echo $OUTPUT->notification('This script is not supported, always make complete backup before proceeding!<br />This operation can not be reverted!'); 00052 00053 echo $OUTPUT->box_start(); 00054 echo '<div class="mdl-align">'; 00055 echo '<form action="index.php" method="post"><div>'; 00056 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />'; 00057 echo '<div><label for="search">Search whole database for: </label><input id="search" type="text" name="search" size="40" /> (usually previous server URL)</div>'; 00058 echo '<div><label for="replace">Replace with this string: </label><input type="text" id="replace" name="replace" size="40" /> (usually new server URL)</div>'; 00059 echo '<div><label for="sure">I understand the risks of this operation: </label><input type="checkbox" id="sure" name="sure" value="1" /></div>'; 00060 echo '<div class="buttons"><input type="submit" class="singlebutton" value="Yes, do it now" /></div>'; 00061 echo '</div></form>'; 00062 echo '</div>'; 00063 echo $OUTPUT->box_end(); 00064 echo $OUTPUT->footer(); 00065 die; 00066 } 00067 00068 echo $OUTPUT->box_start(); 00069 db_replace($search, $replace); 00070 echo $OUTPUT->box_end(); 00071 00073 echo $OUTPUT->notification('Rebuilding course cache...', 'notifysuccess'); 00074 rebuild_course_cache(); 00075 echo $OUTPUT->notification('...finished', 'notifysuccess'); 00076 00077 echo $OUTPUT->continue_button(new moodle_url('/admin/index.php')); 00078 00079 echo $OUTPUT->footer(); 00080 00081