diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..040bc8c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,15 @@ +# Moodle Outage manager plugin - Change Log + +Version 1.0.4 +------------- + +* [Issue #57](https://github.com/catalyst/moodle-auth_outage/issues/57) + Calendar entries now are removed when plugin is uninstalled. + The uninstaller also makes sure there is no maintenance template or + or scheduled 'maintenance later'. + + +Version 1.0.3 +------------- + +Initial release. diff --git a/README.md b/README.md index 3f5cdc2..86fe5ab 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ # Moodle Outage manager plugin * [What is this?](#what-is-this) +* [Change Log](#change-log) * [Moodle Requirements](#moodle-requirements) * [Screenshots](#screenshots) * [Installation](#installation) @@ -25,6 +26,11 @@ an outage and after, different levels of warning and access can be provided to s and testers letting them know what is about to happen and why. +Change Log +---------- + +Please see [CHANGELOG.md](CHANGELOG.md) + Moodle Requirements ------------------- diff --git a/classes/calendar/calendar.php b/classes/calendar/calendar.php index b2db70c..9fb8f3e 100644 --- a/classes/calendar/calendar.php +++ b/classes/calendar/calendar.php @@ -96,9 +96,9 @@ class calendar { 'courseid' => 1, 'groupid' => 0, 'userid' => 0, - 'modulename' => '', + 'modulename' => 'auth_outage', 'instance' => $outage->id, - 'eventtype' => 'auth_outage', + 'eventtype' => 'outage', 'timestart' => $outage->starttime, 'visible' => true, 'timeduration' => $outage->get_duration_planned(), @@ -115,7 +115,7 @@ class calendar { $event = $DB->get_record_select( 'event', - "(eventtype = 'auth_outage' AND instance = :outageid)", + "(modulename='auth_outage' AND eventtype='outage' AND instance = :outageid)", ['outageid' => $outageid], 'id', IGNORE_MISSING diff --git a/db/uninstall.php b/db/uninstall.php new file mode 100644 index 0000000..bce5250 --- /dev/null +++ b/db/uninstall.php @@ -0,0 +1,46 @@ +. + +/** + * Auth Outage plugin uninstall code. + * + * @package auth_outage + * @author Daniel Thee Roperto + * @copyright 2016 Catalyst IT + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +defined('MOODLE_INTERNAL') || die(); + +/** + * Auth Outage plugin uninstall code. + * @return bool result + * @throws moodle_exception + */ + +function xmldb_auth_outage_uninstall() { + // Delete template file. + $template = auth_outage\local\controllers\infopage::get_defaulttemplatefile(); + if (file_exists($template)) { + if (!unlink($template)) { + throw new moodle_exception('Cannot remote maintenance template file: '.$template); + } + } + + // Remove 'maintenance later' which could have been set for the next outage. + unset_config('maintenance_later'); + + return true; +} diff --git a/tests/phpunit/installation_test.php b/tests/phpunit/installation_test.php new file mode 100644 index 0000000..4fa05a9 --- /dev/null +++ b/tests/phpunit/installation_test.php @@ -0,0 +1,86 @@ +. + +/** + * installation_test test class. + * + * Tests for installs, updates and uninstalls as needed. + * + * @package auth_outage + * @author Daniel Thee Roperto + * @copyright 2016 Catalyst IT + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +use auth_outage\local\outage; + +defined('MOODLE_INTERNAL') || die(); +require_once(__DIR__.'/base_testcase.php'); + +/** + * installation_test test class. + * + * Tests for installs, updates and uninstalls as needed. + * + * @package auth_outage + * @author Daniel Thee Roperto + * @copyright 2016 Catalyst IT + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class installation_test extends auth_outage_base_testcase { + /** + * Checks if plugin cleans up data after uninstall. + * + * See Issue #57. + */ + public function test_uninstall() { + global $CFG, $DB; + + $this->resetAfterTest(); + $this->setAdminUser(); + $dbman = $DB->get_manager(); + + // Create a future outage with autostart. + $now = time(); + $outage = new outage([ + 'autostart' => true, + 'starttime' => $now + (1 * 60 * 60), + 'stoptime' => $now + (2 * 60 * 60), + 'warntime' => $now - (2 * 60 * 60), + 'title' => 'Title', + 'description' => 'Description', + ]); + \auth_outage\dml\outagedb::save($outage); + self::assertSame(1, $DB->count_records_select('event', "modulename='auth_outage'", null)); + + // Uninstall plugin. + require_once($CFG->libdir.'/adminlib.php'); + $progress = new progress_trace_buffer(new text_progress_trace(), false); + core_plugin_manager::instance()->uninstall_plugin('auth_outage', $progress); + $progress->finished(); + self::assertContains('++ Success ++', $progress->get_buffer()); + + // Check ... + self::assertSame(0, $DB->count_records_select('event', "eventtype = 'auth_outage'", null), + 'The outage events were not removed.'); + self::assertFalse(file_exists(auth_outage\local\controllers\infopage::get_defaulttemplatefile()), + 'The maintenance template file was not deleted.'); + self::assertFalse(get_config('moodle', 'maintenance_later'), + 'Maintenance later must not be set.'); // Issue #57. + self::assertFalse($dbman->table_exists('auth_outage'), + 'Table "auth_outage" was not dropped.'); + } +} diff --git a/version.php b/version.php index 90ca7fb..ef197fd 100644 --- a/version.php +++ b/version.php @@ -28,7 +28,7 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = "auth_outage"; -$plugin->version = 2016101400; // The current plugin version (Date: YYYYMMDDXX). -$plugin->release = '1.0.3'; // Human-readable release information. +$plugin->version = 2016101800; // The current plugin version (Date: YYYYMMDDXX). +$plugin->release = '1.0.4'; // Human-readable release information. $plugin->requires = 2014051200; // Requires Moodle 2.7 or later. Moodle 2.9 or later recommended. $plugin->maturity = MATURITY_STABLE; // Suitable for PRODUCTION environments!