From bfb2cac284150e4109fd4ade7e4a2ebd214bd813 Mon Sep 17 00:00:00 2001 From: Alexander Bias <alexander.bias@uni-ulm.de> Date: Thu, 28 Mar 2019 14:13:24 +0100 Subject: [PATCH] Remove user preferences when being uninstalled. --- CHANGES.md | 1 + db/uninstall.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 db/uninstall.php diff --git a/CHANGES.md b/CHANGES.md index 710505b..a9cf813 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ Changes ### Unreleased +* 2019-03-28 - Remove user preferences when being uninstalled. * 2019-03-28 - Prepare the plugin that the hooks for fetching the course news will be removed in Moodle 3.7. If installed on Moodle 3.7, this plugin will silently disable the course news feature even if it is enabled in the plugin settings. * 2019-03-28 - Check compatibility for Moodle 3.6, no functionality change. * 2018-12-05 - Changed travis.yml due to upstream changes. diff --git a/db/uninstall.php b/db/uninstall.php new file mode 100644 index 0000000..c68fd66 --- /dev/null +++ b/db/uninstall.php @@ -0,0 +1,45 @@ +<?php +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see <http://www.gnu.org/licenses/>. + +/** + * Block "course overview (campus)" - Uninstall file + * + * @package block_course_overview_campus + * @copyright 2019 Alexander Bias, Ulm University <alexander.bias@uni-ulm.de> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +function xmldb_block_course_overview_campus_uninstall() { + global $DB; + + // The plugin uninstall process in Moodle core will take care of removing the plugin configuration, but not of removing the + // user preferences which we have set for the users. We have to remove them ourselves. + // We remove them directly from the DB table and don't use unset_user_preference() as the cache is cleared anyway directly + // after the plugin has been uninstalled. + + $like = $DB->sql_like('name', '?', true, true, false, '|'); + $params = array($DB->sql_like_escape('block_course_overview_campus-', '|') . '%'); + $DB->delete_records_select('user_preferences', $like, $params); + + $like = $DB->sql_like('name', '?', true, true, false, '|'); + $params = array($DB->sql_like_escape('local_boostcoc-', '|') . '%'); + $DB->delete_records_select('user_preferences', $like, $params); + + return true; +} + -- GitLab