mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
Merge branch 'MDL-53537_m34v4' of https://github.com/sbourget/moodle
This commit is contained in:
commit
34cf57f1d0
5 changed files with 182 additions and 0 deletions
|
@ -60,6 +60,8 @@ class tool_recyclebin_events_testcase extends advanced_testcase {
|
||||||
delete_course($course, false);
|
delete_course($course, false);
|
||||||
$events = $sink->get_events();
|
$events = $sink->get_events();
|
||||||
$event = reset($events);
|
$event = reset($events);
|
||||||
|
// Need the second event here, the first is backup created.
|
||||||
|
$event = next($events);
|
||||||
|
|
||||||
// Get the item from the recycle bin.
|
// Get the item from the recycle bin.
|
||||||
$rb = new \tool_recyclebin\category_bin($course->category);
|
$rb = new \tool_recyclebin\category_bin($course->category);
|
||||||
|
|
|
@ -119,6 +119,21 @@ class backup_plan extends base_plan implements loggable {
|
||||||
$this->controller->set_status(backup::STATUS_EXECUTING);
|
$this->controller->set_status(backup::STATUS_EXECUTING);
|
||||||
parent::execute();
|
parent::execute();
|
||||||
$this->controller->set_status(backup::STATUS_FINISHED_OK);
|
$this->controller->set_status(backup::STATUS_FINISHED_OK);
|
||||||
|
|
||||||
|
if ($this->controller->get_type() === backup::TYPE_1COURSE) {
|
||||||
|
// Trigger a course_backup_created event.
|
||||||
|
$otherarray = array('format' => $this->controller->get_format(),
|
||||||
|
'mode' => $this->controller->get_mode(),
|
||||||
|
'interactive' => $this->controller->get_interactive(),
|
||||||
|
'type' => $this->controller->get_type(),
|
||||||
|
);
|
||||||
|
$event = \core\event\course_backup_created::create(array(
|
||||||
|
'objectid' => $this->get_courseid(),
|
||||||
|
'context' => context_course::instance($this->get_courseid()),
|
||||||
|
'other' => $otherarray
|
||||||
|
));
|
||||||
|
$event->trigger();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1900,6 +1900,52 @@ class core_course_courselib_testcase extends advanced_testcase {
|
||||||
$this->assertEventContextNotUsed($event);
|
$this->assertEventContextNotUsed($event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that triggering a course_backup_created event works as expected.
|
||||||
|
*/
|
||||||
|
public function test_course_backup_created_event() {
|
||||||
|
global $CFG;
|
||||||
|
|
||||||
|
// Get the necessary files to perform backup and restore.
|
||||||
|
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
|
||||||
|
require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
|
||||||
|
|
||||||
|
$this->resetAfterTest();
|
||||||
|
|
||||||
|
// Set to admin user.
|
||||||
|
$this->setAdminUser();
|
||||||
|
|
||||||
|
// The user id is going to be 2 since we are the admin user.
|
||||||
|
$userid = 2;
|
||||||
|
|
||||||
|
// Create a course.
|
||||||
|
$course = $this->getDataGenerator()->create_course();
|
||||||
|
|
||||||
|
// Create backup file and save it to the backup location.
|
||||||
|
$bc = new backup_controller(backup::TYPE_1COURSE, $course->id, backup::FORMAT_MOODLE,
|
||||||
|
backup::INTERACTIVE_NO, backup::MODE_GENERAL, $userid);
|
||||||
|
$sink = $this->redirectEvents();
|
||||||
|
$bc->execute_plan();
|
||||||
|
|
||||||
|
// Capture the event.
|
||||||
|
$events = $sink->get_events();
|
||||||
|
$sink->close();
|
||||||
|
|
||||||
|
// Validate the event.
|
||||||
|
$event = array_pop($events);
|
||||||
|
$this->assertInstanceOf('\core\event\course_backup_created', $event);
|
||||||
|
$this->assertEquals('course', $event->objecttable);
|
||||||
|
$this->assertEquals($bc->get_courseid(), $event->objectid);
|
||||||
|
$this->assertEquals(context_course::instance($bc->get_courseid())->id, $event->contextid);
|
||||||
|
|
||||||
|
$url = new moodle_url('/course/view.php', array('id' => $event->objectid));
|
||||||
|
$this->assertEquals($url, $event->get_url());
|
||||||
|
$this->assertEventContextNotUsed($event);
|
||||||
|
|
||||||
|
// Destroy the resource controller since we are done using it.
|
||||||
|
$bc->destroy();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that triggering a course_restored event works as expected.
|
* Test that triggering a course_restored event works as expected.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -729,6 +729,7 @@ $string['eventcommentcreated'] = 'Comment created';
|
||||||
$string['eventcommentdeleted'] = 'Comment deleted';
|
$string['eventcommentdeleted'] = 'Comment deleted';
|
||||||
$string['eventcommentsviewed'] = 'Comments viewed';
|
$string['eventcommentsviewed'] = 'Comments viewed';
|
||||||
$string['eventconfiglogcreated'] = 'Config log created';
|
$string['eventconfiglogcreated'] = 'Config log created';
|
||||||
|
$string['eventcoursebackupcreated'] = 'Course backup created';
|
||||||
$string['eventcoursecategorycreated'] = 'Category created';
|
$string['eventcoursecategorycreated'] = 'Category created';
|
||||||
$string['eventcoursecategorydeleted'] = 'Category deleted';
|
$string['eventcoursecategorydeleted'] = 'Category deleted';
|
||||||
$string['eventcoursecategoryupdated'] = 'Category updated';
|
$string['eventcoursecategoryupdated'] = 'Category updated';
|
||||||
|
|
118
lib/classes/event/course_backup_created.php
Normal file
118
lib/classes/event/course_backup_created.php
Normal file
|
@ -0,0 +1,118 @@
|
||||||
|
<?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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Course backup created event.
|
||||||
|
*
|
||||||
|
* @package core
|
||||||
|
* @copyright 2017 Stephen Bourget
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace core\event;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Course backup created event class.
|
||||||
|
*
|
||||||
|
* @property-read array $other {
|
||||||
|
* Extra information about event.
|
||||||
|
*
|
||||||
|
* - string format: Format of backup (moodle, imscc)
|
||||||
|
* - int mode: execution mode.
|
||||||
|
* - boolean interactive: Interactive mode (yes/no)
|
||||||
|
* - string type: backup type
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* @package core
|
||||||
|
* @since Moodle 3.4
|
||||||
|
* @copyright 2017 Stephen Bourget
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class course_backup_created extends base {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialise the event data.
|
||||||
|
*/
|
||||||
|
protected function init() {
|
||||||
|
$this->data['objecttable'] = 'course';
|
||||||
|
$this->data['crud'] = 'c';
|
||||||
|
$this->data['edulevel'] = self::LEVEL_TEACHING;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns localised general event name.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_name() {
|
||||||
|
return get_string('eventcoursebackupcreated');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns non-localised description of what happened.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function get_description() {
|
||||||
|
return "The user with id '$this->userid' created a backup of the course with the id '$this->objectid'.";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns relevant URL.
|
||||||
|
*
|
||||||
|
* @return \moodle_url
|
||||||
|
*/
|
||||||
|
public function get_url() {
|
||||||
|
return new \moodle_url('/course/view.php', array('id' => $this->objectid));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom validation.
|
||||||
|
*
|
||||||
|
* @throws \coding_exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function validate_data() {
|
||||||
|
parent::validate_data();
|
||||||
|
|
||||||
|
if (!isset($this->other['format'])) {
|
||||||
|
throw new \coding_exception('The \'format\' value must be set in other.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($this->other['mode'])) {
|
||||||
|
throw new \coding_exception('The \'mode\' value must be set in other.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($this->other['interactive'])) {
|
||||||
|
throw new \coding_exception('The \'interactive\' value must be set in other.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($this->other['type'])) {
|
||||||
|
throw new \coding_exception('The \'type\' value must be set in other.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get_objectid_mapping() {
|
||||||
|
return array('db' => 'course', 'restore' => 'course');
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get_other_mapping() {
|
||||||
|
// No need to map anything.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue