From 63570ad28964fe7b0f09c8b20c95e27564843eea Mon Sep 17 00:00:00 2001 From: btry Date: Fri, 16 Dec 2016 17:27:32 +0100 Subject: [PATCH] feat(enhancement): cleanup invitations when purging a user database kept cleaner --- hook.php | 15 +++++++++++++++ setup.php | 1 + 2 files changed, 16 insertions(+) diff --git a/hook.php b/hook.php index d8666b10..cebf6a15 100644 --- a/hook.php +++ b/hook.php @@ -64,6 +64,21 @@ function plugin_storkmdm_postinit() { } +/** + * Actions done when a profile_user is being purged + */ +function plugin_storkmdm_hook_pre_profileuser_purge(CommonDBTM $item) { + $config = Config::getConfigurationValues('storkmdm', array('guest_profiles_id', 'registered_profiles_id')); + $guestProfileId = $config['guest_profiles_id']; + + if ($item->getField('profiles_id') == $guestProfileId) { + $invitation = new PluginStorkmdmInvitation(); + if (!$invitation->deleteByCriteria(array('users_id' => $item->getField('users_id')))) { + $item->input = false; + } + } +} + /** * Define Dropdown tables to be managed in GLPI * @return translated[] diff --git a/setup.php b/setup.php index aa846479..bbea53c2 100644 --- a/setup.php +++ b/setup.php @@ -131,6 +131,7 @@ function plugin_init_storkmdm() { $PLUGIN_HOOKS['pre_item_purge']['storkmdm'] = array( 'PluginStorkmdmInvitation' => array('PluginStorkmdmInvitation', 'hook_pre_self_purge'), 'Document' => array('PluginStorkmdmInvitation', 'hook_pre_document_purge'), + 'Profile_User' => 'plugin_storkmdm_hook_pre_profileuser_purge', ); // Add css and js resources if the requested page needs them