mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-17 05:48:43 +02:00
Issue #9 - Checking if outage is ongoing or just a warning. Improved hooks, tests and HTML output.
This commit is contained in:
@@ -96,4 +96,18 @@ class outage {
|
||||
|
||||
throw new \InvalidArgumentException('$data must be null (default), an array or an object.');
|
||||
}
|
||||
|
||||
public function is_ongoing($time = null) {
|
||||
if ($time === null) {
|
||||
$time = time();
|
||||
}
|
||||
if (!is_int($time) || ($time <= 0)) {
|
||||
throw new \InvalidArgumentException('$time must be an positive int.');
|
||||
}
|
||||
if (is_null($this->starttime) || is_null($this->stoptime)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (($this->starttime <= $time) && ($time < $this->stoptime));
|
||||
}
|
||||
}
|
||||
@@ -158,15 +158,14 @@ final class outagedb {
|
||||
// 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.
|
||||
$now = time();
|
||||
$data = $DB->get_record_sql('
|
||||
SELECT *
|
||||
FROM {auth_outage}
|
||||
WHERE (starttime - warningduration <= :now1 AND stoptime >= :now2)
|
||||
WHERE (starttime - warningduration <= :datetime1 AND stoptime >= :datetime2)
|
||||
ORDER BY starttime ASC, stoptime DESC, title ASC
|
||||
LIMIT 1
|
||||
',
|
||||
['now1' => $now, 'now2' => $now]
|
||||
['datetime1' => $time, 'datetime2' => $time]
|
||||
);
|
||||
|
||||
return ($data === false) ? null : new \auth_outage\models\outage($data);
|
||||
|
||||
@@ -55,8 +55,9 @@ class outagelib {
|
||||
/**
|
||||
* Will check for ongoing or warning outages and will attach the message bar as required.
|
||||
*/
|
||||
public static function initialize() {
|
||||
public static function inject() {
|
||||
global $CFG;
|
||||
global $PAGE;
|
||||
|
||||
// Many hooks can call it, execute only once.
|
||||
if (self::$initialized) {
|
||||
@@ -68,6 +69,7 @@ class outagelib {
|
||||
return;
|
||||
}
|
||||
|
||||
$PAGE->add_body_class('auth_outage_active');
|
||||
$CFG->additionalhtmltopofbody .= self::get_renderer()->renderbar($active);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user