Example #1
0
function plugin_accounts_uninstall()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/accounts/inc/profile.class.php";
    include_once GLPI_ROOT . "/plugins/accounts/inc/menu.class.php";
    $tables = array("glpi_plugin_accounts_accounts", "glpi_plugin_accounts_accounts_items", "glpi_plugin_accounts_accounttypes", "glpi_plugin_accounts_accountstates", "glpi_plugin_accounts_configs", "glpi_plugin_accounts_hashs", "glpi_plugin_accounts_hashes", "glpi_plugin_accounts_aeskeys", "glpi_plugin_accounts_notificationstates");
    foreach ($tables as $table) {
        $DB->query("DROP TABLE IF EXISTS `{$table}`;");
    }
    //old versions
    $tables = array("glpi_plugin_comptes", "glpi_plugin_compte_device", "glpi_dropdown_plugin_compte_type", "glpi_dropdown_plugin_compte_status", "glpi_plugin_compte_profiles", "glpi_plugin_compte_config", "glpi_plugin_compte_default", "glpi_plugin_compte_mailing", "glpi_plugin_compte", "glpi_plugin_compte_hash", "glpi_plugin_compte_aeskey", "glpi_plugin_accounts_profiles");
    foreach ($tables as $table) {
        $DB->query("DROP TABLE IF EXISTS `{$table}`;");
    }
    $notif = new Notification();
    $options = array('itemtype' => 'PluginAccountsAccount', 'event' => 'new', 'FIELDS' => 'id');
    foreach ($DB->request('glpi_notifications', $options) as $data) {
        $notif->delete($data);
    }
    $options = array('itemtype' => 'PluginAccountsAccount', 'event' => 'ExpiredAccounts', 'FIELDS' => 'id');
    foreach ($DB->request('glpi_notifications', $options) as $data) {
        $notif->delete($data);
    }
    $options = array('itemtype' => 'PluginAccountsAccount', 'event' => 'AccountsWhichExpire', 'FIELDS' => 'id');
    foreach ($DB->request('glpi_notifications', $options) as $data) {
        $notif->delete($data);
    }
    //templates
    $template = new NotificationTemplate();
    $translation = new NotificationTemplateTranslation();
    $options = array('itemtype' => 'PluginAccountsAccount', 'FIELDS' => 'id');
    foreach ($DB->request('glpi_notificationtemplates', $options) as $data) {
        $options_template = array('notificationtemplates_id' => $data['id'], 'FIELDS' => 'id');
        foreach ($DB->request('glpi_notificationtemplatetranslations', $options_template) as $data_template) {
            $translation->delete($data_template);
        }
        $template->delete($data);
    }
    $tables_glpi = array("glpi_displaypreferences", "glpi_documents_items", "glpi_bookmarks", "glpi_logs", "glpi_items_tickets", "glpi_dropdowntranslations");
    foreach ($tables_glpi as $table_glpi) {
        $DB->query("DELETE FROM `{$table_glpi}`\n               WHERE `itemtype` = 'PluginAccountsAccount'\n               OR `itemtype` = 'PluginAccountsHelpdesk'\n               OR `itemtype` = 'PluginAccountsGroup'\n               OR `itemtype` = 'PluginAccountsAccountState'\n               OR `itemtype` = 'PluginAccountsAccountType' ;");
    }
    if (class_exists('PluginDatainjectionModel')) {
        PluginDatainjectionModel::clean(array('itemtype' => 'PluginAccountsAccount'));
    }
    //Delete rights associated with the plugin
    $profileRight = new ProfileRight();
    foreach (PluginAccountsProfile::getAllRights() as $right) {
        $profileRight->deleteByCriteria(array('name' => $right['field']));
    }
    PluginAccountsProfile::removeRightsFromSession();
    PluginAccountsMenu::removeRightsFromSession();
    return true;
}