本文整理汇总了PHP中capabilities_cleanup函数的典型用法代码示例。如果您正苦于以下问题:PHP capabilities_cleanup函数的具体用法?PHP capabilities_cleanup怎么用?PHP capabilities_cleanup使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了capabilities_cleanup函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: xmldb_report_participation_install
function xmldb_report_participation_install() {
global $DB;
// this is a hack which is needed for cleanup of original coursereport_participation stuff
unset_all_config_for_plugin('coursereport_participation');
capabilities_cleanup('coursereport_participation');
// update existing block page patterns
$DB->set_field('block_instances', 'pagetypepattern', 'report-participation-index', array('pagetypepattern'=>'course-report-participation-index'));
}
示例2: xmldb_tool_unittest_install
function xmldb_tool_unittest_install()
{
global $CFG;
// this is a hack - this plugin used to live in admin/report/unittest,
// we want to remove the orphaned version info and capability
// unless there is a new report type with the same name
if (!file_exists("{$CFG->dirroot}/report/unittest")) {
unset_all_config_for_plugin('report_unittest');
capabilities_cleanup('report_unittest');
}
}
示例3: xmldb_report_editdates_install
function xmldb_report_editdates_install()
{
global $DB;
// This is a hack to copy the permission from the old place, if they were present.
// If this report is installed into a new Moodle, we just do what it says in access.php
// and clone the permissions from moodle/site:viewreports, but if we are upgrading
// a Moodle that had the old course report plugin installed, then we get rid of the
// new cloned capabilities, and transfer the old permissions.
if ($DB->record_exists('role_capabilities', array('capability' => 'coursereport/editdates:view'))) {
$DB->delete_records('role_capabilities', array('capability' => 'report/editdates:view'));
$DB->set_field('role_capabilities', 'capability', 'report/editdates:view', array('capability' => 'coursereport/editdates:view'));
}
// This is a hack which is needed for cleanup of original coursereport_completion stuff.
unset_all_config_for_plugin('coursereport_editdates');
capabilities_cleanup('coursereport_editdates');
// Update existing block page patterns.
$DB->set_field('block_instances', 'pagetypepattern', 'report-editdates-index', array('pagetypepattern' => 'course-report-editdates-index'));
}
示例4: xmldb_tool_customlang_install
function xmldb_tool_customlang_install()
{
global $CFG, $OUTPUT, $DB;
// this is a hack - this plugin used to live in admin/report/customlang,
// we want to remove the orphaned version info and capability
// unless there is a new report type with the same name
// the original tables can be dropped because they are used for caching only
if (!file_exists("{$CFG->dirroot}/report/customlang")) {
unset_all_config_for_plugin('report_customlang');
capabilities_cleanup('report_customlang');
$dbman = $DB->get_manager();
$table = new xmldb_table('report_customlang');
if ($dbman->table_exists($table)) {
$dbman->drop_table($table);
}
$table = new xmldb_table('report_customlang_components');
if ($dbman->table_exists($table)) {
$dbman->drop_table($table);
}
}
}
示例5: uninstall_plugin
//.........这里部分代码省略.........
}
// clear course.modinfo for courses that used this module
$sql = "UPDATE {course}\n SET modinfo=''\n WHERE id IN (SELECT DISTINCT course\n FROM {course_modules}\n WHERE module=?)";
$DB->execute($sql, array($module->id));
// delete all the course module records
$DB->delete_records('course_modules', array('module' => $module->id));
// delete module contexts
if ($coursemods) {
foreach ($coursemods as $coursemod) {
if (!delete_context(CONTEXT_MODULE, $coursemod->id)) {
echo $OUTPUT->notification("Could not delete the context for {$strpluginname} with id = {$coursemod->id}");
}
}
}
// delete the module entry itself
$DB->delete_records('modules', array('name' => $module->name));
// cleanup the gradebook
require_once $CFG->libdir . '/gradelib.php';
grade_uninstalled_module($module->name);
// Perform any custom uninstall tasks
if (file_exists($CFG->dirroot . '/mod/' . $module->name . '/lib.php')) {
require_once $CFG->dirroot . '/mod/' . $module->name . '/lib.php';
$uninstallfunction = $module->name . '_uninstall';
if (function_exists($uninstallfunction)) {
debugging("{$uninstallfunction}() has been deprecated. Use the plugin's db/uninstall.php instead", DEBUG_DEVELOPER);
if (!$uninstallfunction()) {
echo $OUTPUT->notification('Encountered a problem running uninstall function for ' . $module->name . '!');
}
}
}
} else {
if ($type === 'enrol') {
// NOTE: this is a bit brute force way - it will not trigger events and hooks properly
// nuke all role assignments
role_unassign_all(array('component' => $component));
// purge participants
$DB->delete_records_select('user_enrolments', "enrolid IN (SELECT id FROM {enrol} WHERE enrol = ?)", array($name));
// purge enrol instances
$DB->delete_records('enrol', array('enrol' => $name));
// tweak enrol settings
if (!empty($CFG->enrol_plugins_enabled)) {
$enabledenrols = explode(',', $CFG->enrol_plugins_enabled);
$enabledenrols = array_unique($enabledenrols);
$enabledenrols = array_flip($enabledenrols);
unset($enabledenrols[$name]);
$enabledenrols = array_flip($enabledenrols);
if (is_array($enabledenrols)) {
set_config('enrol_plugins_enabled', implode(',', $enabledenrols));
}
}
} else {
if ($type === 'block') {
if ($block = $DB->get_record('block', array('name' => $name))) {
// Inform block it's about to be deleted
if (file_exists("{$CFG->dirroot}/blocks/{$block->name}/block_{$block->name}.php")) {
$blockobject = block_instance($block->name);
if ($blockobject) {
$blockobject->before_delete();
//only if we can create instance, block might have been already removed
}
}
// First delete instances and related contexts
$instances = $DB->get_records('block_instances', array('blockname' => $block->name));
foreach ($instances as $instance) {
blocks_delete_instance($instance);
}
// Delete block
$DB->delete_records('block', array('id' => $block->id));
}
}
}
}
// perform clean-up task common for all the plugin/subplugin types
// delete calendar events
$DB->delete_records('event', array('modulename' => $pluginname));
// delete all the logs
$DB->delete_records('log', array('module' => $pluginname));
// delete log_display information
$DB->delete_records('log_display', array('component' => $component));
// delete the module configuration records
unset_all_config_for_plugin($pluginname);
// delete message provider
message_provider_uninstall($component);
// delete message processor
if ($type === 'message') {
message_processor_uninstall($name);
}
// delete the plugin tables
$xmldbfilepath = $plugindirectory . '/db/install.xml';
drop_plugin_tables($component, $xmldbfilepath, false);
if ($type === 'mod' or $type === 'block') {
// non-frankenstyle table prefixes
drop_plugin_tables($name, $xmldbfilepath, false);
}
// delete the capabilities that were defined by this module
capabilities_cleanup($component);
// remove event handlers and dequeue pending events
events_uninstall($component);
echo $OUTPUT->notification(get_string('success'), 'notifysuccess');
}
示例6: uninstall_plugin
//.........这里部分代码省略.........
core_php_time_limit::raise();
// Recursively uninstall all subplugins first.
$subplugintypes = core_component::get_plugin_types_with_subplugins();
if (isset($subplugintypes[$type])) {
$base = core_component::get_plugin_directory($type, $name);
if (file_exists("{$base}/db/subplugins.php")) {
$subplugins = array();
include "{$base}/db/subplugins.php";
foreach ($subplugins as $subplugintype => $dir) {
$instances = core_component::get_plugin_list($subplugintype);
foreach ($instances as $subpluginname => $notusedpluginpath) {
uninstall_plugin($subplugintype, $subpluginname);
}
}
}
}
$component = $type . '_' . $name;
// eg. 'qtype_multichoice' or 'workshopgrading_accumulative' or 'mod_forum'
if ($type === 'mod') {
$pluginname = $name;
// eg. 'forum'
if (get_string_manager()->string_exists('modulename', $component)) {
$strpluginname = get_string('modulename', $component);
} else {
$strpluginname = $component;
}
} else {
$pluginname = $component;
if (get_string_manager()->string_exists('pluginname', $component)) {
$strpluginname = get_string('pluginname', $component);
} else {
$strpluginname = $component;
}
}
echo $OUTPUT->heading($pluginname);
// Delete all tag instances associated with this plugin.
require_once $CFG->dirroot . '/tag/lib.php';
tag_delete_instances($component);
// Custom plugin uninstall.
$plugindirectory = core_component::get_plugin_directory($type, $name);
$uninstalllib = $plugindirectory . '/db/uninstall.php';
if (file_exists($uninstalllib)) {
require_once $uninstalllib;
$uninstallfunction = 'xmldb_' . $pluginname . '_uninstall';
// eg. 'xmldb_workshop_uninstall()'
if (function_exists($uninstallfunction)) {
// Do not verify result, let plugin complain if necessary.
$uninstallfunction();
}
}
// Specific plugin type cleanup.
$plugininfo = core_plugin_manager::instance()->get_plugin_info($component);
if ($plugininfo) {
$plugininfo->uninstall_cleanup();
core_plugin_manager::reset_caches();
}
$plugininfo = null;
// perform clean-up task common for all the plugin/subplugin types
//delete the web service functions and pre-built services
require_once $CFG->dirroot . '/lib/externallib.php';
external_delete_descriptions($component);
// delete calendar events
$DB->delete_records('event', array('modulename' => $pluginname));
// Delete scheduled tasks.
$DB->delete_records('task_scheduled', array('component' => $pluginname));
// Delete Inbound Message datakeys.
$DB->delete_records_select('messageinbound_datakeys', 'handler IN (SELECT id FROM {messageinbound_handlers} WHERE component = ?)', array($pluginname));
// Delete Inbound Message handlers.
$DB->delete_records('messageinbound_handlers', array('component' => $pluginname));
// delete all the logs
$DB->delete_records('log', array('module' => $pluginname));
// delete log_display information
$DB->delete_records('log_display', array('component' => $component));
// delete the module configuration records
unset_all_config_for_plugin($component);
if ($type === 'mod') {
unset_all_config_for_plugin($pluginname);
}
// delete message provider
message_provider_uninstall($component);
// delete the plugin tables
$xmldbfilepath = $plugindirectory . '/db/install.xml';
drop_plugin_tables($component, $xmldbfilepath, false);
if ($type === 'mod' or $type === 'block') {
// non-frankenstyle table prefixes
drop_plugin_tables($name, $xmldbfilepath, false);
}
// delete the capabilities that were defined by this module
capabilities_cleanup($component);
// remove event handlers and dequeue pending events
events_uninstall($component);
// Delete all remaining files in the filepool owned by the component.
$fs = get_file_storage();
$fs->delete_component_files($component);
// Finally purge all caches.
purge_all_caches();
// Invalidate the hash used for upgrade detections.
set_config('allversionshash', '');
echo $OUTPUT->notification(get_string('success'), 'notifysuccess');
}
示例7: xmldb_main_upgrade
//.........这里部分代码省略.........
// Drop unused table "course_completion_notify"
$table = new xmldb_table('course_completion_notify');
// Conditionally launch drop table course_completion_notify
if ($dbman->table_exists($table)) {
$dbman->drop_table($table);
}
// Main savepoint reached
upgrade_main_savepoint(true, 2012070600.08);
}
if ($oldversion < 2012070600.09) {
// Define index path (not unique) to be added to context
$table = new xmldb_table('context');
$index = new xmldb_index('path', XMLDB_INDEX_NOTUNIQUE, array('path'), array('varchar_pattern_ops'));
// Recreate index with new pattern hint
if ($DB->get_dbfamily() === 'postgres') {
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}
$dbman->add_index($table, $index);
}
// Main savepoint reached
upgrade_main_savepoint(true, 2012070600.09);
}
if ($oldversion < 2012070600.1) {
// Define index name (unique) to be dropped form role
$table = new xmldb_table('role');
$index = new xmldb_index('name', XMLDB_INDEX_UNIQUE, array('name'));
// Conditionally launch drop index name
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}
// Main savepoint reached
upgrade_main_savepoint(true, 2012070600.1);
}
if ($oldversion < 2012070600.11) {
// Define index component-itemid-userid (not unique) to be added to role_assignments
$table = new xmldb_table('role_assignments');
$index = new xmldb_index('component-itemid-userid', XMLDB_INDEX_NOTUNIQUE, array('component', 'itemid', 'userid'));
// Conditionally launch add index component-itemid-userid
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}
// Main savepoint reached
upgrade_main_savepoint(true, 2012070600.11);
}
if ($oldversion < 2012071900.01) {
// Cleanup after simpeltests tool
capabilities_cleanup('tool_unittest');
unset_all_config_for_plugin('tool_unittest');
upgrade_main_savepoint(true, 2012071900.01);
}
if ($oldversion < 2012072400.0) {
// Remove obsolete xhtml strict setting - use THEME->doctype in theme config if necessary,
// see theme_config->doctype in lib/outputlib.php for more details.
unset_config('xmlstrictheaders');
upgrade_main_savepoint(true, 2012072400.0);
}
if ($oldversion < 2012072401.0) {
// Saves orphaned questions from the Dark Side
upgrade_save_orphaned_questions();
// Main savepoint reached
upgrade_main_savepoint(true, 2012072401.0);
}
if ($oldversion < 2012072600.01) {
// Handle events with empty eventtype //MDL-32827
$DB->set_field('event', 'eventtype', 'site', array('eventtype' => '', 'courseid' => $SITE->id));
$DB->set_field_select('event', 'eventtype', 'due', "eventtype = '' AND courseid != 0 AND groupid = 0 AND (modulename = 'assignment' OR modulename = 'assign')");
$DB->set_field_select('event', 'eventtype', 'course', "eventtype = '' AND courseid != 0 AND groupid = 0");
$DB->set_field_select('event', 'eventtype', 'group', "eventtype = '' AND groupid != 0");
$DB->set_field_select('event', 'eventtype', 'user', "eventtype = '' AND userid != 0");
// Main savepoint reached
upgrade_main_savepoint(true, 2012072600.01);
}
if ($oldversion < 2012080200.02) {
// Drop obsolete question upgrade field that should have been added to the install.xml.
$table = new xmldb_table('question');
$field = new xmldb_field('oldquestiontextformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0');
if ($dbman->field_exists($table, $field)) {
$dbman->drop_field($table, $field);
}
upgrade_main_savepoint(true, 2012080200.02);
}
if ($oldversion < 2012081400.01) {
// Move the ability to disable blogs to its own setting MDL-25012.
if (isset($CFG->bloglevel)) {
// Only change settings if existing setting was set.
if (empty($CFG->bloglevel)) {
set_config('enableblogs', 0);
// Now set the bloglevel to a valid setting as the disabled setting has been removed.
// This prevents confusing results when users enable the blog system in future.
set_config('bloglevel', BLOG_USER_LEVEL);
} else {
set_config('enableblogs', 1);
}
}
// Main savepoint reached
upgrade_main_savepoint(true, 2012081400.01);
}
return true;
}
示例8: xmldb_main_upgrade
//.........这里部分代码省略.........
if ($DB->get_dbfamily() === 'postgres') {
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}
$dbman->add_index($table, $index);
}
// Main savepoint reached
upgrade_main_savepoint(true, 2012070600.09);
}
if ($oldversion < 2012070600.1) {
// Define index name (unique) to be dropped form role
$table = new xmldb_table('role');
$index = new xmldb_index('name', XMLDB_INDEX_UNIQUE, array('name'));
// Conditionally launch drop index name
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}
// Main savepoint reached
upgrade_main_savepoint(true, 2012070600.1);
}
if ($oldversion < 2012070600.11) {
// Define index component-itemid-userid (not unique) to be added to role_assignments
$table = new xmldb_table('role_assignments');
$index = new xmldb_index('component-itemid-userid', XMLDB_INDEX_NOTUNIQUE, array('component', 'itemid', 'userid'));
// Conditionally launch add index component-itemid-userid
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}
// Main savepoint reached
upgrade_main_savepoint(true, 2012070600.11);
}
if ($oldversion < 2012071900.01) {
// Cleanup after simpeltests tool
capabilities_cleanup('tool_unittest');
unset_all_config_for_plugin('tool_unittest');
upgrade_main_savepoint(true, 2012071900.01);
}
if ($oldversion < 2012072400.0) {
// Remove obsolete xhtml strict setting - use THEME->doctype in theme config if necessary,
// see theme_config->doctype in lib/outputlib.php for more details.
unset_config('xmlstrictheaders');
upgrade_main_savepoint(true, 2012072400.0);
}
if ($oldversion < 2012072401.0) {
// Saves orphaned questions from the Dark Side
upgrade_save_orphaned_questions();
// Main savepoint reached
upgrade_main_savepoint(true, 2012072401.0);
}
if ($oldversion < 2012072600.01) {
// Handle events with empty eventtype //MDL-32827
$DB->set_field('event', 'eventtype', 'site', array('eventtype' => '', 'courseid' => $SITE->id));
$DB->set_field_select('event', 'eventtype', 'due', "eventtype = '' AND courseid != 0 AND groupid = 0 AND (modulename = 'assignment' OR modulename = 'assign')");
$DB->set_field_select('event', 'eventtype', 'course', "eventtype = '' AND courseid != 0 AND groupid = 0");
$DB->set_field_select('event', 'eventtype', 'group', "eventtype = '' AND groupid != 0");
$DB->set_field_select('event', 'eventtype', 'user', "eventtype = '' AND userid != 0");
// Main savepoint reached
upgrade_main_savepoint(true, 2012072600.01);
}
if ($oldversion < 2012080200.02) {
// Drop obsolete question upgrade field that should have been added to the install.xml.
$table = new xmldb_table('question');
$field = new xmldb_field('oldquestiontextformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0');
if ($dbman->field_exists($table, $field)) {
$dbman->drop_field($table, $field);
}
示例9: update_capabilities
/**
* Updates the capabilities table with the component capability definitions.
* If no parameters are given, the function updates the core moodle
* capabilities.
*
* Note that the absence of the db/access.php capabilities definition file
* will cause any stored capabilities for the component to be removed from
* the database.
*
* @param $component - examples: 'moodle', 'mod/forum', 'block/quiz_results'
* @return boolean true if success, exception in case of any problems
*/
function update_capabilities($component = 'moodle')
{
global $DB;
$storedcaps = array();
$filecaps = load_capability_def($component);
$cachedcaps = get_cached_capabilities($component);
if ($cachedcaps) {
foreach ($cachedcaps as $cachedcap) {
array_push($storedcaps, $cachedcap->name);
// update risk bitmasks and context levels in existing capabilities if needed
if (array_key_exists($cachedcap->name, $filecaps)) {
if (!array_key_exists('riskbitmask', $filecaps[$cachedcap->name])) {
$filecaps[$cachedcap->name]['riskbitmask'] = 0;
// no risk if not specified
}
if ($cachedcap->riskbitmask != $filecaps[$cachedcap->name]['riskbitmask']) {
$updatecap = new object();
$updatecap->id = $cachedcap->id;
$updatecap->riskbitmask = $filecaps[$cachedcap->name]['riskbitmask'];
$DB->update_record('capabilities', $updatecap);
}
if (!array_key_exists('contextlevel', $filecaps[$cachedcap->name])) {
$filecaps[$cachedcap->name]['contextlevel'] = 0;
// no context level defined
}
if ($cachedcap->contextlevel != $filecaps[$cachedcap->name]['contextlevel']) {
$updatecap = new object();
$updatecap->id = $cachedcap->id;
$updatecap->contextlevel = $filecaps[$cachedcap->name]['contextlevel'];
$DB->update_record('capabilities', $updatecap);
}
}
}
}
// Are there new capabilities in the file definition?
$newcaps = array();
foreach ($filecaps as $filecap => $def) {
if (!$storedcaps || $storedcaps && in_array($filecap, $storedcaps) === false) {
if (!array_key_exists('riskbitmask', $def)) {
$def['riskbitmask'] = 0;
// no risk if not specified
}
$newcaps[$filecap] = $def;
}
}
// Add new capabilities to the stored definition.
foreach ($newcaps as $capname => $capdef) {
$capability = new object();
$capability->name = $capname;
$capability->captype = $capdef['captype'];
$capability->contextlevel = $capdef['contextlevel'];
$capability->component = $component;
$capability->riskbitmask = $capdef['riskbitmask'];
$DB->insert_record('capabilities', $capability, false);
if (isset($capdef['clonepermissionsfrom']) && in_array($capdef['clonepermissionsfrom'], $storedcaps)) {
if ($rolecapabilities = $DB->get_records('role_capabilities', array('capability' => $capdef['clonepermissionsfrom']))) {
foreach ($rolecapabilities as $rolecapability) {
//assign_capability will update rather than insert if capability exists
if (!assign_capability($capname, $rolecapability->permission, $rolecapability->roleid, $rolecapability->contextid, true)) {
notify('Could not clone capabilities for ' . $capname);
}
}
}
// Do we need to assign the new capabilities to roles that have the
// legacy capabilities moodle/legacy:* as well?
// we ignore legacy key if we have cloned permissions
} else {
if (isset($capdef['legacy']) && is_array($capdef['legacy']) && !assign_legacy_capabilities($capname, $capdef['legacy'])) {
notify('Could not assign legacy capabilities for ' . $capname);
}
}
}
// Are there any capabilities that have been removed from the file
// definition that we need to delete from the stored capabilities and
// role assignments?
capabilities_cleanup($component, $filecaps);
// reset static caches
is_valid_capability('reset', false);
return true;
}
示例10: grade_uninstalled_module
}
// And the module entry itself
if (!$DB->delete_records("modules", array("name" => $module->name))) {
echo $OUTPUT->notification("Error occurred while deleting the {$strmodulename} record from modules table");
}
// And the module configuration records
if (!unset_all_config_for_plugin($module->name)) {
echo $OUTPUT->notification(get_string('errordeletingconfig', 'admin', $strmodulename));
}
// cleanup the gradebook
require_once $CFG->libdir . '/gradelib.php';
grade_uninstalled_module($module->name);
// Then the tables themselves
drop_plugin_tables($module->name, "{$CFG->dirroot}/mod/{$module->name}/db/install.xml", false);
// Delete the capabilities that were defined by this module
capabilities_cleanup('mod/' . $module->name);
// remove entent handlers and dequeue pending events
events_uninstall('mod/' . $module->name);
// Perform any custom uninstall tasks
if (file_exists($CFG->dirroot . '/mod/' . $module->name . '/lib.php')) {
require_once $CFG->dirroot . '/mod/' . $module->name . '/lib.php';
$uninstallfunction = $module->name . '_uninstall';
if (function_exists($uninstallfunction)) {
if (!$uninstallfunction()) {
echo $OUTPUT->notification('Encountered a problem running uninstall function for ' . $module->name . '!');
}
}
}
$a->module = $strmodulename;
$a->directory = "{$CFG->dirroot}/mod/{$delete}";
notice(get_string("moduledeletefiles", "", $a), "modules.php");
示例11: xmldb_main_upgrade
//.........这里部分代码省略.........
if ($DB->get_dbfamily() === 'postgres') {
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}
$dbman->add_index($table, $index);
}
// Main savepoint reached
upgrade_main_savepoint(true, 2012070600.09);
}
if ($oldversion < 2012070600.1) {
// Define index name (unique) to be dropped form role
$table = new xmldb_table('role');
$index = new xmldb_index('name', XMLDB_INDEX_UNIQUE, array('name'));
// Conditionally launch drop index name
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}
// Main savepoint reached
upgrade_main_savepoint(true, 2012070600.1);
}
if ($oldversion < 2012070600.11) {
// Define index component-itemid-userid (not unique) to be added to role_assignments
$table = new xmldb_table('role_assignments');
$index = new xmldb_index('component-itemid-userid', XMLDB_INDEX_NOTUNIQUE, array('component', 'itemid', 'userid'));
// Conditionally launch add index component-itemid-userid
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}
// Main savepoint reached
upgrade_main_savepoint(true, 2012070600.11);
}
if ($oldversion < 2012071900.01) {
// Cleanup after simpeltests tool
capabilities_cleanup('tool_unittest');
unset_all_config_for_plugin('tool_unittest');
upgrade_main_savepoint(true, 2012071900.01);
}
if ($oldversion < 2012072400.0) {
// Remove obsolete xhtml strict setting - use THEME->doctype in theme config if necessary,
// see theme_config->doctype in lib/outputlib.php for more details.
unset_config('xmlstrictheaders');
upgrade_main_savepoint(true, 2012072400.0);
}
if ($oldversion < 2012072401.0) {
// Saves orphaned questions from the Dark Side
upgrade_save_orphaned_questions();
// Main savepoint reached
upgrade_main_savepoint(true, 2012072401.0);
}
if ($oldversion < 2012072600.01) {
// Handle events with empty eventtype //MDL-32827
$DB->set_field('event', 'eventtype', 'site', array('eventtype' => '', 'courseid' => $SITE->id));
$DB->set_field_select('event', 'eventtype', 'due', "eventtype = '' AND courseid != 0 AND groupid = 0 AND (modulename = 'assignment' OR modulename = 'assign')");
$DB->set_field_select('event', 'eventtype', 'course', "eventtype = '' AND courseid != 0 AND groupid = 0");
$DB->set_field_select('event', 'eventtype', 'group', "eventtype = '' AND groupid != 0");
$DB->set_field_select('event', 'eventtype', 'user', "eventtype = '' AND userid != 0");
// Main savepoint reached
upgrade_main_savepoint(true, 2012072600.01);
}
if ($oldversion < 2012080200.02) {
// Drop obsolete question upgrade field that should have been added to the install.xml.
$table = new xmldb_table('question');
$field = new xmldb_field('oldquestiontextformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0');
if ($dbman->field_exists($table, $field)) {
$dbman->drop_field($table, $field);
}
示例12: vmoodle_uninstall_plugin
/**
* Automatically clean-up all plugin data and remove the plugin DB tables
*
* @param string $type The subplugin type, eg. 'vmoodleadminset' etc.
* @param string $name The subplugin name, eg. 'example', 'generic', etc.
* @uses global $OUTPUT to produce notices and other messages
* @return void
*/
function vmoodle_uninstall_plugin($type, $name, $plugindirectory)
{
global $CFG, $DB, $OUTPUT;
// This may take a long time.
@set_time_limit(0);
$component = $type . '_' . $name;
// eg. 'qtype_multichoice' or 'workshopgrading_accumulative' or 'mod_forum'
$pluginname = $component;
if (get_string_manager()->string_exists('pluginname', $component)) {
$strpluginname = get_string('pluginname', $component);
} else {
$strpluginname = $component;
}
echo $OUTPUT->heading($pluginname);
$uninstalllib = $plugindirectory . '/db/uninstall.php';
if (file_exists($uninstalllib)) {
require_once $uninstalllib;
$uninstallfunction = 'xmldb_' . $pluginname . '_uninstall';
// eg. 'xmldb_workshop_uninstall()'
if (function_exists($uninstallfunction)) {
if (!$uninstallfunction()) {
echo $OUTPUT->notification('Encountered a problem running uninstall function for ' . $pluginname);
}
}
}
// Perform clean-up task common for all the plugin/subplugin types.
// Delete the web service functions and pre-built services.
require_once $CFG->dirroot . '/lib/externallib.php';
external_delete_descriptions($component);
// Delete calendar events.
$DB->delete_records('event', array('modulename' => $pluginname));
// Delete all the logs.
$DB->delete_records('log', array('module' => $pluginname));
// Delete log_display information.
$DB->delete_records('log_display', array('component' => $component));
// Delete the module configuration records.
unset_all_config_for_plugin($pluginname);
// delete message provider
message_provider_uninstall($component);
// Delete message processor.
if ($type === 'message') {
message_processor_uninstall($name);
}
// Delete the plugin tables.
$xmldbfilepath = $plugindirectory . '/db/install.xml';
drop_plugin_tables($component, $xmldbfilepath, false);
// Delete the capabilities that were defined by this module.
capabilities_cleanup($component);
// Remove event handlers and dequeue pending events.
events_uninstall($component);
echo $OUTPUT->notification(get_string('success'), 'notifysuccess');
}
示例13: xmldb_main_upgrade
//.........这里部分代码省略.........
}
// Define index useridfrom (not unique) to be dropped form message_read.
$table = new xmldb_table('message_read');
$index = new xmldb_index('useridfrom', XMLDB_INDEX_NOTUNIQUE, array('useridfrom'));
// Conditionally launch drop index useridfrom.
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015031400.0);
}
if ($oldversion < 2015031900.01) {
unset_config('crontime', 'registration');
upgrade_main_savepoint(true, 2015031900.01);
}
if ($oldversion < 2015032000.0) {
$table = new xmldb_table('badge_criteria');
$field = new xmldb_field('description', XMLDB_TYPE_TEXT, null, null, null, null, null);
// Conditionally add description field to the badge_criteria table.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
$field = new xmldb_field('descriptionformat', XMLDB_TYPE_INTEGER, 2, null, XMLDB_NOTNULL, null, 0);
// Conditionally add description format field to the badge_criteria table.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
upgrade_main_savepoint(true, 2015032000.0);
}
if ($oldversion < 2015040200.01) {
// Force uninstall of deleted tool.
if (!file_exists("{$CFG->dirroot}/{$CFG->admin}/tool/timezoneimport")) {
// Remove capabilities.
capabilities_cleanup('tool_timezoneimport');
// Remove all other associated config.
unset_all_config_for_plugin('tool_timezoneimport');
}
upgrade_main_savepoint(true, 2015040200.01);
}
if ($oldversion < 2015040200.02) {
// Define table timezone to be dropped.
$table = new xmldb_table('timezone');
// Conditionally launch drop table for timezone.
if ($dbman->table_exists($table)) {
$dbman->drop_table($table);
}
upgrade_main_savepoint(true, 2015040200.02);
}
if ($oldversion < 2015040200.03) {
if (isset($CFG->timezone) and $CFG->timezone == 99) {
// Migrate to real server timezone.
unset_config('timezone');
}
upgrade_main_savepoint(true, 2015040200.03);
}
if ($oldversion < 2015040700.01) {
$DB->delete_records('config_plugins', array('name' => 'requiremodintro'));
upgrade_main_savepoint(true, 2015040700.01);
}
if ($oldversion < 2015040900.01) {
// Add "My grades" to the user menu.
$oldconfig = get_config('core', 'customusermenuitems');
if (strpos("mygrades,grades|/grade/report/mygrades.php|grades", $oldconfig) === false) {
$newconfig = "mygrades,grades|/grade/report/mygrades.php|grades\n" . $oldconfig;
set_config('customusermenuitems', $newconfig);
}
示例14: xmldb_main_upgrade
//.........这里部分代码省略.........
}
// Define index useridfrom (not unique) to be dropped form message_read.
$table = new xmldb_table('message_read');
$index = new xmldb_index('useridfrom', XMLDB_INDEX_NOTUNIQUE, array('useridfrom'));
// Conditionally launch drop index useridfrom.
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015031400.0);
}
if ($oldversion < 2015031900.01) {
unset_config('crontime', 'registration');
upgrade_main_savepoint(true, 2015031900.01);
}
if ($oldversion < 2015032000.0) {
$table = new xmldb_table('badge_criteria');
$field = new xmldb_field('description', XMLDB_TYPE_TEXT, null, null, null, null, null);
// Conditionally add description field to the badge_criteria table.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
$field = new xmldb_field('descriptionformat', XMLDB_TYPE_INTEGER, 2, null, XMLDB_NOTNULL, null, 0);
// Conditionally add description format field to the badge_criteria table.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
upgrade_main_savepoint(true, 2015032000.0);
}
if ($oldversion < 2015040200.01) {
// Force uninstall of deleted tool.
if (!file_exists("{$CFG->dirroot}/{$CFG->admin}/tool/timezoneimport")) {
// Remove capabilities.
capabilities_cleanup('tool_timezoneimport');
// Remove all other associated config.
unset_all_config_for_plugin('tool_timezoneimport');
}
upgrade_main_savepoint(true, 2015040200.01);
}
if ($oldversion < 2015040200.02) {
// Define table timezone to be dropped.
$table = new xmldb_table('timezone');
// Conditionally launch drop table for timezone.
if ($dbman->table_exists($table)) {
$dbman->drop_table($table);
}
upgrade_main_savepoint(true, 2015040200.02);
}
if ($oldversion < 2015040200.03) {
if (isset($CFG->timezone) and $CFG->timezone == 99) {
// Migrate to real server timezone.
unset_config('timezone');
}
upgrade_main_savepoint(true, 2015040200.03);
}
if ($oldversion < 2015040700.01) {
$DB->delete_records('config_plugins', array('name' => 'requiremodintro'));
upgrade_main_savepoint(true, 2015040700.01);
}
if ($oldversion < 2015040900.01) {
// Add "My grades" to the user menu.
$oldconfig = get_config('core', 'customusermenuitems');
if (strpos("mygrades,grades|/grade/report/mygrades.php|grades", $oldconfig) === false) {
$newconfig = "mygrades,grades|/grade/report/mygrades.php|grades\n" . $oldconfig;
set_config('customusermenuitems', $newconfig);
}
示例15: array
}
}
// First delete instances and then block
$instances = $DB->get_records('block_instances', array('blockname' => $block->name));
if (!empty($instances)) {
foreach ($instances as $instance) {
blocks_delete_instance($instance);
}
}
// Delete block
$DB->delete_records('block', array('id' => $block->id));
drop_plugin_tables($block->name, "{$CFG->dirroot}/blocks/{$block->name}/db/install.xml", false);
// old obsoleted table names
drop_plugin_tables('block_' . $block->name, "{$CFG->dirroot}/blocks/{$block->name}/db/install.xml", false);
// Delete the capabilities that were defined by this block
capabilities_cleanup('block/' . $block->name);
// Remove event handlers and dequeue pending events
events_uninstall('block/' . $block->name);
$a->block = $strblockname;
$a->directory = $CFG->dirroot . '/blocks/' . $block->name;
notice(get_string('blockdeletefiles', '', $a), 'blocks.php');
}
}
echo $OUTPUT->header();
echo $OUTPUT->heading($strmanageblocks);
/// Main display starts here
/// Get and sort the existing blocks
if (!($blocks = $DB->get_records('block', array(), 'name ASC'))) {
print_error('noblocks', 'error');
// Should never happen
}