mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-39957 course: replaced the course_category_deleted legacy event
This commit is contained in:
parent
ec8f23de3b
commit
f326c5b4f4
@ -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';
|
||||
|
95
lib/classes/event/course_category_deleted.php
Normal file
95
lib/classes/event/course_category_deleted.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?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/>.
|
||||
|
||||
namespace core\event;
|
||||
|
||||
/**
|
||||
* category deleted event.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
||||
* @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 . ')');
|
||||
}
|
||||
}
|
@ -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');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user