MDL-43661 change event property level to edulevel
Level is a reserved word in sql, sorry.
This commit is contained in:
+29
-11
@@ -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]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user