2009-11-01 10:57:00 +00:00
< ? php
2005-01-16 13:49:30 +00:00
/// Search and replace strings throughout all texts in the whole database
2010-11-19 03:40:43 +00:00
define ( 'NO_OUTPUT_BUFFERING' , true );
2006-03-06 19:27:25 +00:00
require_once ( '../config.php' );
2006-09-25 20:22:55 +00:00
require_once ( $CFG -> dirroot . '/course/lib.php' );
require_once ( $CFG -> libdir . '/adminlib.php' );
2007-04-30 17:08:34 +00:00
admin_externalpage_setup ( 'replace' );
2005-01-16 13:49:30 +00:00
2006-03-06 19:27:25 +00:00
$search = optional_param ( 'search' , '' , PARAM_RAW );
$replace = optional_param ( 'replace' , '' , PARAM_RAW );
2011-03-14 00:51:42 +01:00
$sure = optional_param ( 'sure' , 0 , PARAM_BOOL );
2005-01-16 13:49:30 +00:00
###################################################################
2010-03-31 08:05:53 +00:00
echo $OUTPUT -> header ();
2005-01-16 13:49:30 +00:00
2009-08-06 08:17:12 +00:00
echo $OUTPUT -> heading ( 'Search and replace text throughout the whole database' );
2005-01-16 13:49:30 +00:00
2011-03-14 00:51:42 +01:00
if ( $DB -> get_dbfamily () !== 'mysql' and $DB -> get_dbfamily () !== 'postgres' ) {
//TODO: add $DB->text_replace() to DML drivers
echo $OUTPUT -> notification ( 'Sorry, this feature is implemented only for MySQL and PostgreSQL databases.' );
echo $OUTPUT -> footer ();
die ;
}
2006-09-25 20:22:55 +00:00
2011-03-14 00:51:42 +01:00
if ( ! data_submitted () or ! $search or ! $replace or ! confirm_sesskey () or ! $sure ) { /// Print a form
echo $OUTPUT -> notification ( 'This script is not supported, always make complete backup before proceeding!<br />This operations can not be rewerted!' );
2005-01-16 13:49:30 +00:00
2009-08-18 04:28:40 +00:00
echo $OUTPUT -> box_start ();
2008-12-10 06:48:54 +00:00
echo '<div class="mdl-align">' ;
2011-03-14 00:51:42 +01:00
echo '<form action="replace.php" method="post"><div>' ;
2009-01-02 10:36:25 +00:00
echo '<input type="hidden" name="sesskey" value="' . sesskey () . '" />' ;
2011-03-14 00:51:42 +01:00
echo '<div><label for="search">Search whole database for: </label><input id="search" type="text" name="search" size="40" /> (usually previous server URL)</div>' ;
echo '<div><label for="replace">Replace with this string: </label><input type="text" id="replace" name="replace" size="40" /> (usually new server URL)</div>' ;
echo '<div><label for="sure">I understand the risks of this operation: </label><input type="checkbox" id="sure" name="sure" value="1" /></div>' ;
echo '<div class="buttons"><input type="submit" class="singlebutton" value="Yes, do it now" /></div>' ;
echo '</div></form>' ;
2005-01-16 13:49:30 +00:00
echo '</div>' ;
2009-08-18 04:28:40 +00:00
echo $OUTPUT -> box_end ();
2009-08-06 14:12:46 +00:00
echo $OUTPUT -> footer ();
2005-01-16 13:49:30 +00:00
die ;
}
2009-08-18 04:28:40 +00:00
echo $OUTPUT -> box_start ();
2011-03-14 00:51:42 +01:00
db_replace ( $search , $replace );
2009-08-18 04:28:40 +00:00
echo $OUTPUT -> box_end ();
2005-01-16 13:49:30 +00:00
2006-09-25 20:22:55 +00:00
/// Rebuild course cache which might be incorrect now
2009-08-18 04:28:40 +00:00
echo $OUTPUT -> notification ( 'Rebuilding course cache...' , 'notifysuccess' );
2006-09-25 20:22:55 +00:00
rebuild_course_cache ();
2009-08-18 04:28:40 +00:00
echo $OUTPUT -> notification ( '...finished' , 'notifysuccess' );
2006-09-25 20:22:55 +00:00
2009-08-18 04:28:40 +00:00
echo $OUTPUT -> continue_button ( 'index.php' );
2005-01-16 13:49:30 +00:00
2009-08-06 14:12:46 +00:00
echo $OUTPUT -> footer ();
2006-09-25 20:22:55 +00:00
2009-11-01 10:57:00 +00:00