e92c286c20
even non-course and sticky blocks. The parent context is block_instances.parentcontextid. The block context should be used for checking permissions directly related to the block, like moodle/block:view or moodle/site:manageblocks. However, if the block is displaying information about the current page, for example the participants block showing who 'here', then it may be better to use the context of the page where the bloack is appearing - in other words $this->page->context - to check permissions about the user's ability to see participants here. Or, if the block is displaying something stronly related to courses, for example, a course meny block, the block should probably use the context for $this->page->course to check permissions.
63 lines
2.0 KiB
PHP
63 lines
2.0 KiB
PHP
<?php /// $Id$
|
|
/// Search and replace strings throughout all texts in the whole database
|
|
|
|
require_once('../config.php');
|
|
require_once($CFG->dirroot.'/course/lib.php');
|
|
require_once($CFG->libdir.'/adminlib.php');
|
|
|
|
admin_externalpage_setup('replace');
|
|
|
|
$search = optional_param('search', '', PARAM_RAW);
|
|
$replace = optional_param('replace', '', PARAM_RAW);
|
|
|
|
###################################################################
|
|
admin_externalpage_print_header();
|
|
|
|
print_heading('Search and replace text throughout the whole database');
|
|
|
|
|
|
if (!data_submitted() or !$search or !$replace or !confirm_sesskey()) { /// Print a form
|
|
|
|
print_simple_box_start('center');
|
|
echo '<div class="mdl-align">';
|
|
echo '<form action="replace.php" method="post">';
|
|
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
|
|
echo 'Search whole database for: <input type="text" name="search" /><br />';
|
|
echo 'Replace with this string: <input type="text" name="replace" /><br />';
|
|
echo '<input type="submit" value="Yes, do it now" /><br />';
|
|
echo '</form>';
|
|
echo '</div>';
|
|
print_simple_box_end();
|
|
admin_externalpage_print_footer();
|
|
die;
|
|
}
|
|
|
|
print_simple_box_start('center');
|
|
|
|
if (!db_replace($search, $replace)) {
|
|
print_error('erroroccur', debug);
|
|
}
|
|
|
|
print_simple_box_end();
|
|
|
|
/// Try to replace some well-known serialised contents (html blocks)
|
|
notify('Replacing in html blocks...');
|
|
$instances = $DB->get_recordset('block_instances', array('blockname' => 'html'));
|
|
foreach ($instances as $instance) {
|
|
$blockobject = block_instance('html', $instance);
|
|
$blockobject->config->text = str_replace($search, $replace, $blockobject->config->text);
|
|
$blockobject->instance_config_commit();
|
|
}
|
|
$instances->close();
|
|
|
|
/// Rebuild course cache which might be incorrect now
|
|
notify('Rebuilding course cache...', 'notifysuccess');
|
|
rebuild_course_cache();
|
|
notify('...finished', 'notifysuccess');
|
|
|
|
print_continue('index.php');
|
|
|
|
admin_externalpage_print_footer();
|
|
|
|
?>
|