mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-58898 oauth: Remove orphaned linked logins
This commit is contained in:
parent
b16603770b
commit
4c8727bad6
@ -39,6 +39,16 @@ defined('MOODLE_INTERNAL') || die();
|
||||
*/
|
||||
class api {
|
||||
|
||||
/**
|
||||
* Remove all linked logins that are using issuers that have been deleted.
|
||||
*
|
||||
* @param int $issuerid The issuer id of the issuer to check, or false to check all (defaults to all)
|
||||
* @return boolean
|
||||
*/
|
||||
public static function clean_orphaned_linked_logins($issuerid = false) {
|
||||
return linked_login::delete_orphaned($issuerid);
|
||||
}
|
||||
|
||||
/**
|
||||
* List linked logins
|
||||
*
|
||||
|
@ -65,4 +65,26 @@ class linked_login extends persistent {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all linked logins that are using issuers that have been deleted.
|
||||
*
|
||||
* @param int $issuerid The issuer id of the issuer to check, or false to check all (defaults to all)
|
||||
* @return boolean
|
||||
*/
|
||||
public static function delete_orphaned($issuerid = false) {
|
||||
global $DB;
|
||||
// Delete any linked_login entries with a issuerid
|
||||
// which does not exist in the issuer table.
|
||||
// In the left join, the issuer id will be null
|
||||
// where a match linked_login.issuerid is not found.
|
||||
$sql = "DELETE FROM {" . self::TABLE . "}
|
||||
WHERE issuerid NOT IN (SELECT id FROM {" . \core\oauth2\issuer::TABLE . "})";
|
||||
$params = [];
|
||||
if (!empty($issuerid)) {
|
||||
$sql .= ' AND issuerid = ?';
|
||||
$params['issuerid'] = $issuerid;
|
||||
}
|
||||
return $DB->execute($sql, $params);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -79,6 +79,7 @@ $linkedlogin = null;
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(get_string('linkedlogins', 'auth_oauth2'));
|
||||
echo $OUTPUT->doc_link('Linked_Logins', get_string('linkedloginshelp', 'auth_oauth2'));
|
||||
auth_oauth2\api::clean_orphaned_linked_logins();
|
||||
$linkedlogins = auth_oauth2\api::get_linked_logins();
|
||||
|
||||
echo $renderer->linked_logins_table($linkedlogins);
|
||||
|
Loading…
x
Reference in New Issue
Block a user