MDL-48012 tool_recyclebin: used new hooks in core
This commit is contained in:
@@ -1,65 +0,0 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -131,4 +131,28 @@ function tool_recyclebin_extend_navigation_category_settings($navigation, $conte
|
||||
}
|
||||
|
||||
$navigation->add_node($node);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'));
|
||||
|
||||
@@ -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'));
|
||||
|
||||
Reference in New Issue
Block a user