Skip to content

Commit

Permalink
MDL-49291 core: final deprecation of sql_*_reader interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjnelson committed Jan 18, 2016
1 parent e8d5100 commit 806905b
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 234 deletions.
32 changes: 0 additions & 32 deletions admin/tool/log/classes/log/manager.php
Expand Up @@ -106,38 +106,6 @@ public function get_readers($interface = null) {
if (empty($interface) || ($reader instanceof $interface)) {
$return[$plugin] = $reader;
}
// TODO MDL-49291 These conditions should be removed as part of the 2nd stage deprecation.
if ($reader instanceof \core\log\sql_internal_reader) {
debugging('\core\log\sql_internal_reader has been deprecated in favour of \core\log\sql_internal_table_reader.' .
' Update ' . get_class($reader) . ' to use the new interface.', DEBUG_DEVELOPER);
} else if ($reader instanceof \core\log\sql_select_reader) {
debugging('\core\log\sql_select_reader has been deprecated in favour of \core\log\sql_reader. Update ' .
get_class($reader) . ' to use the new interface.', DEBUG_DEVELOPER);
}
}

// TODO MDL-49291 This section below (until the final return) should be removed as part of the 2nd stage deprecation.
$isselectreader = (ltrim($interface, '\\') === 'core\log\sql_select_reader');
$isinternalreader = (ltrim($interface, '\\') === 'core\log\sql_internal_reader');
if ($isselectreader || $isinternalreader) {

if ($isselectreader) {
$alternative = '\core\log\sql_reader';
} else {
$alternative = '\core\log\sql_internal_table_reader';
}

if (count($return) === 0) {
// If there are no classes implementing the provided interface and the provided interface is one of
// the deprecated ones, we return the non-deprecated alternatives. It should be safe as the new interface
// is adding a new method but not changing the existing ones.
debugging($interface . ' has been deprecated in favour of ' . $alternative . '. Returning ' . $alternative .
' instances instead. Please call get_readers() using the new interface.', DEBUG_DEVELOPER);
$return = $this->get_readers($alternative);
} else {
debugging($interface . ' has been deprecated in favour of ' . $alternative .
'. Please call get_readers() using the new interface.', DEBUG_DEVELOPER);
}
}

return $return;
Expand Down
50 changes: 0 additions & 50 deletions lib/classes/log/sql_internal_reader.php

This file was deleted.

60 changes: 0 additions & 60 deletions lib/classes/log/sql_select_reader.php

This file was deleted.

94 changes: 2 additions & 92 deletions report/log/classes/table_log.php
Expand Up @@ -36,13 +36,6 @@ class report_log_table_log extends table_sql {
/** @var array list of user fullnames shown in report */
private $userfullnames = array();

/**
* @deprecated since Moodle 2.9 MDL-48595 - please do not use this argument any more.
* @todo MDL-49291 This will be deleted in 3.1
* @var array list of course short names shown in report.
*/
private $courseshortnames = array();

/** @var array list of context name shown in report */
private $contextname = array();

Expand Down Expand Up @@ -99,19 +92,9 @@ public function __construct($uniqueid, $filterparams = null) {
* Generate the course column.
*
* @deprecated since Moodle 2.9 MDL-48595 - please do not use this function any more.
* @todo MDL-49291 This will be deleted in 3.1
* @param stdClass $event event data.
* @return string HTML for the course column.
*/
public function col_course($event) {

debugging('col_course() is deprecated, there is no such column', DEBUG_DEVELOPER);

if (empty($event->courseid) || empty($this->courseshortnames[$event->courseid])) {
return '-';
} else {
return $this->courseshortnames[$event->courseid];
}
throw new coding_exception('col_course() can not be used any more, there is no such column.');
}

/**
Expand Down Expand Up @@ -544,82 +527,9 @@ public function query_db($pagesize, $useinitialsbar = true) {
* which will be used to render logs in table.
*
* @deprecated since Moodle 2.9 MDL-48595 - please do not use this function any more.
* @todo MDL-49291 This will be deleted in 3.1
* @see self::update_users_used()
*/
public function update_users_and_courses_used() {
global $SITE, $DB;

debugging('update_users_and_courses_used() is deprecated, please use update_users_used() instead.', DEBUG_DEVELOPER);

// We should not call self::update_users_used() as would have to iterate twice around the list of logs.

$this->userfullnames = array();
$this->courseshortnames = array($SITE->id => $SITE->shortname);
$userids = array();
$courseids = array();
// For each event cache full username and course.
// Get list of userids and courseids which will be shown in log report.
foreach ($this->rawdata as $event) {
$logextra = $event->get_logextra();
if (!empty($event->userid) && empty($userids[$event->userid])) {
$userids[$event->userid] = $event->userid;
}
if (!empty($logextra['realuserid']) && empty($userids[$logextra['realuserid']])) {
$userids[$logextra['realuserid']] = $logextra['realuserid'];
}
if (!empty($event->relateduserid) && empty($userids[$event->relateduserid])) {
$userids[$event->relateduserid] = $event->relateduserid;
}

if (!empty($event->courseid) && ($event->courseid != $SITE->id) && !in_array($event->courseid, $courseids)) {
$courseids[] = $event->courseid;
}
}

// Closing it just in case, we can not rewind moodle recordsets anyway.
if ($this->rawdata instanceof \core\dml\recordset_walk ||
$this->rawdata instanceof moodle_recordset) {
$this->rawdata->close();
}

// Get user fullname and put that in return list.
if (!empty($userids)) {
list($usql, $uparams) = $DB->get_in_or_equal($userids);
$users = $DB->get_records_sql("SELECT id," . get_all_user_name_fields(true) . " FROM {user} WHERE id " . $usql,
$uparams);
foreach ($users as $userid => $user) {
$this->userfullnames[$userid] = fullname($user);
unset($userids[$userid]);
}

// We fill the array with false values for the users that don't exist anymore
// in the database so we don't need to query the db again later.
foreach ($userids as $userid) {
$this->userfullnames[$userid] = false;
}
}

// Get course shortname and put that in return list.
if (!empty($courseids)) { // If all logs don't belog to site level then get course info.
list($coursesql, $courseparams) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED);
$ccselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
$ccjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
$courseparams['contextlevel'] = CONTEXT_COURSE;
$sql = "SELECT c.id,c.shortname $ccselect FROM {course} c
$ccjoin
WHERE c.id " . $coursesql;

$courses = $DB->get_records_sql($sql, $courseparams);
foreach ($courses as $courseid => $course) {
$url = new moodle_url("/course/view.php", array('id' => $courseid));
context_helper::preload_from_record($course);
$context = context_course::instance($courseid, IGNORE_MISSING);
// Method format_string() takes care of missing contexts.
$this->courseshortnames[$courseid] = html_writer::link($url, format_string($course->shortname, true,
array('context' => $context)));
}
}
throw new coding_exception('update_users_and_courses_used() can not be used any more, please use update_users_used() instead.');
}

/**
Expand Down

0 comments on commit 806905b

Please sign in to comment.