Commit c8f0fee9 authored by Paul Holden's avatar Paul Holden
Browse files

MDL-71314 course: add category record snapshot to deletion event.

parent a747fd30
...@@ -2034,6 +2034,7 @@ class core_course_category implements renderable, cacheable_object, IteratorAggr ...@@ -2034,6 +2034,7 @@ class core_course_category implements renderable, cacheable_object, IteratorAggr
$DB->delete_records('event', array('categoryid' => $this->id)); $DB->delete_records('event', array('categoryid' => $this->id));
// Finally delete the category and it's context. // Finally delete the category and it's context.
$categoryrecord = $this->get_db_record();
$DB->delete_records('course_categories', array('id' => $this->id)); $DB->delete_records('course_categories', array('id' => $this->id));
$coursecatcontext = context_coursecat::instance($this->id); $coursecatcontext = context_coursecat::instance($this->id);
...@@ -2048,6 +2049,7 @@ class core_course_category implements renderable, cacheable_object, IteratorAggr ...@@ -2048,6 +2049,7 @@ class core_course_category implements renderable, cacheable_object, IteratorAggr
'context' => $coursecatcontext, 'context' => $coursecatcontext,
'other' => array('name' => $this->name) 'other' => array('name' => $this->name)
)); ));
$event->add_record_snapshot($event->objecttable, $categoryrecord);
$event->set_coursecat($this); $event->set_coursecat($this);
$event->trigger(); $event->trigger();
...@@ -2223,6 +2225,7 @@ class core_course_category implements renderable, cacheable_object, IteratorAggr ...@@ -2223,6 +2225,7 @@ class core_course_category implements renderable, cacheable_object, IteratorAggr
} }
// Finally delete the category and it's context. // Finally delete the category and it's context.
$categoryrecord = $this->get_db_record();
$DB->delete_records('course_categories', array('id' => $this->id)); $DB->delete_records('course_categories', array('id' => $this->id));
$context->delete(); $context->delete();
...@@ -2233,6 +2236,7 @@ class core_course_category implements renderable, cacheable_object, IteratorAggr ...@@ -2233,6 +2236,7 @@ class core_course_category implements renderable, cacheable_object, IteratorAggr
'context' => $context, 'context' => $context,
'other' => array('name' => $this->name, 'contentmovedcategoryid' => $newparentid) 'other' => array('name' => $this->name, 'contentmovedcategoryid' => $newparentid)
)); ));
$event->add_record_snapshot($event->objecttable, $categoryrecord);
$event->set_coursecat($this); $event->set_coursecat($this);
$event->trigger(); $event->trigger();
......
...@@ -1995,7 +1995,8 @@ class core_course_courselib_testcase extends advanced_testcase { ...@@ -1995,7 +1995,8 @@ class core_course_courselib_testcase extends advanced_testcase {
// Create a category. // Create a category.
$category = $this->getDataGenerator()->create_category(); $category = $this->getDataGenerator()->create_category();
// Save the context before it is deleted. // Save the original record/context before it is deleted.
$categoryrecord = $category->get_db_record();
$categorycontext = context_coursecat::instance($category->id); $categorycontext = context_coursecat::instance($category->id);
// Catch the update event. // Catch the update event.
...@@ -2014,6 +2015,10 @@ class core_course_courselib_testcase extends advanced_testcase { ...@@ -2014,6 +2015,10 @@ class core_course_courselib_testcase extends advanced_testcase {
$this->assertEquals('course_categories', $event->objecttable); $this->assertEquals('course_categories', $event->objecttable);
$this->assertEquals($category->id, $event->objectid); $this->assertEquals($category->id, $event->objectid);
$this->assertEquals($categorycontext->id, $event->contextid); $this->assertEquals($categorycontext->id, $event->contextid);
$this->assertEquals([
'name' => $category->name,
], $event->other);
$this->assertEquals($categoryrecord, $event->get_record_snapshot($event->objecttable, $event->objectid));
$this->assertEquals('course_category_deleted', $event->get_legacy_eventname()); $this->assertEquals('course_category_deleted', $event->get_legacy_eventname());
$this->assertEquals(null, $event->get_url()); $this->assertEquals(null, $event->get_url());
$this->assertEventLegacyData($category, $event); $this->assertEventLegacyData($category, $event);
...@@ -2024,7 +2029,8 @@ class core_course_courselib_testcase extends advanced_testcase { ...@@ -2024,7 +2029,8 @@ class core_course_courselib_testcase extends advanced_testcase {
$category = $this->getDataGenerator()->create_category(); $category = $this->getDataGenerator()->create_category();
$category2 = $this->getDataGenerator()->create_category(); $category2 = $this->getDataGenerator()->create_category();
// Save the context before it is moved and then deleted. // Save the original record/context before it is moved and then deleted.
$category2record = $category2->get_db_record();
$category2context = context_coursecat::instance($category2->id); $category2context = context_coursecat::instance($category2->id);
// Catch the update event. // Catch the update event.
...@@ -2043,6 +2049,11 @@ class core_course_courselib_testcase extends advanced_testcase { ...@@ -2043,6 +2049,11 @@ class core_course_courselib_testcase extends advanced_testcase {
$this->assertEquals('course_categories', $event->objecttable); $this->assertEquals('course_categories', $event->objecttable);
$this->assertEquals($category2->id, $event->objectid); $this->assertEquals($category2->id, $event->objectid);
$this->assertEquals($category2context->id, $event->contextid); $this->assertEquals($category2context->id, $event->contextid);
$this->assertEquals([
'name' => $category2->name,
'contentmovedcategoryid' => $category->id,
], $event->other);
$this->assertEquals($category2record, $event->get_record_snapshot($event->objecttable, $event->objectid));
$this->assertEquals('course_category_deleted', $event->get_legacy_eventname()); $this->assertEquals('course_category_deleted', $event->get_legacy_eventname());
$this->assertEventLegacyData($category2, $event); $this->assertEventLegacyData($category2, $event);
$expectedlog = array(SITEID, 'category', 'delete', 'index.php', $category2->name . '(ID ' . $category2->id . ')'); $expectedlog = array(SITEID, 'category', 'delete', 'index.php', $category2->name . '(ID ' . $category2->id . ')');
......
...@@ -48,6 +48,8 @@ compatibility (to not break third-party plugins without it), legacy_format_rende ...@@ -48,6 +48,8 @@ compatibility (to not break third-party plugins without it), legacy_format_rende
course formats don't have their own renderer. course formats don't have their own renderer.
* New external core_course\external\get_state returns current state information for a given course. * New external core_course\external\get_state returns current state information for a given course.
* New external function core_course_update_course runs given action to edit course status. * New external function core_course_update_course runs given action to edit course status.
* The `\core\event\course_category_deleted` event is now created with a snapshot of the category record being deleted,
available inside event observers via `$event->get_record_snapshot`
=== 3.11 === === 3.11 ===
* A new callback xxx_coursemodule_definition_after_data that allows plugins to extend activity forms after the data is set. * A new callback xxx_coursemodule_definition_after_data that allows plugins to extend activity forms after the data is set.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment