mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
Merge branch 'MDL-54771-master' of git://github.com/cameron1729/moodle
This commit is contained in:
commit
eb4f0d9c84
3 changed files with 21 additions and 2 deletions
|
@ -158,6 +158,12 @@ function tool_recyclebin_pre_course_module_delete($cm) {
|
|||
* @param \stdClass $course The course record.
|
||||
*/
|
||||
function tool_recyclebin_pre_course_delete($course) {
|
||||
// It is possible that the course deletion which triggered this hook
|
||||
// was from an in progress course restore. In that case we do not want
|
||||
// it in the recycle bin.
|
||||
if (isset($course->deletesource) && $course->deletesource == 'restore') {
|
||||
return;
|
||||
}
|
||||
// Delete all the items in the course recycle bin, regardless if it enabled or not.
|
||||
// It may have been enabled, then disabled later on, so may still have content.
|
||||
$coursebin = new \tool_recyclebin\course_bin($course->id);
|
||||
|
|
|
@ -38,6 +38,11 @@ class tool_recyclebin_category_bin_tests extends advanced_testcase {
|
|||
*/
|
||||
protected $course;
|
||||
|
||||
/**
|
||||
* @var stdClass $coursebeingrestored
|
||||
*/
|
||||
protected $coursebeingrestored;
|
||||
|
||||
/**
|
||||
* Setup for each test.
|
||||
*/
|
||||
|
@ -57,10 +62,16 @@ class tool_recyclebin_category_bin_tests extends advanced_testcase {
|
|||
public function test_pre_course_delete_hook() {
|
||||
global $DB;
|
||||
|
||||
// This simulates a temporary course being cleaned up by a course restore.
|
||||
$this->coursebeingrestored = $this->getDataGenerator()->create_course();
|
||||
$this->coursebeingrestored->deletesource = 'restore';
|
||||
|
||||
// Should have nothing in the recycle bin.
|
||||
$this->assertEquals(0, $DB->count_records('tool_recyclebin_category'));
|
||||
|
||||
delete_course($this->course, false);
|
||||
// This should not be added to the recycle bin.
|
||||
delete_course($this->coursebeingrestored, false);
|
||||
|
||||
// Check the course is now in the recycle bin.
|
||||
$this->assertEquals(1, $DB->count_records('tool_recyclebin_category'));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue