mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-16 21:41:31 +02:00
Merge pull request #299 from catalyst/MOODLE_39_STABLE_ISSUE209
Issue#209 Remove as much db calls as possible in outage plugin
This commit is contained in:
@@ -211,21 +211,20 @@ class outagedb {
|
||||
throw new coding_exception('$time must be null or a positive int.', $time);
|
||||
}
|
||||
|
||||
$select = ':datetime2 <= stoptime AND (finished IS NULL OR :datetime3 <= finished)'; // End condition.
|
||||
$select = "(warntime <= :datetime1 AND (${select}))"; // Full select part.
|
||||
$data = $DB->get_records_select(
|
||||
'auth_outage',
|
||||
$select,
|
||||
['datetime1' => $time, 'datetime2' => $time, 'datetime3' => $time],
|
||||
'starttime ASC, stoptime DESC, title ASC',
|
||||
'*',
|
||||
0,
|
||||
1
|
||||
);
|
||||
// Get cached outage, or null.
|
||||
$outageinfo = get_config('moodle', 'auth_outage_active_outage');
|
||||
|
||||
// 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 outage(array_shift($data));
|
||||
if (!$outageinfo) {
|
||||
return null;
|
||||
} else {
|
||||
$outagecache = new outage(json_decode($outageinfo));
|
||||
}
|
||||
|
||||
if ($outagecache && $outagecache->warntime <= $time && $outagecache->stoptime >= $time
|
||||
&& (!$outagecache->finished || $outagecache->finished >= $time)) {
|
||||
return $outagecache;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -297,4 +297,12 @@ class outage {
|
||||
// Adjust bool fields.
|
||||
$this->autostart = ($this->autostart === null) ? null : (bool)$this->autostart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return json encoded outage.
|
||||
* @return string Json string.
|
||||
*/
|
||||
public function __toString() {
|
||||
return json_encode(get_object_vars($this));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,6 +210,10 @@ class outagelib {
|
||||
} else {
|
||||
$ongoingoutage = true;
|
||||
}
|
||||
|
||||
// Set json formatted outage string to cache.
|
||||
set_config('auth_outage_active_outage', (string)$outage);
|
||||
|
||||
maintenance_static_page::create_from_outage($outage)->generate();
|
||||
self::update_climaintenance_code($outage);
|
||||
if (!$ongoingoutage || $reenablemaint || is_null($outage)) {
|
||||
|
||||
Reference in New Issue
Block a user