mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
MDL-39846 rename 'extra' event property to 'other'
This commit is contained in:
parent
605a8c336f
commit
c4297815eb
@ -1687,7 +1687,7 @@ function role_assign($roleid, $userid, $contextid, $component = '', $itemid = 0,
|
||||
|
||||
$event = \core\event\role_assigned::create(
|
||||
array('context'=>$context, 'objectid'=>$ra->roleid, 'relateduserid'=>$ra->userid,
|
||||
'extra'=>array('id'=>$ra->id, 'component'=>$ra->component, 'itemid'=>$ra->itemid)));
|
||||
'other'=>array('id'=>$ra->id, 'component'=>$ra->component, 'itemid'=>$ra->itemid)));
|
||||
$event->add_cached_record('role_assignments', $ra);
|
||||
$event->trigger();
|
||||
|
||||
@ -1775,7 +1775,7 @@ function role_unassign_all(array $params, $subcontexts = false, $includemanual =
|
||||
}
|
||||
$event = \core\event\role_unassigned::create(
|
||||
array('context'=>$context, 'objectid'=>$ra->roleid, 'relateduserid'=>$ra->userid,
|
||||
'extra'=>array('id'=>$ra->id, 'component'=>$ra->component, 'itemid'=>$ra->itemid)));
|
||||
'other'=>array('id'=>$ra->id, 'component'=>$ra->component, 'itemid'=>$ra->itemid)));
|
||||
$event->add_cached_record('role_assignments', $ra);
|
||||
$event->trigger();
|
||||
}
|
||||
@ -1806,7 +1806,7 @@ function role_unassign_all(array $params, $subcontexts = false, $includemanual =
|
||||
}
|
||||
$event = \core\event\role_unassigned::create(
|
||||
array('context'=>$context, 'objectid'=>$ra->roleid, 'relateduserid'=>$ra->userid,
|
||||
'extra'=>array('id'=>$ra->id, 'component'=>$ra->component, 'itemid'=>$ra->itemid)));
|
||||
'other'=>array('id'=>$ra->id, 'component'=>$ra->component, 'itemid'=>$ra->itemid)));
|
||||
$event->add_cached_record('role_assignments', $ra);
|
||||
$event->trigger();
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ namespace core\event;
|
||||
* @property-read int $userid who did this?
|
||||
* @property-read int $courseid
|
||||
* @property-read int $relateduserid
|
||||
* @property-read mixed $extra array or scalar, can not contain objects
|
||||
* @property-read mixed $other array or scalar, can not contain objects
|
||||
* @property-read int $timecreated
|
||||
*/
|
||||
abstract class base {
|
||||
@ -79,7 +79,7 @@ abstract class base {
|
||||
/** @var array list of event properties */
|
||||
private static $fields = array(
|
||||
'eventname', 'component', 'action', 'object', 'objectid', 'crud', 'level', 'contextid',
|
||||
'contextlevel', 'contextinstanceid', 'userid', 'courseid', 'relateduserid', 'extra',
|
||||
'contextlevel', 'contextinstanceid', 'userid', 'courseid', 'relateduserid', 'other',
|
||||
'timecreated');
|
||||
|
||||
/** @var array simple record cache */
|
||||
@ -98,7 +98,7 @@ abstract class base {
|
||||
* The optional data keys as:
|
||||
* 1/ objectid - the id of the object specified in class name
|
||||
* 2/ context - the context of this event
|
||||
* 3/ extra - the extra data describing the event, can not contain objects
|
||||
* 3/ other - the other data describing the event, can not contain objects
|
||||
* 4/ relateduserid - the id of user which is somehow related to this event
|
||||
*
|
||||
* @param array $data
|
||||
@ -139,7 +139,7 @@ abstract class base {
|
||||
$event->data['objectid'] = isset($data['objectid']) ? $data['objectid'] : null;
|
||||
$event->data['courseid'] = isset($data['courseid']) ? $data['courseid'] : null;
|
||||
$event->data['userid'] = isset($data['userid']) ? $data['userid'] : $USER->id;
|
||||
$event->data['extra'] = isset($data['extra']) ? $data['extra'] : null;
|
||||
$event->data['other'] = isset($data['other']) ? $data['other'] : null;
|
||||
$event->data['relateduserid'] = isset($data['relateduserid']) ? $data['relateduserid'] : null;
|
||||
|
||||
$event->context = null;
|
||||
@ -171,7 +171,7 @@ abstract class base {
|
||||
$event->data['relateduserid'] = $event->context->instanceid;
|
||||
}
|
||||
|
||||
// Set static event data specific for child class, this should also validate extra data.
|
||||
// Set static event data specific for child class, this should also validate other data.
|
||||
$event->init();
|
||||
|
||||
// Warn developers if they do something wrong.
|
||||
@ -207,7 +207,7 @@ abstract class base {
|
||||
*
|
||||
* TODO: MDL-37658
|
||||
*
|
||||
* Optionally validate $this->data['extra'].
|
||||
* Optionally validate $this->data['other'].
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -397,9 +397,9 @@ abstract class base {
|
||||
if (self::$fields !== array_keys($this->data)) {
|
||||
debugging('Number of event data fields must not be changed in event classes');
|
||||
}
|
||||
$encoded = json_encode($this->data['extra']);
|
||||
if ($encoded === false or $this->data['extra'] !== json_decode($encoded, true)) {
|
||||
debugging('Extra event data must be compatible with json encoding');
|
||||
$encoded = json_encode($this->data['other']);
|
||||
if ($encoded === false or $this->data['other'] !== json_decode($encoded, true)) {
|
||||
debugging('other event data must be compatible with json encoding');
|
||||
}
|
||||
if ($this->data['userid'] and !is_number($this->data['userid'])) {
|
||||
debugging('Event property userid must be a number');
|
||||
|
@ -74,6 +74,6 @@ class role_assigned extends base {
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_legacy_eventdata() {
|
||||
return $this->get_cached_record('role_assignments', $this->data['extra']['id']);
|
||||
return $this->get_cached_record('role_assignments', $this->data['other']['id']);
|
||||
}
|
||||
}
|
||||
|
@ -74,6 +74,6 @@ class role_unassigned extends base {
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_legacy_eventdata() {
|
||||
return $this->get_cached_record('role_assignments', $this->data['extra']['id']);
|
||||
return $this->get_cached_record('role_assignments', $this->data['other']['id']);
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ class core_event_testcase extends advanced_testcase {
|
||||
global $USER;
|
||||
|
||||
$system = \context_system::instance();
|
||||
$event = \core_tests\event\unittest_executed::create(array('courseid'=>1, 'context'=>$system, 'objectid'=>5, 'extra'=>array('sample'=>null, 'xx'=>10)));
|
||||
$event = \core_tests\event\unittest_executed::create(array('courseid'=>1, 'context'=>$system, 'objectid'=>5, 'other'=>array('sample'=>null, 'xx'=>10)));
|
||||
|
||||
$this->assertSame('\core_tests\event\unittest_executed', $event->eventname);
|
||||
$this->assertSame('core_tests', $event->component);
|
||||
@ -54,9 +54,9 @@ class core_event_testcase extends advanced_testcase {
|
||||
$this->assertNull($event->relateduserid);
|
||||
$this->assertFalse(isset($event->relateduserid));
|
||||
|
||||
$this->assertSame(array('sample'=>null, 'xx'=>10), $event->extra);
|
||||
$this->assertTrue(isset($event->extra['xx']));
|
||||
$this->assertFalse(isset($event->extra['sample']));
|
||||
$this->assertSame(array('sample'=>null, 'xx'=>10), $event->other);
|
||||
$this->assertTrue(isset($event->other['xx']));
|
||||
$this->assertFalse(isset($event->other['sample']));
|
||||
|
||||
$this->assertLessThanOrEqual(time(), $event->timecreated);
|
||||
|
||||
@ -253,7 +253,7 @@ class core_event_testcase extends advanced_testcase {
|
||||
\core\event\manager::phpunit_replace_observers($observers);
|
||||
\core_tests\event\unittest_observer::reset();
|
||||
|
||||
$event1 = \core_tests\event\unittest_executed::create(array('courseid'=>1, 'context'=>\context_system::instance(), 'extra'=>array('sample'=>1, 'xx'=>10)));
|
||||
$event1 = \core_tests\event\unittest_executed::create(array('courseid'=>1, 'context'=>\context_system::instance(), 'other'=>array('sample'=>1, 'xx'=>10)));
|
||||
$event1->nest = 1;
|
||||
$this->assertFalse($event1->is_triggered());
|
||||
$this->assertFalse($event1->is_dispatched());
|
||||
@ -263,7 +263,7 @@ class core_event_testcase extends advanced_testcase {
|
||||
$this->assertTrue($event1->is_dispatched());
|
||||
$this->assertFalse($event1->is_restored());
|
||||
|
||||
$event1 = \core_tests\event\unittest_executed::create(array('courseid'=>2, 'context'=>\context_system::instance(), 'extra'=>array('sample'=>2, 'xx'=>10)));
|
||||
$event1 = \core_tests\event\unittest_executed::create(array('courseid'=>2, 'context'=>\context_system::instance(), 'other'=>array('sample'=>2, 'xx'=>10)));
|
||||
$event1->trigger();
|
||||
|
||||
$this->assertSame(
|
||||
@ -289,11 +289,11 @@ class core_event_testcase extends advanced_testcase {
|
||||
\core\event\manager::phpunit_replace_observers($observers);
|
||||
\core_tests\event\unittest_observer::reset();
|
||||
|
||||
$event1 = \core_tests\event\unittest_executed::create(array('courseid'=>1, 'context'=>\context_system::instance(), 'extra'=>array('sample'=>1, 'xx'=>10)));
|
||||
$event1 = \core_tests\event\unittest_executed::create(array('courseid'=>1, 'context'=>\context_system::instance(), 'other'=>array('sample'=>1, 'xx'=>10)));
|
||||
$event1->trigger();
|
||||
$this->assertDebuggingCalled();
|
||||
|
||||
$event1 = \core_tests\event\unittest_executed::create(array('courseid'=>2, 'context'=>\context_system::instance(), 'extra'=>array('sample'=>2, 'xx'=>10)));
|
||||
$event1 = \core_tests\event\unittest_executed::create(array('courseid'=>2, 'context'=>\context_system::instance(), 'other'=>array('sample'=>2, 'xx'=>10)));
|
||||
$event1->trigger();
|
||||
$this->assertDebuggingCalled();
|
||||
|
||||
@ -325,9 +325,9 @@ class core_event_testcase extends advanced_testcase {
|
||||
\core\event\manager::phpunit_replace_observers($observers);
|
||||
\core_tests\event\unittest_observer::reset();
|
||||
|
||||
$event1 = \core_tests\event\unittest_executed::create(array('courseid'=>1, 'context'=>\context_system::instance(), 'extra'=>array('sample'=>1, 'xx'=>10)));
|
||||
$event1 = \core_tests\event\unittest_executed::create(array('courseid'=>1, 'context'=>\context_system::instance(), 'other'=>array('sample'=>1, 'xx'=>10)));
|
||||
$event1->trigger();
|
||||
$event2 = \core_tests\event\unittest_executed::create(array('courseid'=>2, 'context'=>\context_system::instance(), 'extra'=>array('sample'=>2, 'xx'=>10)));
|
||||
$event2 = \core_tests\event\unittest_executed::create(array('courseid'=>2, 'context'=>\context_system::instance(), 'other'=>array('sample'=>2, 'xx'=>10)));
|
||||
$event2->trigger();
|
||||
|
||||
$this->assertSame(
|
||||
@ -341,9 +341,9 @@ class core_event_testcase extends advanced_testcase {
|
||||
|
||||
$trans = $DB->start_delegated_transaction();
|
||||
|
||||
$event1 = \core_tests\event\unittest_executed::create(array('courseid'=>1, 'context'=>\context_system::instance(), 'extra'=>array('sample'=>1, 'xx'=>10)));
|
||||
$event1 = \core_tests\event\unittest_executed::create(array('courseid'=>1, 'context'=>\context_system::instance(), 'other'=>array('sample'=>1, 'xx'=>10)));
|
||||
$event1->trigger();
|
||||
$event2 = \core_tests\event\unittest_executed::create(array('courseid'=>2, 'context'=>\context_system::instance(), 'extra'=>array('sample'=>2, 'xx'=>10)));
|
||||
$event2 = \core_tests\event\unittest_executed::create(array('courseid'=>2, 'context'=>\context_system::instance(), 'other'=>array('sample'=>2, 'xx'=>10)));
|
||||
$event2->trigger();
|
||||
|
||||
$this->assertSame(
|
||||
@ -359,10 +359,10 @@ class core_event_testcase extends advanced_testcase {
|
||||
\core\event\manager::phpunit_replace_observers($observers);
|
||||
\core_tests\event\unittest_observer::reset();
|
||||
|
||||
$event1 = \core_tests\event\unittest_executed::create(array('courseid'=>1, 'context'=>\context_system::instance(), 'extra'=>array('sample'=>1, 'xx'=>10)));
|
||||
$event1 = \core_tests\event\unittest_executed::create(array('courseid'=>1, 'context'=>\context_system::instance(), 'other'=>array('sample'=>1, 'xx'=>10)));
|
||||
$event1->trigger();
|
||||
$trans = $DB->start_delegated_transaction();
|
||||
$event2 = \core_tests\event\unittest_executed::create(array('courseid'=>2, 'context'=>\context_system::instance(), 'extra'=>array('sample'=>2, 'xx'=>10)));
|
||||
$event2 = \core_tests\event\unittest_executed::create(array('courseid'=>2, 'context'=>\context_system::instance(), 'other'=>array('sample'=>2, 'xx'=>10)));
|
||||
$event2->trigger();
|
||||
try {
|
||||
$trans->rollback(new \moodle_exception('xxx'));
|
||||
@ -404,10 +404,10 @@ class core_event_testcase extends advanced_testcase {
|
||||
\core\event\manager::phpunit_replace_observers($observers);
|
||||
\core_tests\event\unittest_observer::reset();
|
||||
|
||||
$event1 = \core_tests\event\unittest_executed::create(array('courseid'=>1, 'context'=>\context_system::instance(), 'extra'=>array('sample'=>5, 'xx'=>10)));
|
||||
$event1 = \core_tests\event\unittest_executed::create(array('courseid'=>1, 'context'=>\context_system::instance(), 'other'=>array('sample'=>5, 'xx'=>10)));
|
||||
$event1->trigger();
|
||||
|
||||
$event2 = \core_tests\event\unittest_executed::create(array('courseid'=>2, 'context'=>\context_system::instance(), 'extra'=>array('sample'=>6, 'xx'=>11)));
|
||||
$event2 = \core_tests\event\unittest_executed::create(array('courseid'=>2, 'context'=>\context_system::instance(), 'other'=>array('sample'=>6, 'xx'=>11)));
|
||||
$event2->nest = true;
|
||||
$event2->trigger();
|
||||
|
||||
@ -441,7 +441,7 @@ class core_event_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
public function test_restore_event() {
|
||||
$event1 = \core_tests\event\unittest_executed::create(array('courseid'=>1, 'context'=>\context_system::instance(), 'extra'=>array('sample'=>1, 'xx'=>10)));
|
||||
$event1 = \core_tests\event\unittest_executed::create(array('courseid'=>1, 'context'=>\context_system::instance(), 'other'=>array('sample'=>1, 'xx'=>10)));
|
||||
$data1 = $event1->get_data();
|
||||
|
||||
$event2 = \core\event\base::restore($data1, array('origin'=>'clid'));
|
||||
@ -475,7 +475,7 @@ class core_event_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
public function test_trigger_problems() {
|
||||
$event = \core_tests\event\unittest_executed::create(array('courseid'=>1, 'context'=>\context_system::instance(), 'extra'=>array('sample'=>5, 'xx'=>10)));
|
||||
$event = \core_tests\event\unittest_executed::create(array('courseid'=>1, 'context'=>\context_system::instance(), 'other'=>array('sample'=>5, 'xx'=>10)));
|
||||
$event->trigger();
|
||||
try {
|
||||
$event->trigger();
|
||||
@ -496,7 +496,7 @@ class core_event_testcase extends advanced_testcase {
|
||||
$this->assertInstanceOf('coding_exception', $e);
|
||||
}
|
||||
|
||||
$event = \core_tests\event\unittest_executed::create(array('courseid'=>1, 'context'=>\context_system::instance(), 'extra'=>array('sample'=>5, 'xx'=>10)));
|
||||
$event = \core_tests\event\unittest_executed::create(array('courseid'=>1, 'context'=>\context_system::instance(), 'other'=>array('sample'=>5, 'xx'=>10)));
|
||||
try {
|
||||
\core\event\manager::dispatch($event);
|
||||
$this->fail('Exception expected on manual event dispatching');
|
||||
@ -550,17 +550,17 @@ class core_event_testcase extends advanced_testcase {
|
||||
$this->assertDebuggingNotCalled();
|
||||
$CFG->debug = E_ALL | E_STRICT;
|
||||
|
||||
$event4 = \core_tests\event\problematic_event1::create(array('extra'=>array('a'=>1)));
|
||||
$event4 = \core_tests\event\problematic_event1::create(array('other'=>array('a'=>1)));
|
||||
$event4->trigger();
|
||||
$this->assertDebuggingNotCalled();
|
||||
|
||||
$event5 = \core_tests\event\problematic_event1::create(array('extra'=>(object)array('a'=>1)));
|
||||
$event5 = \core_tests\event\problematic_event1::create(array('other'=>(object)array('a'=>1)));
|
||||
$this->assertDebuggingNotCalled();
|
||||
$event5->trigger();
|
||||
$this->assertDebuggingCalled();
|
||||
|
||||
$url = new moodle_url('/admin/');
|
||||
$event6 = \core_tests\event\problematic_event1::create(array('extra'=>array('a'=>$url)));
|
||||
$event6 = \core_tests\event\problematic_event1::create(array('other'=>array('a'=>$url)));
|
||||
$this->assertDebuggingNotCalled();
|
||||
$event6->trigger();
|
||||
$this->assertDebuggingCalled();
|
||||
@ -569,7 +569,7 @@ class core_event_testcase extends advanced_testcase {
|
||||
public function test_record_cache() {
|
||||
global $DB;
|
||||
|
||||
$event = \core_tests\event\unittest_executed::create(array('courseid'=>1, 'context'=>\context_system::instance(), 'extra'=>array('sample'=>1, 'xx'=>10)));
|
||||
$event = \core_tests\event\unittest_executed::create(array('courseid'=>1, 'context'=>\context_system::instance(), 'other'=>array('sample'=>1, 'xx'=>10)));
|
||||
$course1 = $DB->get_record('course', array('id'=>1));
|
||||
$this->assertNotEmpty($course1);
|
||||
|
||||
|
8
lib/tests/fixtures/event_fixtures.php
vendored
8
lib/tests/fixtures/event_fixtures.php
vendored
@ -45,7 +45,7 @@ class unittest_executed extends \core\event\base {
|
||||
}
|
||||
|
||||
public function get_url() {
|
||||
return new moodle_url('/somepath/somefile.php', array('id'=>$this->data['extra']['sample']));
|
||||
return new moodle_url('/somepath/somefile.php', array('id'=>$this->data['other']['sample']));
|
||||
}
|
||||
|
||||
public function get_legacy_eventname() {
|
||||
@ -53,11 +53,11 @@ class unittest_executed extends \core\event\base {
|
||||
}
|
||||
|
||||
public function get_legacy_eventdata() {
|
||||
return array($this->data['courseid'], $this->data['extra']['sample']);
|
||||
return array($this->data['courseid'], $this->data['other']['sample']);
|
||||
}
|
||||
|
||||
public function get_legacy_logdata() {
|
||||
return array($this->data['courseid'], 'core_unittest', 'view', 'unittest.php?id='.$this->data['extra']['sample']);
|
||||
return array($this->data['courseid'], 'core_unittest', 'view', 'unittest.php?id='.$this->data['other']['sample']);
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ class unittest_observer {
|
||||
self::$event[] = $event;
|
||||
if ($event->nest) {
|
||||
self::$info[] = 'observe_all-nesting-'.$event->courseid;
|
||||
unittest_executed::create(array('courseid'=>3, 'context'=>\context_system::instance(), 'extra'=>array('sample'=>666, 'xx'=>666)))->trigger();
|
||||
unittest_executed::create(array('courseid'=>3, 'context'=>\context_system::instance(), 'other'=>array('sample'=>666, 'xx'=>666)))->trigger();
|
||||
} else {
|
||||
self::$info[] = 'observe_all-'.$event->courseid;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user