Commit 1d4b387f authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Clean up favourites records on user & institution deletion

Remove records referring to a user or institution when a user or
institution is deleted.

Also, when a user leaves an institution, remove the institution's
right to maintain any of the user's favourites lists.

Change-Id: I7efbfff3ba26e9e8e81b8003ace670bf2041176a
Signed-off-by: default avatarRichard Mansfield <>
parent 14ad642c
......@@ -105,6 +105,12 @@ if ($institution || $add) {
foreach ($authinstanceids as $id) {
delete_records('auth_instance_config', 'instance', $id);
// The institution should have been removed from favourites lists when the members were removed,
// but make sure it's gone.
execute_sql('DELETE FROM {favorite_usr} WHERE favorite IN (SELECT id FROM {favorite} WHERE institution = ?)', array($values['i']));
delete_records('favorite', 'institution', $values['i']);
execute_sql("UPDATE {group} SET institution = NULL, shortname = NULL WHERE institution = ?", array($values['i']));
delete_records('auth_instance', 'institution', $values['i']);
delete_records('host', 'institution', $values['i']);
......@@ -343,6 +343,18 @@ class Institution {
update_record('usr', $user);
// If this user has a favourites list which is updated by this institution, remove it
// from this institution's control.
// Don't delete it in case the user wants to keep it, but move it out of the way, so
// another institution can create a new faves list with the same name.
UPDATE {favorite}
SET institution = NULL, shortname = substring(shortname from 1 for 100) || '.' || ?
WHERE owner = ? AND institution = ?",
array(substr($this->name, 0, 100) . '.' . get_random_key(), $user->id, $this->name)
delete_records('usr_institution', 'usr', $user->id, 'institution', $this->name);
handle_event('updateuser', $user->id);
......@@ -1075,6 +1075,12 @@ function delete_user($userid) {
WHERE owner = ?
OR requester = ?', array($userid, $userid));
// Delete the user from others' favourites lists
delete_records('favorite_usr', 'usr', $userid);
// Delete favourites lists owned by the user
execute_sql('DELETE FROM {favorite_usr} WHERE favorite IN (SELECT id FROM {favorite} WHERE owner = ?)', array($userid));
delete_records('favorite', 'owner', $userid);
delete_records('artefact_access_usr', 'usr', $userid);
delete_records('auth_remote_user', 'localusr', $userid);
delete_records('import_queue', 'usr', $userid);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment