mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 20:42:22 +02:00
MDL-43661 change event property level to edulevel
Level is a reserved word in sql, sorry.
This commit is contained in:
parent
0758665c0d
commit
3345e24f4b
@ -40,7 +40,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @property-read string $objecttable name of database table where is object record stored
|
||||
* @property-read int $objectid optional id of the object
|
||||
* @property-read string $crud letter indicating event type
|
||||
* @property-read int $level log level (number between 1 and 100)
|
||||
* @property-read int $edulevel log level (one of the constants LEVEL_)
|
||||
* @property-read int $contextid
|
||||
* @property-read int $contextlevel
|
||||
* @property-read int $contextinstanceid
|
||||
@ -101,7 +101,7 @@ abstract class base implements \IteratorAggregate {
|
||||
|
||||
/** @var array list of event properties */
|
||||
private static $fields = array(
|
||||
'eventname', 'component', 'action', 'target', 'objecttable', 'objectid', 'crud', 'level', 'contextid',
|
||||
'eventname', 'component', 'action', 'target', 'objecttable', 'objectid', 'crud', 'edulevel', 'contextid',
|
||||
'contextlevel', 'contextinstanceid', 'userid', 'courseid', 'relateduserid', 'other',
|
||||
'timecreated');
|
||||
|
||||
@ -148,7 +148,7 @@ abstract class base implements \IteratorAggregate {
|
||||
* @throws \coding_exception
|
||||
*/
|
||||
public static final function create(array $data = null) {
|
||||
global $PAGE, $USER, $CFG;
|
||||
global $USER, $CFG;
|
||||
|
||||
$data = (array)$data;
|
||||
|
||||
@ -161,6 +161,14 @@ abstract class base implements \IteratorAggregate {
|
||||
// Set static event data specific for child class.
|
||||
$event->init();
|
||||
|
||||
if (isset($event->data['level'])) {
|
||||
if (!isset($event->data['edulevel'])) {
|
||||
debugging('level property is deprecated, use edulevel property instead', DEBUG_DEVELOPER);
|
||||
$event->data['edulevel'] = $event->data['level'];
|
||||
}
|
||||
unset($event->data['level']);
|
||||
}
|
||||
|
||||
// Set automatic data.
|
||||
$event->data['timecreated'] = time();
|
||||
|
||||
@ -205,7 +213,7 @@ abstract class base implements \IteratorAggregate {
|
||||
// Warn developers if they do something wrong.
|
||||
if ($CFG->debugdeveloper) {
|
||||
static $automatickeys = array('eventname', 'component', 'action', 'target', 'contextlevel', 'contextinstanceid', 'timecreated');
|
||||
static $initkeys = array('crud', 'level', 'objecttable');
|
||||
static $initkeys = array('crud', 'level', 'objecttable', 'edulevel');
|
||||
|
||||
foreach ($data as $key => $ignored) {
|
||||
if ($key === 'context') {
|
||||
@ -234,7 +242,7 @@ abstract class base implements \IteratorAggregate {
|
||||
*
|
||||
* Set all required data properties:
|
||||
* 1/ crud - letter [crud]
|
||||
* 2/ level - using a constant self::LEVEL_*.
|
||||
* 2/ edulevel - using a constant self::LEVEL_*.
|
||||
* 3/ objecttable - name of database table if objectid specified
|
||||
*
|
||||
* Optionally it can set:
|
||||
@ -362,7 +370,7 @@ abstract class base implements \IteratorAggregate {
|
||||
/**
|
||||
* Return standardised event data as array.
|
||||
*
|
||||
* @return array
|
||||
* @return array All elements are scalars except the 'other' field which is array.
|
||||
*/
|
||||
public function get_data() {
|
||||
return $this->data;
|
||||
@ -371,7 +379,9 @@ abstract class base implements \IteratorAggregate {
|
||||
/**
|
||||
* Return auxiliary data that was stored in logs.
|
||||
*
|
||||
* TODO MDL-41331: Properly define this method once logging is finalised.
|
||||
* List of standard properties:
|
||||
* - origin: IP number, cli,cron
|
||||
* - realuserid: id of the user when logged-in-as
|
||||
*
|
||||
* @return array the format is standardised by logging API
|
||||
*/
|
||||
@ -425,8 +435,8 @@ abstract class base implements \IteratorAggregate {
|
||||
if (empty($this->data['crud'])) {
|
||||
throw new \coding_exception('crud must be specified in init() method of each method');
|
||||
}
|
||||
if (!isset($this->data['level'])) {
|
||||
throw new \coding_exception('level must be specified in init() method of each method');
|
||||
if (!isset($this->data['edulevel'])) {
|
||||
throw new \coding_exception('edulevel must be specified in init() method of each method');
|
||||
}
|
||||
if (!empty($this->data['objectid']) and empty($this->data['objecttable'])) {
|
||||
throw new \coding_exception('objecttable must be specified in init() method if objectid present');
|
||||
@ -439,9 +449,9 @@ abstract class base implements \IteratorAggregate {
|
||||
if (!in_array($this->data['crud'], array('c', 'r', 'u', 'd'), true)) {
|
||||
debugging("Invalid event crud value specified.", DEBUG_DEVELOPER);
|
||||
}
|
||||
if (!in_array($this->data['level'], array(self::LEVEL_OTHER, self::LEVEL_TEACHING, self::LEVEL_PARTICIPATING))) {
|
||||
if (!in_array($this->data['edulevel'], array(self::LEVEL_OTHER, self::LEVEL_TEACHING, self::LEVEL_PARTICIPATING))) {
|
||||
// Bitwise combination of levels is not allowed at this stage.
|
||||
debugging('Event property level must a constant value, see event_base::LEVEL_*', DEBUG_DEVELOPER);
|
||||
debugging('Event property edulevel must a constant value, see event_base::LEVEL_*', DEBUG_DEVELOPER);
|
||||
}
|
||||
if (self::$fields !== array_keys($this->data)) {
|
||||
debugging('Number of event data fields must not be changed in event classes', DEBUG_DEVELOPER);
|
||||
@ -601,6 +611,10 @@ abstract class base implements \IteratorAggregate {
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($name) {
|
||||
if ($name === 'level') {
|
||||
debugging('level property is deprecated, use edulevel property instead', DEBUG_DEVELOPER);
|
||||
return $this->data['edulevel'];
|
||||
}
|
||||
if (array_key_exists($name, $this->data)) {
|
||||
return $this->data[$name];
|
||||
}
|
||||
@ -630,6 +644,10 @@ abstract class base implements \IteratorAggregate {
|
||||
* @return bool
|
||||
*/
|
||||
public function __isset($name) {
|
||||
if ($name === 'level') {
|
||||
debugging('level property is deprecated, use edulevel property instead', DEBUG_DEVELOPER);
|
||||
return isset($this->data['edulevel']);
|
||||
}
|
||||
return isset($this->data[$name]);
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ class core_event_testcase extends advanced_testcase {
|
||||
$this->assertSame('unittest', $event->target);
|
||||
$this->assertSame(5, $event->objectid);
|
||||
$this->assertSame('u', $event->crud);
|
||||
$this->assertSame(\core\event\base::LEVEL_PARTICIPATING, $event->level);
|
||||
$this->assertSame(\core\event\base::LEVEL_PARTICIPATING, $event->edulevel);
|
||||
|
||||
$this->assertEquals($system, $event->get_context());
|
||||
$this->assertSame($system->id, $event->contextid);
|
||||
@ -451,6 +451,23 @@ class core_event_testcase extends advanced_testcase {
|
||||
\core_tests\event\unittest_observer::$info);
|
||||
}
|
||||
|
||||
public function test_deprecated() {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
$event = \core_tests\event\deprecated_event1::create();
|
||||
$this->assertDebuggingCalled('level property is deprecated, use edulevel property instead');
|
||||
|
||||
$this->assertSame($event::LEVEL_TEACHING, $event->level);
|
||||
$this->assertDebuggingCalled('level property is deprecated, use edulevel property instead');
|
||||
|
||||
$this->assertTrue(isset($event->level));
|
||||
$this->assertDebuggingCalled('level property is deprecated, use edulevel property instead');
|
||||
|
||||
$this->assertSame($event::LEVEL_TEACHING, $event->edulevel);
|
||||
}
|
||||
|
||||
public function test_legacy() {
|
||||
global $DB;
|
||||
|
||||
|
38
lib/tests/fixtures/event_fixtures.php
vendored
38
lib/tests/fixtures/event_fixtures.php
vendored
@ -41,7 +41,7 @@ class unittest_executed extends \core\event\base {
|
||||
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'u';
|
||||
$this->data['level'] = self::LEVEL_PARTICIPATING;
|
||||
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
|
||||
}
|
||||
|
||||
public function get_url() {
|
||||
@ -116,14 +116,14 @@ class unittest_observer {
|
||||
class bad_event1 extends \core\event\base {
|
||||
protected function init() {
|
||||
//$this->data['crud'] = 'u';
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
}
|
||||
}
|
||||
|
||||
class bad_event2 extends \core\event\base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'u';
|
||||
//$this->data['level'] = 10;
|
||||
//$this->data['edulevel'] = 10;
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,14 +131,14 @@ class bad_event2b extends \core\event\base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'u';
|
||||
// Invalid level value.
|
||||
$this->data['level'] = -1;
|
||||
$this->data['edulevel'] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
class bad_event3 extends \core\event\base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'u';
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
unset($this->data['courseid']);
|
||||
}
|
||||
}
|
||||
@ -146,7 +146,7 @@ class bad_event3 extends \core\event\base {
|
||||
class bad_event4 extends \core\event\base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'u';
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
$this->data['xxx'] = 1;
|
||||
}
|
||||
}
|
||||
@ -154,14 +154,14 @@ class bad_event4 extends \core\event\base {
|
||||
class bad_event5 extends \core\event\base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'x';
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
}
|
||||
}
|
||||
|
||||
class bad_event6 extends \core\event\base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'c';
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
$this->data['objecttable'] = 'xxx_xxx_xx';
|
||||
}
|
||||
}
|
||||
@ -169,7 +169,7 @@ class bad_event6 extends \core\event\base {
|
||||
class bad_event7 extends \core\event\base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'c';
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
$this->data['objecttable'] = null;
|
||||
}
|
||||
}
|
||||
@ -177,7 +177,7 @@ class bad_event7 extends \core\event\base {
|
||||
class bad_event8 extends \core\event\base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'c';
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
$this->data['objecttable'] = 'user';
|
||||
}
|
||||
}
|
||||
@ -185,14 +185,14 @@ class bad_event8 extends \core\event\base {
|
||||
class problematic_event1 extends \core\event\base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'u';
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
}
|
||||
}
|
||||
|
||||
class problematic_event2 extends \core\event\base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'c';
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
$this->context = \context_system::instance();
|
||||
}
|
||||
}
|
||||
@ -200,7 +200,7 @@ class problematic_event2 extends \core\event\base {
|
||||
class problematic_event3 extends \core\event\base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'c';
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
$this->context = \context_system::instance();
|
||||
}
|
||||
|
||||
@ -211,11 +211,19 @@ class problematic_event3 extends \core\event\base {
|
||||
}
|
||||
}
|
||||
|
||||
class deprecated_event1 extends \core\event\base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'c';
|
||||
$this->data['level'] = self::LEVEL_TEACHING; // Tests edulevel hint.
|
||||
$this->context = \context_system::instance();
|
||||
}
|
||||
}
|
||||
|
||||
class noname_event extends \core\event\base {
|
||||
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'c';
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
$this->context = \context_system::instance();
|
||||
}
|
||||
}
|
||||
@ -237,7 +245,7 @@ class content_viewed extends \core\event\content_viewed {
|
||||
class course_module_viewed extends \core\event\course_module_viewed {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'r';
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
$this->data['objecttable'] = 'feedback';
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ information provided here is intended especially for developers.
|
||||
* $core_renderer->block_move_target() changed to support more verbose move-block-here descriptions.
|
||||
|
||||
DEPRECATIONS:
|
||||
* Update init methods in all event classes - "level" property was renamed to "edulevel", the level property is now deprecated.
|
||||
* Abstract class \core\event\course_module_instances_list_viewed is deprecated now, use \core\event\instances_list_viewed instead.
|
||||
* mod_book\event\instances_list_viewed has been deprecated. Please use mod_book\event\course_module_instance_list_viewed instead.
|
||||
* mod_chat\event\instances_list_viewed has been deprecated. Please use mod_chat\event\course_module_instance_list_viewed instead.
|
||||
|
Loading…
x
Reference in New Issue
Block a user