From c27596c5500470c01c0ee3e71bfb4e8d5fe6a5fc Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Wed, 24 Feb 2016 13:57:51 +0800 Subject: [PATCH] MDL-48012 tool_recyclebin: used new hooks in core --- admin/tool/recyclebin/classes/observer.php | 65 ------------------- admin/tool/recyclebin/lib.php | 26 +++++++- admin/tool/recyclebin/tests/category_test.php | 4 +- admin/tool/recyclebin/tests/course_test.php | 4 +- 4 files changed, 29 insertions(+), 70 deletions(-) delete mode 100644 admin/tool/recyclebin/classes/observer.php diff --git a/admin/tool/recyclebin/classes/observer.php b/admin/tool/recyclebin/classes/observer.php deleted file mode 100644 index 6db585db5d9..00000000000 --- a/admin/tool/recyclebin/classes/observer.php +++ /dev/null @@ -1,65 +0,0 @@ -. - -/** - * Recycle bin observers. - * - * @package tool_recyclebin - * @copyright 2015 University of Kent - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -namespace tool_recyclebin; - -defined('MOODLE_INTERNAL') || die(); - -/** - * Main class for the recycle bin. - * - * @package tool_recyclebin - * @copyright 2015 University of Kent - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class observer -{ - /** - * Course hook. - * Note: This is not actually a typical observer. - * There is no pre-course delete event, see README. - * - * @param \stdClass $course The course record. - */ - public static function pre_course_delete($course) { - if (\tool_recyclebin\category::is_enabled()) { - $recyclebin = new \tool_recyclebin\category($course->category); - $recyclebin->store_item($course); - } - } - - /** - * Course module hook. - * Note: This is not actually a typical observer. - * There is no pre-cm event, see README. - * - * @param \stdClass $cm The course module record. - */ - public static function pre_cm_delete($cm) { - if (\tool_recyclebin\course::is_enabled()) { - $recyclebin = new \tool_recyclebin\course($cm->course); - $recyclebin->store_item($cm); - } - } -} diff --git a/admin/tool/recyclebin/lib.php b/admin/tool/recyclebin/lib.php index e4bcfbae496..da32e59e6c7 100644 --- a/admin/tool/recyclebin/lib.php +++ b/admin/tool/recyclebin/lib.php @@ -131,4 +131,28 @@ function tool_recyclebin_extend_navigation_category_settings($navigation, $conte } $navigation->add_node($node); -} \ No newline at end of file +} + +/** + * Hook called before we delete a course module. + * + * @param \stdClass $cm The course module record. + */ +function tool_recyclebin_pre_course_module_delete($cm) { + if (\tool_recyclebin\course::is_enabled()) { + $recyclebin = new \tool_recyclebin\course($cm->course); + $recyclebin->store_item($cm); + } +} + +/** + * Hook called before we delete a course. + * + * @param \stdClass $course The course record. + */ +function tool_recyclebin_pre_course_delete($course) { + if (\tool_recyclebin\category::is_enabled()) { + $recyclebin = new \tool_recyclebin\category($course->category); + $recyclebin->store_item($course); + } +} diff --git a/admin/tool/recyclebin/tests/category_test.php b/admin/tool/recyclebin/tests/category_test.php index e042a5f60c4..5f20e7107cd 100644 --- a/admin/tool/recyclebin/tests/category_test.php +++ b/admin/tool/recyclebin/tests/category_test.php @@ -47,9 +47,9 @@ class tool_recyclebin_category_tests extends \advanced_testcase } /** - * Run a bunch of tests to make sure we capture courses. + * Check that our hook is called when a course is deleted. */ - public function test_observer() { + public function test_hook() { global $DB; $this->assertEquals($this->before + 1, $DB->count_records('course')); diff --git a/admin/tool/recyclebin/tests/course_test.php b/admin/tool/recyclebin/tests/course_test.php index fe15149eab4..8e9f49faad2 100644 --- a/admin/tool/recyclebin/tests/course_test.php +++ b/admin/tool/recyclebin/tests/course_test.php @@ -51,9 +51,9 @@ class tool_recyclebin_course_tests extends \advanced_testcase } /** - * Run a bunch of tests to make sure we capture mods. + * Check that our hook is called when an activity is deleted. */ - public function test_observer() { + public function test_hook() { global $DB; $this->assertEquals($this->before + 1, $DB->count_records('course_modules'));