mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-17 05:48:43 +02:00
Issue #9 - Fixed outagedb::getactive() to make better usage of Moodle DB API, removing hardcoded LIMIT from SQL Query.
This commit is contained in:
@@ -154,20 +154,21 @@ final class outagedb {
|
||||
throw new \InvalidArgumentException('$time must be null or an int.');
|
||||
}
|
||||
|
||||
// TODO Is there a way to use Moodle API instead of writing SQL (conditions not equals)?
|
||||
// TODO Query not fully using indexes (starttime + 90)
|
||||
// Gets any active outage (already started or during warning period).
|
||||
// Gets only one record if available, the one that starts(ed) first and that stops last.
|
||||
$data = $DB->get_record_sql('
|
||||
SELECT *
|
||||
FROM {auth_outage}
|
||||
WHERE (starttime - warningduration <= :datetime1 AND stoptime >= :datetime2)
|
||||
ORDER BY starttime ASC, stoptime DESC, title ASC
|
||||
LIMIT 1
|
||||
',
|
||||
['datetime1' => $time, 'datetime2' => $time]
|
||||
$data = $DB->get_records_select(
|
||||
'auth_outage',
|
||||
'(starttime - warningduration <= :datetime1 AND stoptime >= :datetime2)',
|
||||
['datetime1' => $time, 'datetime2' => $time],
|
||||
'starttime ASC, stoptime DESC, title ASC',
|
||||
'*',
|
||||
0,
|
||||
1
|
||||
);
|
||||
|
||||
return ($data === false) ? null : new \auth_outage\models\outage($data);
|
||||
// Not using $DB->get_record_select instead because there is no 'limit' parameter.
|
||||
// Allowing multiple records still raises an internal error.
|
||||
return (count($data) == 0) ? null : new \auth_outage\models\outage(array_shift($data));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user