diff --git a/classes/outagedb.php b/classes/outagedb.php index f7ef64e..a731367 100644 --- a/classes/outagedb.php +++ b/classes/outagedb.php @@ -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)); } } diff --git a/res/outage.css b/res/outage.css index d703444..2572bf7 100644 --- a/res/outage.css +++ b/res/outage.css @@ -1,4 +1,5 @@ .auth_outage_warningbar { + box-sizing: content-box; position: fixed; top: 0px; left: 0px;