MDL-27547 When deleting a local plugin containing a built-in service, the built-in service is not deleted

This commit is contained in:
Jerome Mouneyrac 2012-04-11 14:48:14 +08:00
parent 9ad535c550
commit bc81eadb19
3 changed files with 27 additions and 17 deletions

View File

@ -269,6 +269,10 @@ function uninstall_plugin($type, $name) {
// 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));

View File

@ -487,4 +487,24 @@ function external_create_service_token($servicename, $context){
global $USER, $DB;
$service = $DB->get_record('external_services', array('name'=>$servicename), '*', MUST_EXIST);
return external_generate_token(EXTERNAL_TOKEN_EMBEDDED, $service, $USER->id, $context, 0);
}
/**
* Delete all pre-built services (+ related tokens) and external functions information defined in the specified component.
*
* @param string $component name of component (moodle, mod_assignment, etc.)
*/
function external_delete_descriptions($component) {
global $DB;
$params = array($component);
$DB->delete_records_select('external_tokens',
"externalserviceid IN (SELECT id FROM {external_services} WHERE component = ?)", $params);
$DB->delete_records_select('external_services_users',
"externalserviceid IN (SELECT id FROM {external_services} WHERE component = ?)", $params);
$DB->delete_records_select('external_services_functions',
"functionname IN (SELECT name FROM {external_functions} WHERE component = ?)", $params);
$DB->delete_records('external_services', array('component'=>$component));
$DB->delete_records('external_functions', array('component'=>$component));
}

View File

@ -869,11 +869,12 @@ function log_update_descriptions($component) {
* @return void
*/
function external_update_descriptions($component) {
global $DB;
global $DB, $CFG;
$defpath = get_component_directory($component).'/db/services.php';
if (!file_exists($defpath)) {
require_once($CFG->dirroot.'/lib/externallib.php');
external_delete_descriptions($component);
return;
}
@ -937,6 +938,7 @@ function external_update_descriptions($component) {
$dbservices = $DB->get_records('external_services', array('component'=>$component));
foreach ($dbservices as $dbservice) {
if (empty($services[$dbservice->name])) {
$DB->delete_records('external_tokens', array('externalserviceid'=>$dbservice->id));
$DB->delete_records('external_services_functions', array('externalserviceid'=>$dbservice->id));
$DB->delete_records('external_services_users', array('externalserviceid'=>$dbservice->id));
$DB->delete_records('external_services', array('id'=>$dbservice->id));
@ -1030,22 +1032,6 @@ function external_update_descriptions($component) {
}
}
/**
* Delete all service and external functions information defined in the specified component.
* @param string $component name of component (moodle, mod_assignment, etc.)
* @return void
*/
function external_delete_descriptions($component) {
global $DB;
$params = array($component);
$DB->delete_records_select('external_services_users', "externalserviceid IN (SELECT id FROM {external_services} WHERE component = ?)", $params);
$DB->delete_records_select('external_services_functions', "externalserviceid IN (SELECT id FROM {external_services} WHERE component = ?)", $params);
$DB->delete_records('external_services', array('component'=>$component));
$DB->delete_records('external_functions', array('component'=>$component));
}
/**
* upgrade logging functions
*/