From e0abc2e40586bf7fefe6f9c6961c58394e4861a0 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Mon, 8 May 2017 14:26:44 +0800 Subject: [PATCH] MDL-58774 auth_oauth2: Cleanup on user delete. --- auth/oauth2/classes/api.php | 14 ++++++++++++++ auth/oauth2/db/events.php | 31 +++++++++++++++++++++++++++++++ auth/oauth2/version.php | 2 +- 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 auth/oauth2/db/events.php diff --git a/auth/oauth2/classes/api.php b/auth/oauth2/classes/api.php index 430abeef8d3..adf3f94bc0d 100644 --- a/auth/oauth2/classes/api.php +++ b/auth/oauth2/classes/api.php @@ -319,4 +319,18 @@ class api { $login->delete(); } + + /** + * Delete linked logins for a user. + * + * @param \core\event\user_deleted $event + * @return boolean + */ + public static function user_deleted(\core\event\user_deleted $event) { + global $DB; + + $userid = $event->objectid; + + return $DB->delete_records(linked_login::TABLE, ['userid' => $userid]); + } } diff --git a/auth/oauth2/db/events.php b/auth/oauth2/db/events.php new file mode 100644 index 00000000000..b6f793c38d1 --- /dev/null +++ b/auth/oauth2/db/events.php @@ -0,0 +1,31 @@ +. + +/** + * This file definies observers needed by the plugin. + * + * @package auth_oauth2 + * @copyright 2017 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +// List of observers. +$observers = [ + [ + 'eventname' => '\core\event\user_deleted', + 'callback' => '\auth_oauth2\api::user_deleted', + ], +]; diff --git a/auth/oauth2/version.php b/auth/oauth2/version.php index 2ff2041e851..bbc6242d0da 100644 --- a/auth/oauth2/version.php +++ b/auth/oauth2/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2017032300; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2017050800; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2016112900; // Requires this Moodle version. $plugin->component = 'auth_oauth2'; // Full name of the plugin (used for diagnostics).