Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-27547 When deleting a local plugin containing a built-in service,…

… the built-in service is not deleted
  • Loading branch information...
commit bc81eadb197286c7ee79ccf4a7721af893c1caf5 1 parent 9ad535c
Jérôme Mouneyrac mouneyrac authored
Showing with 27 additions and 17 deletions.
  1. +4 −0 lib/adminlib.php
  2. +20 −0 lib/externallib.php
  3. +3 −17 lib/upgradelib.php
4 lib/adminlib.php
View
@@ -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));
20 lib/externallib.php
View
@@ -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));
}
20 lib/upgradelib.php
View
@@ -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));
@@ -1031,22 +1033,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
*/
function upgrade_handle_exception($ex, $plugin = null) {
Please sign in to comment.
Something went wrong with that request. Please try again.