diff --git a/lib/models/InstituteMember.class.php b/lib/models/InstituteMember.class.php index 602d1cb0d3c884696ae5a0e72c0c0c8a26117148..fe1b19d8359d9df9bebc4a0bfb551cd5d2840671 100644 --- a/lib/models/InstituteMember.class.php +++ b/lib/models/InstituteMember.class.php @@ -74,6 +74,15 @@ class InstituteMember extends SimpleORMap implements PrivacyObject $config['additional_fields']['institute_name'] = []; + $config['registered_callbacks']['after_delete'][] = function ($member) { + $institute = $member->institute; + $user_id = $member->user_id; + + if ($institute) { + $institute->status_groups->removeUser($user_id, true); + } + }; + parent::configure($config); } @@ -170,24 +179,6 @@ class InstituteMember extends SimpleORMap implements PrivacyObject return true; } - /** - * Removes a user from an institute. Removes the user from all - * statusgroups as well. - * - * @return int number of deleted institute member records - */ - public function delete() - { - $institute = $this->institute; - $user_id = $this->user_id; - - if ($result = parent::delete()) { - $institute->status_groups->removeUser($user_id, true); - } - - return $result; - } - /** * Export available data of a given user into a storage object * (an instance of the StoredUserData class) for that user.