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)) {
|
||||
|
||||
@@ -244,6 +244,15 @@ class auth_outage_outagedb_test extends auth_outage_base_testcase {
|
||||
$activeid = self::saveoutage(false, $now, -2, 1, 2, 'An outage in warning period.');
|
||||
self::assertSame($activeid, outagedb::get_active($now)->id, 'Wrong active outage picked.');
|
||||
|
||||
$activeid = self::saveoutage(false, $now, -2, 0, 2, 'An outage starts now.');
|
||||
self::assertSame($activeid, outagedb::get_active($now)->id, 'Wrong active outage picked.');
|
||||
|
||||
self::saveoutage(false, $now, -2, 0, -1, 'Invalid outage.');
|
||||
self::assertSame($activeid, outagedb::get_active($now)->id, 'Wrong active outage picked.');
|
||||
|
||||
self::saveoutage(false, $now, -2, 0, 0, 'Invalid outage.');
|
||||
self::assertSame($activeid, outagedb::get_active($now)->id, 'Wrong active outage picked.');
|
||||
|
||||
self::saveoutage(false, $now, -1, 2, 3,
|
||||
'Another outage in warning period, but ignored as it starts after the previous one.');
|
||||
self::assertSame($activeid, outagedb::get_active($now)->id, 'Wrong active outage picked.');
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->component = "auth_outage";
|
||||
$plugin->version = 2022042800; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->release = 2022042800; // Human-readable release information.
|
||||
$plugin->version = 2022051200; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->release = 2022051200; // Human-readable release information.
|
||||
$plugin->requires = 2017111309; // 2017111309 = T13, but this really requires 3.9 and higher.
|
||||
$plugin->maturity = MATURITY_STABLE; // Suitable for PRODUCTION environments!
|
||||
$plugin->supported = [39, 311]; // A range of branch numbers of supported moodle versions.
|
||||
|
||||
Reference in New Issue
Block a user