mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-16 21:41:31 +02:00
Fixed insepections, refactored to reduce complexity (phpmd warning).
This commit is contained in:
118
classes/calendar/calendar.php
Normal file
118
classes/calendar/calendar.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace auth_outage\calendar;
|
||||
|
||||
use auth_outage\local\outage;
|
||||
use calendar_event;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot.'/calendar/lib.php');
|
||||
|
||||
/**
|
||||
* Manages outages in the calendar.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class calendar {
|
||||
/**
|
||||
* Private constructor, use static methods instead.
|
||||
*/
|
||||
private function __construct() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an event on the calendar for this outage.
|
||||
* @param outage $outage Outage to be added to the calendar.
|
||||
*/
|
||||
public static function calendar_create(outage $outage) {
|
||||
calendar_event::create(self::calendar_data($outage));
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an event on the calendar based on this outage.
|
||||
* @param outage $outage Outage to be updated in the calendar.
|
||||
*/
|
||||
public static function calendar_update(outage $outage) {
|
||||
$event = self::calendar_load($outage->id);
|
||||
|
||||
if (is_null($event)) {
|
||||
debugging('Cannot update calendar entry for outage #'.$outage->id.', event not found. Creating it...');
|
||||
self::calendar_create($outage);
|
||||
} else {
|
||||
$event->update(self::calendar_data($outage));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an event from the calendar related to this outage.
|
||||
* @param int $outageid Id of outage to be deleted from the calendar.
|
||||
*/
|
||||
public static function calendar_delete($outageid) {
|
||||
$event = self::calendar_load($outageid);
|
||||
|
||||
// If not found (was not created before) ignore it.
|
||||
if (is_null($event)) {
|
||||
debugging('Cannot delete calendar entry for outage #'.$outageid.', event not found. Ignoring it...');
|
||||
} else {
|
||||
$event->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an array with the calendar event data based on an outage object.
|
||||
* @param outage $outage Outage to use as reference for the calendar event.
|
||||
* @return mixed[] Calendar event data.
|
||||
*/
|
||||
private static function calendar_data(outage $outage) {
|
||||
return [
|
||||
'name' => $outage->get_title(),
|
||||
'description' => $outage->get_description(),
|
||||
'courseid' => 1,
|
||||
'groupid' => 0,
|
||||
'userid' => 0,
|
||||
'modulename' => '',
|
||||
'instance' => $outage->id,
|
||||
'eventtype' => 'auth_outage',
|
||||
'timestart' => $outage->starttime,
|
||||
'visible' => true,
|
||||
'timeduration' => $outage->get_duration_planned(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the calendar event for an specific outage.
|
||||
* @param int $outageid The outage id to find in the calendar.
|
||||
* @return calendar_event|null The calendar event or null if not found.
|
||||
*/
|
||||
private static function calendar_load($outageid) {
|
||||
global $DB;
|
||||
|
||||
$event = $DB->get_record_select(
|
||||
'event',
|
||||
"(eventtype = 'auth_outage' AND instance = :outageid)",
|
||||
['outageid' => $outageid],
|
||||
'id',
|
||||
IGNORE_MISSING
|
||||
);
|
||||
|
||||
return ($event === false) ? null : calendar_event::load($event->id);
|
||||
}
|
||||
}
|
||||
@@ -14,12 +14,14 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace auth_outage\local;
|
||||
namespace auth_outage\dml;
|
||||
|
||||
use auth_outage\calendar\calendar;
|
||||
use auth_outage\event\outage_created;
|
||||
use auth_outage\event\outage_deleted;
|
||||
use auth_outage\event\outage_updated;
|
||||
use calendar_event;
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\local\outagelib;
|
||||
use coding_exception;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
@@ -104,7 +106,7 @@ class outagedb {
|
||||
['objectid' => $outage->id, 'other' => (array)$outage]
|
||||
)->trigger();
|
||||
// Create calendar entry.
|
||||
self::calendar_create($outage);
|
||||
calendar::calendar_create($outage);
|
||||
} else {
|
||||
// Remove the createdby field so it does not get updated.
|
||||
unset($outage->createdby);
|
||||
@@ -114,7 +116,7 @@ class outagedb {
|
||||
['objectid' => $outage->id, 'other' => (array)$outage]
|
||||
)->trigger();
|
||||
// Update calendar entry.
|
||||
self::calendar_update($outage);
|
||||
calendar::calendar_update($outage);
|
||||
}
|
||||
|
||||
// Trigger outages modified events.
|
||||
@@ -145,7 +147,7 @@ class outagedb {
|
||||
|
||||
// Delete it and remove from calendar.
|
||||
$DB->delete_records('auth_outage', ['id' => $id]);
|
||||
self::calendar_delete($id);
|
||||
calendar::calendar_delete($id);
|
||||
|
||||
// Trigger events.
|
||||
outagelib::outages_modified();
|
||||
@@ -341,82 +343,4 @@ class outagedb {
|
||||
// Allowing multiple records still raises an internal error.
|
||||
return (count($data) == 0) ? null : new outage(array_shift($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an event on the calendar for this outage.
|
||||
* @param outage $outage Outage to be added to the calendar.
|
||||
*/
|
||||
private static function calendar_create(outage $outage) {
|
||||
calendar_event::create(self::calendar_data($outage));
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an event on the calendar based on this outage.
|
||||
* @param outage $outage Outage to be updated in the calendar.
|
||||
*/
|
||||
private static function calendar_update(outage $outage) {
|
||||
$event = self::calendar_load($outage->id);
|
||||
|
||||
if (is_null($event)) {
|
||||
debugging('Cannot update calendar entry for outage #'.$outage->id.', event not found. Creating it...');
|
||||
self::calendar_create($outage);
|
||||
} else {
|
||||
$event->update(self::calendar_data($outage));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an event from the calendar related to this outage.
|
||||
* @param int $outageid Id of outage to be deleted from the calendar.
|
||||
*/
|
||||
private static function calendar_delete($outageid) {
|
||||
$event = self::calendar_load($outageid);
|
||||
|
||||
// If not found (was not created before) ignore it.
|
||||
if (is_null($event)) {
|
||||
debugging('Cannot delete calendar entry for outage #'.$outageid.', event not found. Ignoring it...');
|
||||
} else {
|
||||
$event->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an array with the calendar event data based on an outage object.
|
||||
* @param outage $outage Outage to use as reference for the calendar event.
|
||||
* @return mixed[] Calendar event data.
|
||||
*/
|
||||
private static function calendar_data(outage $outage) {
|
||||
return [
|
||||
'name' => $outage->get_title(),
|
||||
'description' => $outage->get_description(),
|
||||
'courseid' => 1,
|
||||
'groupid' => 0,
|
||||
'userid' => 0,
|
||||
'modulename' => '',
|
||||
'instance' => $outage->id,
|
||||
'eventtype' => 'auth_outage',
|
||||
'timestart' => $outage->starttime,
|
||||
'visible' => true,
|
||||
'timeduration' => $outage->get_duration_planned(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the calendar event for an specific outage.
|
||||
* @param int $outageid The outage id to find in the calendar.
|
||||
* @return calendar_event|null The calendar event or null if not found.
|
||||
*/
|
||||
private static function calendar_load($outageid) {
|
||||
global $DB;
|
||||
|
||||
$event = $DB->get_record_select(
|
||||
'event',
|
||||
"(eventtype = 'auth_outage' AND instance = :outageid)",
|
||||
['outageid' => $outageid],
|
||||
'id',
|
||||
IGNORE_MISSING
|
||||
);
|
||||
|
||||
return ($event === false) ? null : calendar_event::load($event->id);
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,41 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class cli_exception extends Exception {
|
||||
/**
|
||||
* Undefined error.
|
||||
*/
|
||||
const ERROR_UNDEFINED = 1;
|
||||
|
||||
/**
|
||||
* Unknow parameter.
|
||||
*/
|
||||
const ERROR_PARAMETER_UNKNOWN = 2;
|
||||
|
||||
/**
|
||||
* Invalid parameter usage.
|
||||
*/
|
||||
const ERROR_PARAMETER_INVALID = 3;
|
||||
|
||||
/**
|
||||
* Missing required parameter.
|
||||
*/
|
||||
const ERROR_PARAMETER_MISSING = 4;
|
||||
|
||||
/**
|
||||
* The informed outage cannot be used for that purpose.
|
||||
*/
|
||||
const ERROR_OUTAGE_INVALID = 5;
|
||||
|
||||
/**
|
||||
* The informed outage was not found.
|
||||
*/
|
||||
const ERROR_OUTAGE_NOT_FOUND = 6;
|
||||
|
||||
/**
|
||||
* The outage has changed before the completion of the command.
|
||||
*/
|
||||
const ERROR_OUTAGE_CHANGED = 7;
|
||||
|
||||
/**
|
||||
* cliexception constructor.
|
||||
* @param string $message An explanation of the exception.
|
||||
|
||||
@@ -56,14 +56,15 @@ abstract class clibase {
|
||||
list($options, $unrecognized) = cli_get_params($this->generate_options(), $this->generate_shortcuts());
|
||||
if ($unrecognized) {
|
||||
$unrecognized = implode("\n ", $unrecognized);
|
||||
throw new cli_exception(get_string('cliunknowoption', 'admin', $unrecognized));
|
||||
throw new cli_exception(get_string('cliunknowoption', 'admin', $unrecognized),
|
||||
cli_exception::ERROR_PARAMETER_UNKNOWN);
|
||||
}
|
||||
} else {
|
||||
// If not using Moodle CLI API to read parameters, ensure all keys exist.
|
||||
$default = $this->generate_options();
|
||||
foreach ($options as $k => $v) {
|
||||
if (!array_key_exists($k, $default)) {
|
||||
throw new cli_exception(get_string('cliunknowoption', 'admin', $k));
|
||||
throw new cli_exception(get_string('cliunknowoption', 'admin', $k), cli_exception::ERROR_PARAMETER_UNKNOWN);
|
||||
}
|
||||
$default[$k] = $v;
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
namespace auth_outage\local\cli;
|
||||
|
||||
use auth_outage\dml\outagedb;
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\local\outagedb;
|
||||
use coding_exception;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
@@ -112,7 +112,8 @@ class create extends clibase {
|
||||
|
||||
// If not help mode, 'start' is required and cannot use default.
|
||||
if (is_null($this->options['start'])) {
|
||||
throw new cli_exception(get_string('clierrormissingparamaters', 'auth_outage'));
|
||||
throw new cli_exception(get_string('clierrormissingparamaters', 'auth_outage'),
|
||||
cli_exception::ERROR_PARAMETER_MISSING);
|
||||
}
|
||||
|
||||
// If cloning, set defaults to outage being cloned.
|
||||
@@ -184,7 +185,8 @@ class create extends clibase {
|
||||
private function clone_defaults() {
|
||||
$id = $this->options['clone'];
|
||||
if (!is_number($id) || ($id <= 0)) {
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => 'clone']));
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => 'clone']),
|
||||
cli_exception::ERROR_PARAMETER_INVALID);
|
||||
}
|
||||
|
||||
$outage = outagedb::get_by_id((int)$id);
|
||||
@@ -204,51 +206,84 @@ class create extends clibase {
|
||||
* @throws cli_exception
|
||||
*/
|
||||
private function merge_options_check_parameters(array $options) {
|
||||
// Check parameters that must be a non-negative int while converting their type to int.
|
||||
foreach (['start', 'warn', 'duration'] as $param) {
|
||||
if (!is_number($options[$param])) {
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => $param]));
|
||||
}
|
||||
$options[$param] = (int)$options[$param];
|
||||
if ($options[$param] < 0) {
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => $param]));
|
||||
}
|
||||
$options[$param] = $this->merge_options_check_parameters_int_nonnegative($options[$param], $param);
|
||||
}
|
||||
|
||||
// Check parameters that must be a non empty string.
|
||||
foreach (['title', 'description'] as $param) {
|
||||
if (!is_string($options[$param])) {
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => $param]));
|
||||
}
|
||||
$options[$param] = trim($options[$param]);
|
||||
if (strlen($options[$param]) == 0) {
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => $param]));
|
||||
}
|
||||
$options[$param] = $this->merge_options_check_parameters_string_nonempty($options[$param], $param);
|
||||
}
|
||||
|
||||
// Check parameters that must be a specified bool.
|
||||
foreach (['autostart'] as $param) {
|
||||
if (is_string($options[$param])) {
|
||||
switch (strtoupper($options[$param])) {
|
||||
case '0':
|
||||
case 'FALSE':
|
||||
case 'NO':
|
||||
case 'N':
|
||||
$options[$param] = false;
|
||||
break;
|
||||
case '1':
|
||||
case 'TRUE':
|
||||
case 'YES':
|
||||
case 'Y':
|
||||
$options[$param] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!is_bool($options[$param])) {
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => $param]));
|
||||
}
|
||||
$options[$param] = $this->merge_options_check_parameters_bool($options[$param], $param);
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the given option is or can be converted to a non-negative int.
|
||||
* @param mixed $option The parameter to check.
|
||||
* @param string $param Name of that parameter.
|
||||
* @return int The converted parameter.
|
||||
* @throws cli_exception
|
||||
*/
|
||||
private function merge_options_check_parameters_int_nonnegative($option, $param) {
|
||||
if (!is_number($option)) {
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => $param]),
|
||||
cli_exception::ERROR_PARAMETER_INVALID);
|
||||
}
|
||||
$option = (int)$option;
|
||||
if ($option < 0) {
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => $param]),
|
||||
cli_exception::ERROR_PARAMETER_INVALID);
|
||||
}
|
||||
return $option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the given option is or can be converted to a non-empty string.
|
||||
* @param mixed $option The parameter to check.
|
||||
* @param string $param Name of that parameter.
|
||||
* @return string The converted parameter.
|
||||
* @throws cli_exception
|
||||
*/
|
||||
|
||||
private function merge_options_check_parameters_string_nonempty($option, $param) {
|
||||
if (!is_string($option)) {
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => $param]),
|
||||
cli_exception::ERROR_PARAMETER_INVALID);
|
||||
}
|
||||
$option = trim($option);
|
||||
if (strlen($option) == 0) {
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => $param]),
|
||||
cli_exception::ERROR_PARAMETER_INVALID);
|
||||
}
|
||||
return $option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the given option is or can be converted to a bool.
|
||||
* @param mixed $option The parameter to check.
|
||||
* @param string $param Name of that parameter.
|
||||
* @return bool The converted parameter.
|
||||
* @throws cli_exception
|
||||
*/
|
||||
private function merge_options_check_parameters_bool($option, $param) {
|
||||
if (is_bool($option)) {
|
||||
return $option;
|
||||
}
|
||||
|
||||
if (is_string($option)) {
|
||||
$option = strtoupper($option);
|
||||
if (in_array($option, ['0', 'FALSE', 'NO', 'N'])) {
|
||||
return false;
|
||||
}
|
||||
if (in_array($option, ['1', 'TRUE', 'YES', 'Y'])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => $param]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
namespace auth_outage\local\cli;
|
||||
|
||||
use auth_outage\dml\outagedb;
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\local\outagedb;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -70,12 +70,13 @@ class finish extends clibase {
|
||||
$byid = !is_null($this->options['outageid']);
|
||||
$byactive = $this->options['active'];
|
||||
if ($byid == $byactive) {
|
||||
throw new cli_exception(get_string('cliwaitforiterroridxoractive', 'auth_outage'));
|
||||
throw new cli_exception(get_string('cliwaitforiterroridxoractive', 'auth_outage'),
|
||||
cli_exception::ERROR_PARAMETER_MISSING);
|
||||
}
|
||||
|
||||
$outage = $this->get_outage();
|
||||
if (!$outage->is_ongoing()) {
|
||||
throw new cli_exception(get_string('clifinishnotongoing', 'auth_outage'));
|
||||
throw new cli_exception(get_string('clifinishnotongoing', 'auth_outage'), cli_exception::ERROR_OUTAGE_INVALID);
|
||||
}
|
||||
|
||||
outagedb::finish($outage->id, $this->time);
|
||||
@@ -92,13 +93,14 @@ class finish extends clibase {
|
||||
} else {
|
||||
$id = $this->options['outageid'];
|
||||
if (!is_number($id) || ($id <= 0)) {
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => 'outageid']));
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => 'outageid']),
|
||||
cli_exception::ERROR_PARAMETER_INVALID);
|
||||
}
|
||||
$outage = outagedb::get_by_id((int)$id);
|
||||
}
|
||||
|
||||
if (is_null($outage)) {
|
||||
throw new cli_exception(get_string('clierroroutagenotfound', 'auth_outage'));
|
||||
throw new cli_exception(get_string('clierroroutagenotfound', 'auth_outage'), cli_exception::ERROR_OUTAGE_NOT_FOUND);
|
||||
}
|
||||
|
||||
return $outage;
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
namespace auth_outage\local\cli;
|
||||
|
||||
use auth_outage\dml\outagedb;
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\local\outagedb;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -92,7 +92,8 @@ class waitforit extends clibase {
|
||||
$byid = !is_null($this->options['outageid']);
|
||||
$byactive = $this->options['active'];
|
||||
if ($byid == $byactive) {
|
||||
throw new cli_exception(get_string('cliwaitforiterroridxoractive', 'auth_outage'));
|
||||
throw new cli_exception(get_string('cliwaitforiterroridxoractive', 'auth_outage'),
|
||||
cli_exception::ERROR_PARAMETER_INVALID);
|
||||
}
|
||||
|
||||
$this->verbose('Verbose mode activated.');
|
||||
@@ -137,14 +138,15 @@ class waitforit extends clibase {
|
||||
} else {
|
||||
$id = $this->options['outageid'];
|
||||
if (!is_number($id) || ($id <= 0)) {
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => 'outageid']));
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => 'outageid']),
|
||||
cli_exception::ERROR_PARAMETER_INVALID);
|
||||
}
|
||||
$this->verbose('Querying database for outage #'.$id.'...');
|
||||
$outage = outagedb::get_by_id((int)$id);
|
||||
}
|
||||
|
||||
if (is_null($outage)) {
|
||||
throw new cli_exception(get_string('clierroroutagenotfound', 'auth_outage'));
|
||||
throw new cli_exception(get_string('clierroroutagenotfound', 'auth_outage'), cli_exception::ERROR_OUTAGE_NOT_FOUND);
|
||||
}
|
||||
|
||||
$this->verbose('Found outage #'.$outage->id.': '.$outage->get_title());
|
||||
@@ -161,11 +163,11 @@ class waitforit extends clibase {
|
||||
$this->verbose('Checking outage status...');
|
||||
// Outage should not change while waiting to start.
|
||||
if (outagedb::get_by_id($outage->id) != $outage) {
|
||||
throw new cli_exception(get_string('clierroroutagechanged', 'auth_outage'));
|
||||
throw new cli_exception(get_string('clierroroutagechanged', 'auth_outage'), cli_exception::ERROR_OUTAGE_CHANGED);
|
||||
}
|
||||
// Outage cannot have already ended.
|
||||
if ($outage->has_ended($this->time)) {
|
||||
throw new cli_exception(get_string('clierroroutageended', 'auth_outage'));
|
||||
throw new cli_exception(get_string('clierroroutageended', 'auth_outage'), cli_exception::ERROR_OUTAGE_INVALID);
|
||||
}
|
||||
// If outage has started, do not wait.
|
||||
if ($outage->is_ongoing($this->time)) {
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
namespace auth_outage\local\controllers;
|
||||
|
||||
use auth_outage\dml\outagedb;
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\local\outagedb;
|
||||
use auth_outage\local\outagelib;
|
||||
use coding_exception;
|
||||
use context_system;
|
||||
|
||||
@@ -132,15 +132,7 @@ class outage {
|
||||
$this->$k = $v;
|
||||
}
|
||||
}
|
||||
|
||||
// Adjust int fields.
|
||||
$fs = ['createdby', 'id', 'lastmodified', 'modifiedby', 'starttime', 'stoptime', 'warntime', 'finished'];
|
||||
foreach ($fs as $f) {
|
||||
$this->$f = ($this->$f === null) ? null : (int)$this->$f;
|
||||
}
|
||||
|
||||
// Adjust bool fields.
|
||||
$this->autostart = ($this->autostart === null) ? null : (bool)$this->autostart;
|
||||
$this->adjust_field_types();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -274,4 +266,15 @@ class outage {
|
||||
$str
|
||||
);
|
||||
}
|
||||
|
||||
private function adjust_field_types() {
|
||||
// Adjust int fields.
|
||||
$fs = ['createdby', 'id', 'lastmodified', 'modifiedby', 'starttime', 'stoptime', 'warntime', 'finished'];
|
||||
foreach ($fs as $f) {
|
||||
$this->$f = ($this->$f === null) ? null : (int)$this->$f;
|
||||
}
|
||||
|
||||
// Adjust bool fields.
|
||||
$this->autostart = ($this->autostart === null) ? null : (bool)$this->autostart;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
namespace auth_outage\local;
|
||||
|
||||
use auth_outage\dml\outagedb;
|
||||
use auth_outage\local\controllers\infopage;
|
||||
use auth_outage_renderer;
|
||||
use Exception;
|
||||
|
||||
@@ -29,10 +29,17 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class update_static_page extends scheduled_task {
|
||||
/**
|
||||
* Gets the name of this event.
|
||||
* @return string Name of this event.
|
||||
*/
|
||||
public function get_name() {
|
||||
return get_string('taskupdatestaticpage', 'auth_outage');
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the event.
|
||||
*/
|
||||
public function execute() {
|
||||
infopage::update_static_page();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user