diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 61b401a8855..f4dc49bd40d 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -659,6 +659,7 @@ $string['errorcreatingactivity'] = 'Unable to create an instance of activity \'{ $string['errorfiletoobig'] = 'The file was bigger than the limit of {$a} bytes'; $string['errornouploadrepo'] = 'There is no upload repository enabled for this site'; $string['errorwhenconfirming'] = 'You are not confirmed yet because an error occurred. If you clicked on a link in an email to get here, make sure that the line in your email wasn\'t broken or wrapped. You may have to use cut and paste to reconstruct the link properly.'; +$string['eventcoursecategorydeleted'] = 'Category deleted'; $string['eventcoursecontentdeleted'] = 'Course content deleted'; $string['eventcoursecreated'] = 'Course created'; $string['eventcoursedeleted'] = 'Course deleted'; diff --git a/lib/classes/event/course_category_deleted.php b/lib/classes/event/course_category_deleted.php new file mode 100644 index 00000000000..1f8fde94fe1 --- /dev/null +++ b/lib/classes/event/course_category_deleted.php @@ -0,0 +1,95 @@ +. + +namespace core\event; + +/** + * category deleted event. + * + * @package core + * @copyright 2013 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class course_category_deleted extends base { + + /** + * The course category class used for legacy reasons. + */ + private $coursecat; + + /** + * Initialise the event data. + */ + protected function init() { + $this->data['objecttable'] = 'course_categories'; + $this->data['crud'] = 'd'; + $this->data['level'] = 50; + } + + /** + * Returns localised general event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventcoursecategorydeleted'); + } + + /** + * Returns non-localised description of what happened. + * + * @return string + */ + public function get_description() { + return "Category {$this->objectid} was deleted by user {$this->userid}"; + } + + /** + * Returns the name of the legacy event. + * + * @return string legacy event name + */ + public static function get_legacy_eventname() { + return 'course_category_deleted'; + } + + /** + * Returns the legacy event data. + * + * @return coursecat the category that was deleted + */ + protected function get_legacy_eventdata() { + return $this->coursecat; + } + + /** + * Set the legacy event data. + * + * @param coursecat $class instance of the coursecat class + */ + public function set_legacy_eventdata($class) { + $this->coursecat = $class; + } + + /** + * Return legacy data for add_to_log(). + * + * @return array + */ + protected function get_legacy_logdata() { + return array(SITEID, 'category', 'delete', 'index.php', $this->other['name'] . '(ID ' . $this->objectid . ')'); + } +} diff --git a/lib/coursecatlib.php b/lib/coursecatlib.php index 816c001d9b2..0a5164939d9 100644 --- a/lib/coursecatlib.php +++ b/lib/coursecatlib.php @@ -1366,6 +1366,7 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate { */ public function delete_full($showfeedback = true) { global $CFG, $DB; + require_once($CFG->libdir.'/gradelib.php'); require_once($CFG->libdir.'/questionlib.php'); require_once($CFG->dirroot.'/cohort/lib.php'); @@ -1400,12 +1401,20 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate { // finally delete the category and it's context $DB->delete_records('course_categories', array('id' => $this->id)); - context_helper::delete_instance(CONTEXT_COURSECAT, $this->id); - add_to_log(SITEID, "category", "delete", "index.php", "$this->name (ID $this->id)"); + + $coursecatcontext = context_coursecat::instance($this->id); + $coursecatcontext->delete(); cache_helper::purge_by_event('changesincoursecat'); - events_trigger('course_category_deleted', $this); + // Trigger a course category deleted event. + $event = \core\event\course_category_deleted::create(array( + 'objectid' => $this->id, + 'context' => $coursecatcontext, + 'other' => array('name' => $this->name) + )); + $event->set_legacy_eventdata($this); + $event->trigger(); // If we deleted $CFG->defaultrequestcategory, make it point somewhere else. if ($this->id == $CFG->defaultrequestcategory) { @@ -1495,6 +1504,7 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate { */ public function delete_move($newparentid, $showfeedback = false) { global $CFG, $DB, $OUTPUT; + require_once($CFG->libdir.'/gradelib.php'); require_once($CFG->libdir.'/questionlib.php'); require_once($CFG->dirroot.'/cohort/lib.php'); @@ -1543,9 +1553,15 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate { // finally delete the category and it's context $DB->delete_records('course_categories', array('id' => $this->id)); $context->delete(); - add_to_log(SITEID, "category", "delete", "index.php", "$this->name (ID $this->id)"); - events_trigger('course_category_deleted', $this); + // Trigger a course category deleted event. + $event = \core\event\course_category_deleted::create(array( + 'objectid' => $this->id, + 'context' => $context, + 'other' => array('name' => $this->name) + )); + $event->set_legacy_eventdata($this); + $event->trigger(); cache_helper::purge_by_event('changesincoursecat');