mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-16 21:41:31 +02:00
Issue #42 - Refactoring code according to Moodle Coding Style.
This commit is contained in:
4
auth.php
4
auth.php
@@ -26,7 +26,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->libdir . '/authlib.php');
|
||||
require_once($CFG->libdir.'/authlib.php');
|
||||
|
||||
/**
|
||||
* Class auth_plugin_outage
|
||||
@@ -53,6 +53,6 @@ class auth_plugin_outage extends auth_plugin_base {
|
||||
* Login page hook.
|
||||
*/
|
||||
public function loginpage_hook() {
|
||||
\auth_outage\outagelib::inject();
|
||||
\auth_outage\local\outagelib::inject();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,15 +19,35 @@ namespace auth_outage\event;
|
||||
use core\event\base;
|
||||
use moodle_url;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* The auth_outage outage created class.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class outage_created extends base {
|
||||
/**
|
||||
* Returns non-localised event description with id's for admin use only.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user with the id '{$this->userid}' created a new outage title '{$this->other['title']}' ".
|
||||
" with id '{$this->other['id']}'.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns relevant URL, override in subclasses.
|
||||
* @return moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new moodle_url('/auth/outage/list.php#auth_outage_id_'.$this->other['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*/
|
||||
@@ -37,22 +57,4 @@ class outage_created extends base {
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
$this->context = \context_system::instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns non-localised event description with id's for admin use only.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user with the id '{$this->userid}' created a new outage title '{$this->other['title']}' "
|
||||
. " with id '{$this->other['id']}'.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns relevant URL, override in subclasses.
|
||||
* @return moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new moodle_url('/auth/outage/list.php#auth_outage_id_' . $this->other['id']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,16 +17,37 @@
|
||||
namespace auth_outage\event;
|
||||
|
||||
use core\event\base;
|
||||
use moodle_url;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* The auth_outage outage deleted class.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class outage_deleted extends base {
|
||||
/**
|
||||
* Returns non-localised event description with id's for admin use only.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user with the id '{$this->userid}' deleted the outage titled '{$this->other['title']}' ".
|
||||
"with id '{$this->other['id']}'.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns relevant URL, override in subclasses.
|
||||
* @return moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new moodle_url('/auth/outage/list.php#auth_outage_id_'.$this->other['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*/
|
||||
@@ -36,22 +57,4 @@ class outage_deleted extends base {
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
$this->context = \context_system::instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns non-localised event description with id's for admin use only.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user with the id '{$this->userid}' deleted the outage titled '{$this->other['title']}' "
|
||||
. "with id '{$this->other['id']}'.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns relevant URL, override in subclasses.
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/auth/outage/list.php#auth_outage_id_' . $this->other['id']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,16 +17,37 @@
|
||||
namespace auth_outage\event;
|
||||
|
||||
use core\event\base;
|
||||
use moodle_url;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* The auth_outage outage updated class.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class outage_updated extends base {
|
||||
/**
|
||||
* Returns non-localised event description with id's for admin use only.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user with the id '{$this->userid}' updated the outage title '{$this->other['title']}' ".
|
||||
"with id '{$this->other['id']}'.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns relevant URL, override in subclasses.
|
||||
* @return moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new moodle_url('/auth/outage/list.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*/
|
||||
@@ -36,22 +57,4 @@ class outage_updated extends base {
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
$this->context = \context_system::instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns non-localised event description with id's for admin use only.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user with the id '{$this->userid}' updated the outage title '{$this->other['title']}' "
|
||||
. "with id '{$this->other['id']}'.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns relevant URL, override in subclasses.
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/auth/outage/list.php');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,20 +14,20 @@
|
||||
// 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\forms\outage;
|
||||
namespace auth_outage\form\outage;
|
||||
|
||||
if (!defined('MOODLE_INTERNAL')) {
|
||||
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
|
||||
}
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->libdir . '/formslib.php');
|
||||
require_once($CFG->libdir.'/formslib.php');
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Outage delete confirmation form.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class delete extends \moodleform {
|
||||
@@ -14,22 +14,21 @@
|
||||
// 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\forms\outage;
|
||||
namespace auth_outage\form\outage;
|
||||
|
||||
use auth_outage\models\outage;
|
||||
use auth_outage\local\outage;
|
||||
use coding_exception;
|
||||
|
||||
if (!defined('MOODLE_INTERNAL')) {
|
||||
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
|
||||
}
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->libdir . '/formslib.php');
|
||||
require_once($CFG->libdir.'/formslib.php');
|
||||
|
||||
/**
|
||||
* Outage form.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class edit extends \moodleform {
|
||||
@@ -58,7 +57,7 @@ class edit extends \moodleform {
|
||||
'text',
|
||||
'title',
|
||||
get_string('title', 'auth_outage'),
|
||||
'maxlength="' . self::TITLE_MAX_CHARS . '" size="60"'
|
||||
'maxlength="'.self::TITLE_MAX_CHARS.'" size="60"'
|
||||
);
|
||||
$mform->setType('title', PARAM_TEXT);
|
||||
$mform->addHelpButton('title', 'title', 'auth_outage');
|
||||
@@ -74,9 +73,9 @@ class edit extends \moodleform {
|
||||
/**
|
||||
* Validate the parts of the request form for this module
|
||||
*
|
||||
* @param array $data An array of form data
|
||||
* @param array $files An array of form files
|
||||
* @return array of error messages
|
||||
* @param mixed[] $data An array of form data
|
||||
* @param string[] $files An array of form files
|
||||
* @return string[] of error messages
|
||||
*/
|
||||
public function validation($data, $files) {
|
||||
$errors = parent::validation($data, $files);
|
||||
@@ -110,7 +109,7 @@ class edit extends \moodleform {
|
||||
return null;
|
||||
}
|
||||
if ($data->description['format'] != '1') {
|
||||
debugging('Not implemented for format ' . $data->description['format'], DEBUG_DEVELOPER);
|
||||
debugging('Not implemented for format '.$data->description['format'], DEBUG_DEVELOPER);
|
||||
return null;
|
||||
}
|
||||
// Return an outage.
|
||||
@@ -120,16 +119,17 @@ class edit extends \moodleform {
|
||||
'stoptime' => $data->starttime + $data->outageduration,
|
||||
'warntime' => $data->starttime - $data->warningduration,
|
||||
'title' => $data->title,
|
||||
'description' => $data->description['text']
|
||||
'description' => $data->description['text'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load in existing outage as form defaults.
|
||||
*
|
||||
* @param outage $outage outage object with default values
|
||||
* @throws coding_exception
|
||||
*/
|
||||
public function set_data($outage) {
|
||||
// Cannot change method signature, check type.
|
||||
if ($outage instanceof outage) {
|
||||
$this->_form->setDefaults([
|
||||
'id' => $outage->id,
|
||||
@@ -137,10 +137,10 @@ class edit extends \moodleform {
|
||||
'outageduration' => $outage->get_duration_planned(),
|
||||
'warningduration' => $outage->get_warning_duration(),
|
||||
'title' => $outage->title,
|
||||
'description' => ['text' => $outage->description, 'format' => '1']
|
||||
'description' => ['text' => $outage->description, 'format' => '1'],
|
||||
]);
|
||||
} else {
|
||||
throw new \InvalidArgumentException('$outage must be an outage object.');
|
||||
throw new coding_exception('$outage must be an outage object.', $outage);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,22 +14,20 @@
|
||||
// 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\forms\outage;
|
||||
namespace auth_outage\form\outage;
|
||||
|
||||
use moodleform;
|
||||
|
||||
if (!defined('MOODLE_INTERNAL')) {
|
||||
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
|
||||
}
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->libdir . '/formslib.php');
|
||||
require_once($CFG->libdir.'/formslib.php');
|
||||
|
||||
/**
|
||||
* Outage finish confirmation form.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class finish extends moodleform {
|
||||
@@ -14,19 +14,21 @@
|
||||
// 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\cli;
|
||||
namespace auth_outage\local\cli;
|
||||
|
||||
use Exception;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Exception executing CLI.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class cliexception extends Exception {
|
||||
class cli_exception extends Exception {
|
||||
/**
|
||||
* cliexception constructor.
|
||||
* @param string $message An explanation of the exception.
|
||||
@@ -34,6 +36,6 @@ class cliexception extends Exception {
|
||||
* @param Exception|null $previous Another exception as reference.
|
||||
*/
|
||||
public function __construct($message, $code = 1, Exception $previous = null) {
|
||||
parent::__construct('*ERROR* ' . $message, $code, $previous = null);
|
||||
parent::__construct('*ERROR* '.$message, $code, $previous = null);
|
||||
}
|
||||
}
|
||||
@@ -14,22 +14,24 @@
|
||||
// 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\cli;
|
||||
namespace auth_outage\local\cli;
|
||||
|
||||
use coding_exception;
|
||||
use core\session\manager;
|
||||
use InvalidArgumentException;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Outage CLI base class.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
abstract class clibase {
|
||||
/**
|
||||
* @var array Options passed as parameters to the CLI.
|
||||
* @var mixed[] Options passed as parameters to the CLI.
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
@@ -40,28 +42,28 @@ abstract class clibase {
|
||||
|
||||
/**
|
||||
* clibase constructor.
|
||||
* @param array|null $options The parameters to use or null to read from the command line.
|
||||
* @throws cliexception
|
||||
* @param mixed[]|null $options The parameters to use or null to read from the command line.
|
||||
* @throws cli_exception
|
||||
*/
|
||||
public function __construct(array $options = null) {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir . '/clilib.php');
|
||||
require_once($CFG->libdir.'/clilib.php');
|
||||
|
||||
$this->becomeadmin();
|
||||
$this->become_admin_user();
|
||||
|
||||
if (is_null($options)) {
|
||||
// Using Moodle CLI API to read the parameters.
|
||||
list($options, $unrecognized) = cli_get_params($this->generateoptions(), $this->generateshortcuts());
|
||||
list($options, $unrecognized) = cli_get_params($this->generate_options(), $this->generate_shortcuts());
|
||||
if ($unrecognized) {
|
||||
$unrecognized = implode("\n ", $unrecognized);
|
||||
throw new cliexception(get_string('cliunknowoption', 'admin', $unrecognized));
|
||||
throw new cli_exception(get_string('cliunknowoption', 'admin', $unrecognized));
|
||||
}
|
||||
} else {
|
||||
// If not using Moodle CLI API to read parameters, ensure all keys exist.
|
||||
$default = $this->generateoptions();
|
||||
$default = $this->generate_options();
|
||||
foreach ($options as $k => $v) {
|
||||
if (!array_key_exists($k, $default)) {
|
||||
throw new cliexception(get_string('cliunknowoption', 'admin', $k));
|
||||
throw new cli_exception(get_string('cliunknowoption', 'admin', $k));
|
||||
}
|
||||
$default[$k] = $v;
|
||||
}
|
||||
@@ -75,25 +77,26 @@ abstract class clibase {
|
||||
/**
|
||||
* Sets the reference time for creating outages.
|
||||
* @param int $time Timestamp for the reference time.
|
||||
* @throws coding_exception
|
||||
*/
|
||||
public function set_referencetime($time) {
|
||||
if (!is_int($time) || ($time <= 0)) {
|
||||
throw new InvalidArgumentException('$time must be a positive int.');
|
||||
throw new coding_exception('$time must be a positive int.', $time);
|
||||
}
|
||||
$this->time = $time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates all options (parameters) available for the CLI command.
|
||||
* @return array Options.
|
||||
* @return mixed[] Options.
|
||||
*/
|
||||
public abstract function generateoptions();
|
||||
public abstract function generate_options();
|
||||
|
||||
/**
|
||||
* Generate all short forms for the available options.
|
||||
* @return array Short form options.
|
||||
* @return string[] Short form options.
|
||||
*/
|
||||
public abstract function generateshortcuts();
|
||||
public abstract function generate_shortcuts();
|
||||
|
||||
/**
|
||||
* Executes the CLI script.
|
||||
@@ -103,9 +106,9 @@ abstract class clibase {
|
||||
/**
|
||||
* Change session to admin user.
|
||||
*/
|
||||
protected function becomeadmin() {
|
||||
protected function become_admin_user() {
|
||||
global $DB;
|
||||
$user = $DB->get_record('user', array('id' => 2));
|
||||
$user = $DB->get_record('user', ['id' => 2]);
|
||||
unset($user->description);
|
||||
unset($user->access);
|
||||
unset($user->preference);
|
||||
@@ -117,15 +120,15 @@ abstract class clibase {
|
||||
* Outputs a help message.
|
||||
* @param string $cliname Name of CLI used in the language file.
|
||||
*/
|
||||
protected function showhelp($cliname) {
|
||||
$options = $this->generateoptions();
|
||||
$shorts = array_flip($this->generateshortcuts());
|
||||
protected function show_help($cliname) {
|
||||
$options = $this->generate_options();
|
||||
$shorts = array_flip($this->generate_shortcuts());
|
||||
|
||||
printf("%s\n\n", get_string('cli' . $cliname . 'help', 'auth_outage'));
|
||||
printf("%s\n\n", get_string('cli'.$cliname.'help', 'auth_outage'));
|
||||
foreach (array_keys($options) as $long) {
|
||||
$text = get_string('cli' . $cliname . 'param' . $long, 'auth_outage');
|
||||
$short = isset($shorts[$long]) ? ('-' . $shorts[$long] . ',') : '';
|
||||
$long = '--' . $long;
|
||||
$text = get_string('cli'.$cliname.'param'.$long, 'auth_outage');
|
||||
$short = isset($shorts[$long]) ? ('-'.$shorts[$long].',') : '';
|
||||
$long = '--'.$long;
|
||||
printf(" %-4s %-20s %s\n", $short, $long, $text);
|
||||
}
|
||||
}
|
||||
@@ -14,32 +14,34 @@
|
||||
// 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\cli;
|
||||
namespace auth_outage\local\cli;
|
||||
|
||||
use auth_outage\models\outage;
|
||||
use auth_outage\outagedb;
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\local\outagedb;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Outage CLI to create outage.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class create extends clibase {
|
||||
/**
|
||||
* @var array Defaults to use if given option is null.
|
||||
* @var mixed[] Defaults to use if given option is null.
|
||||
*/
|
||||
private $defaults;
|
||||
|
||||
/**
|
||||
* Generates all options (parameters) available for the CLI command.
|
||||
* @return array Options.
|
||||
* @return mixed[] Options.
|
||||
*/
|
||||
public function generateoptions() {
|
||||
public function generate_options() {
|
||||
// Do not provide some defaults, if cloning an outage we need to know which parameters were provided.
|
||||
$options = [
|
||||
return [
|
||||
'help' => false,
|
||||
'clone' => null,
|
||||
'warn' => null,
|
||||
@@ -50,14 +52,13 @@ class create extends clibase {
|
||||
'onlyid' => false,
|
||||
'block' => false,
|
||||
];
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate all short forms for the available options.
|
||||
* @return array Short form options.
|
||||
* @return string[] Short form options.
|
||||
*/
|
||||
public function generateshortcuts() {
|
||||
public function generate_shortcuts() {
|
||||
return [
|
||||
'b' => 'block',
|
||||
'c' => 'clone',
|
||||
@@ -72,7 +73,7 @@ class create extends clibase {
|
||||
|
||||
/**
|
||||
* Sets the default values for options.
|
||||
* @param array $defaults Defaults.
|
||||
* @param mixed[] $defaults Defaults.
|
||||
*/
|
||||
public function set_defaults(array $defaults) {
|
||||
$this->defaults = $defaults;
|
||||
@@ -84,23 +85,23 @@ class create extends clibase {
|
||||
public function execute() {
|
||||
// Help always overrides any other parameter.
|
||||
if ($this->options['help']) {
|
||||
$this->showhelp('create');
|
||||
$this->show_help('create');
|
||||
return;
|
||||
}
|
||||
|
||||
// If not help mode, 'start' is required and cannot use default.
|
||||
if (is_null($this->options['start'])) {
|
||||
throw new cliexception(get_string('clierrormissingparamaters', 'auth_outage'));
|
||||
throw new cli_exception(get_string('clierrormissingparamaters', 'auth_outage'));
|
||||
}
|
||||
|
||||
// If cloning, set defaults to outage being cloned.
|
||||
if (!is_null($this->options['clone'])) {
|
||||
$this->clonedefaults();
|
||||
$this->clone_defaults();
|
||||
}
|
||||
|
||||
// Merge provided parameters with defaults then create outage.
|
||||
$options = $this->mergeoptions();
|
||||
$id = $this->createoutage($options);
|
||||
$options = $this->merge_options();
|
||||
$id = $this->create_outage($options);
|
||||
|
||||
if ($options['block']) {
|
||||
$block = new waitforit(['outageid' => $id]);
|
||||
@@ -110,10 +111,10 @@ class create extends clibase {
|
||||
|
||||
/**
|
||||
* Merges provided options with defaults, checking and converting types as needed.
|
||||
* @return array Parameters to use.
|
||||
* @throws cliexception
|
||||
* @return mixed[] Parameters to use.
|
||||
* @throws cli_exception
|
||||
*/
|
||||
private function mergeoptions() {
|
||||
private function merge_options() {
|
||||
$options = $this->options;
|
||||
// Merge with defaults.
|
||||
if (!is_null($this->defaults)) {
|
||||
@@ -124,17 +125,17 @@ class create extends clibase {
|
||||
}
|
||||
}
|
||||
|
||||
return $this->mergeoptions_checkparameters($options);
|
||||
return $this->merge_options_check_parameters($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an outages based on the provided options.
|
||||
* @param array $options Options used to create the outage.
|
||||
* @param mixed[] $options Options used to create the outage.
|
||||
* @return int Id of the new outage.
|
||||
*/
|
||||
private function createoutage(array $options) {
|
||||
private function create_outage(array $options) {
|
||||
// We need to become an admin to avoid permission problems.
|
||||
$this->becomeadmin();
|
||||
$this->become_admin_user();
|
||||
|
||||
// Create the outage.
|
||||
$start = $this->time + $options['start'];
|
||||
@@ -157,10 +158,10 @@ class create extends clibase {
|
||||
return $id;
|
||||
}
|
||||
|
||||
private function clonedefaults() {
|
||||
private function clone_defaults() {
|
||||
$id = $this->options['clone'];
|
||||
if (!is_number($id) || ($id <= 0)) {
|
||||
throw new cliexception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => 'clone']));
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => 'clone']));
|
||||
}
|
||||
|
||||
$outage = outagedb::get_by_id((int)$id);
|
||||
@@ -174,30 +175,30 @@ class create extends clibase {
|
||||
|
||||
/**
|
||||
* Check parameters converting their type as needed.
|
||||
* @param array $options Input options.
|
||||
* @return array Output options.
|
||||
* @throws cliexception
|
||||
* @param mixed $options Input options.
|
||||
* @return mixed Output options.
|
||||
* @throws cli_exception
|
||||
*/
|
||||
private function mergeoptions_checkparameters(array $options) {
|
||||
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 cliexception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => $param]));
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => $param]));
|
||||
}
|
||||
$options[$param] = (int)$options[$param];
|
||||
if ($options[$param] < 0) {
|
||||
throw new cliexception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => $param]));
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => $param]));
|
||||
}
|
||||
}
|
||||
|
||||
// Check parameters that must be a non empty string.
|
||||
foreach (['title', 'description'] as $param) {
|
||||
if (!is_string($options[$param])) {
|
||||
throw new cliexception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => $param]));
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => $param]));
|
||||
}
|
||||
$options[$param] = trim($options[$param]);
|
||||
if (strlen($options[$param]) == 0) {
|
||||
throw new cliexception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => $param]));
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => $param]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,25 +14,27 @@
|
||||
// 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\cli;
|
||||
namespace auth_outage\local\cli;
|
||||
|
||||
use auth_outage\models\outage;
|
||||
use auth_outage\outagedb;
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\local\outagedb;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Outage CLI to finish an outage.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class finish extends clibase {
|
||||
/**
|
||||
* Generates all options (parameters) available for the CLI command.
|
||||
* @return array Options.
|
||||
* @return mixed[] Options.
|
||||
*/
|
||||
public function generateoptions() {
|
||||
public function generate_options() {
|
||||
// Do not provide some defaults, if cloning an outage we need to know which parameters were provided.
|
||||
$options = [
|
||||
'help' => false,
|
||||
@@ -44,9 +46,9 @@ class finish extends clibase {
|
||||
|
||||
/**
|
||||
* Generate all short forms for the available options.
|
||||
* @return array Short form options.
|
||||
* @return string[] Short form options.
|
||||
*/
|
||||
public function generateshortcuts() {
|
||||
public function generate_shortcuts() {
|
||||
return [
|
||||
'h' => 'help',
|
||||
'id' => 'outageid',
|
||||
@@ -60,7 +62,7 @@ class finish extends clibase {
|
||||
public function execute() {
|
||||
// Help always overrides any other parameter.
|
||||
if ($this->options['help']) {
|
||||
$this->showhelp('finish');
|
||||
$this->show_help('finish');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -68,12 +70,12 @@ class finish extends clibase {
|
||||
$byid = !is_null($this->options['outageid']);
|
||||
$byactive = $this->options['active'];
|
||||
if ($byid == $byactive) {
|
||||
throw new cliexception(get_string('cliwaitforiterroridxoractive', 'auth_outage'));
|
||||
throw new cli_exception(get_string('cliwaitforiterroridxoractive', 'auth_outage'));
|
||||
}
|
||||
|
||||
$outage = $this->get_outage();
|
||||
if (!$outage->is_ongoing()) {
|
||||
throw new cliexception(get_string('clifinishnotongoing', 'auth_outage'));
|
||||
throw new cli_exception(get_string('clifinishnotongoing', 'auth_outage'));
|
||||
}
|
||||
|
||||
outagedb::finish($outage->id, $this->time);
|
||||
@@ -82,7 +84,7 @@ class finish extends clibase {
|
||||
/**
|
||||
* Gets the outage to finish.
|
||||
* @return outage|null The outage to wait for.
|
||||
* @throws cliexception
|
||||
* @throws cli_exception
|
||||
*/
|
||||
private function get_outage() {
|
||||
if ($this->options['active']) {
|
||||
@@ -90,13 +92,13 @@ class finish extends clibase {
|
||||
} else {
|
||||
$id = $this->options['outageid'];
|
||||
if (!is_number($id) || ($id <= 0)) {
|
||||
throw new cliexception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => 'outageid']));
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => 'outageid']));
|
||||
}
|
||||
$outage = outagedb::get_by_id((int)$id);
|
||||
}
|
||||
|
||||
if (is_null($outage)) {
|
||||
throw new cliexception(get_string('clierroroutagenotfound', 'auth_outage'));
|
||||
throw new cli_exception(get_string('clierroroutagenotfound', 'auth_outage'));
|
||||
}
|
||||
|
||||
return $outage;
|
||||
@@ -14,17 +14,19 @@
|
||||
// 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\cli;
|
||||
namespace auth_outage\local\cli;
|
||||
|
||||
use auth_outage\models\outage;
|
||||
use auth_outage\outagedb;
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\local\outagedb;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Outage CLI to wait for an outage to start.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class waitforit extends clibase {
|
||||
@@ -40,9 +42,9 @@ class waitforit extends clibase {
|
||||
|
||||
/**
|
||||
* Generates all options (parameters) available for the CLI command.
|
||||
* @return array Options.
|
||||
* @return mixed[] Options.
|
||||
*/
|
||||
public function generateoptions() {
|
||||
public function generate_options() {
|
||||
// Do not provide some defaults, if cloning an outage we need to know which parameters were provided.
|
||||
$options = [
|
||||
'help' => false,
|
||||
@@ -56,9 +58,9 @@ class waitforit extends clibase {
|
||||
|
||||
/**
|
||||
* Generate all short forms for the available options.
|
||||
* @return array Short form options.
|
||||
* @return string[] Short form options.
|
||||
*/
|
||||
public function generateshortcuts() {
|
||||
public function generate_shortcuts() {
|
||||
return [
|
||||
'h' => 'help',
|
||||
'id' => 'outageid',
|
||||
@@ -82,7 +84,7 @@ class waitforit extends clibase {
|
||||
public function execute() {
|
||||
// Help always overrides any other parameter.
|
||||
if ($this->options['help']) {
|
||||
$this->showhelp('waitforit');
|
||||
$this->show_help('waitforit');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -90,20 +92,20 @@ class waitforit extends clibase {
|
||||
$byid = !is_null($this->options['outageid']);
|
||||
$byactive = $this->options['active'];
|
||||
if ($byid == $byactive) {
|
||||
throw new cliexception(get_string('cliwaitforiterroridxoractive', 'auth_outage'));
|
||||
throw new cli_exception(get_string('cliwaitforiterroridxoractive', 'auth_outage'));
|
||||
}
|
||||
|
||||
$this->verbose('Verbose mode activated.');
|
||||
|
||||
$outage = $this->get_outage();
|
||||
|
||||
while ($sleep = $this->waitforoutagestart($outage)) {
|
||||
while ($sleep = $this->wait_for_outage_to_start($outage)) {
|
||||
if (is_null($this->sleepcallback)) {
|
||||
$this->verbose('Sleeping for ' . $sleep . ' second(s).');
|
||||
$this->verbose('Sleeping for '.$sleep.' second(s).');
|
||||
sleep($sleep);
|
||||
$this->time = time();
|
||||
} else {
|
||||
$this->verbose('Calling callback to sleep ' . $sleep . ' second(s).');
|
||||
$this->verbose('Calling callback to sleep '.$sleep.' second(s).');
|
||||
$callback = $this->sleepcallback;
|
||||
$this->time = $callback($sleep);
|
||||
}
|
||||
@@ -126,7 +128,7 @@ class waitforit extends clibase {
|
||||
/**
|
||||
* Gets the outage to wait for.
|
||||
* @return outage|null The outage to wait for.
|
||||
* @throws cliexception
|
||||
* @throws cli_exception
|
||||
*/
|
||||
private function get_outage() {
|
||||
if ($this->options['active']) {
|
||||
@@ -135,29 +137,35 @@ class waitforit extends clibase {
|
||||
} else {
|
||||
$id = $this->options['outageid'];
|
||||
if (!is_number($id) || ($id <= 0)) {
|
||||
throw new cliexception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => 'outageid']));
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => 'outageid']));
|
||||
}
|
||||
$this->verbose('Querying database for outage #' . $id . '...');
|
||||
$this->verbose('Querying database for outage #'.$id.'...');
|
||||
$outage = outagedb::get_by_id((int)$id);
|
||||
}
|
||||
|
||||
if (is_null($outage)) {
|
||||
throw new cliexception(get_string('clierroroutagenotfound', 'auth_outage'));
|
||||
throw new cli_exception(get_string('clierroroutagenotfound', 'auth_outage'));
|
||||
}
|
||||
|
||||
$this->verbose('Found outage #' . $outage->id . ': ' . $outage->get_title());
|
||||
$this->verbose('Found outage #'.$outage->id.': '.$outage->get_title());
|
||||
return $outage;
|
||||
}
|
||||
|
||||
private function waitforoutagestart(outage $outage) {
|
||||
/**
|
||||
* Calculate how many seconds to wait for the outage to start.
|
||||
* @param outage $outage Outage to consider.
|
||||
* @return int Seconds until it stars.
|
||||
* @throws cli_exception
|
||||
*/
|
||||
private function wait_for_outage_to_start(outage $outage) {
|
||||
$this->verbose('Checking outage status...');
|
||||
// Outage should not change while waiting to start.
|
||||
if (outagedb::get_by_id($outage->id) != $outage) {
|
||||
throw new cliexception(get_string('clierroroutagechanged', 'auth_outage'));
|
||||
throw new cli_exception(get_string('clierroroutagechanged', 'auth_outage'));
|
||||
}
|
||||
// Outage cannot have already ended.
|
||||
if ($outage->has_ended($this->time)) {
|
||||
throw new cliexception(get_string('clierroroutageended', 'auth_outage'));
|
||||
throw new cli_exception(get_string('clierroroutageended', 'auth_outage'));
|
||||
}
|
||||
// If outage has started, do not wait.
|
||||
if ($outage->is_ongoing($this->time)) {
|
||||
@@ -14,13 +14,15 @@
|
||||
// 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;
|
||||
namespace auth_outage\local\controllers;
|
||||
|
||||
use auth_outage\models\outage;
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\local\outagedb;
|
||||
use auth_outage\local\outagelib;
|
||||
use coding_exception;
|
||||
use context_system;
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use file_exception;
|
||||
use invalid_state_exception;
|
||||
use moodle_url;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
@@ -33,7 +35,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class infopage_controller {
|
||||
class infopage {
|
||||
/**
|
||||
* @var outage|null The outage to display or null if none found.
|
||||
*/
|
||||
@@ -46,7 +48,7 @@ class infopage_controller {
|
||||
|
||||
/**
|
||||
* infopage_controller constructor.
|
||||
* @param array|null $params Parameters to use or null to get from Moodle API (request).
|
||||
* @param mixed[]|null $params Parameters to use or null to get from Moodle API (request).
|
||||
*/
|
||||
public function __construct(array $params = null) {
|
||||
if (is_null($params)) {
|
||||
@@ -74,7 +76,7 @@ class infopage_controller {
|
||||
*/
|
||||
public static function find_outageid_from_infopage($html) {
|
||||
if (!is_string($html)) {
|
||||
throw new InvalidArgumentException('$html must be a string.');
|
||||
throw new coding_exception('$html must be a string.', $html);
|
||||
}
|
||||
|
||||
$output = [];
|
||||
@@ -88,24 +90,23 @@ class infopage_controller {
|
||||
* Saves a static info page for the given outage.
|
||||
* @param outage $outage Outage to generate the info page.
|
||||
* @param string $file File to save the static info page.
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function save_static_page(outage $outage, $file) {
|
||||
if (!is_string($file)) {
|
||||
throw new InvalidArgumentException('$file is not a string.');
|
||||
throw new coding_exception('$file is not a string.', $file);
|
||||
}
|
||||
|
||||
$info = new infopage_controller(['outage' => $outage, 'static' => true]);
|
||||
$info = new infopage(['outage' => $outage, 'static' => true]);
|
||||
$html = $info->get_output();
|
||||
|
||||
// Sanity check before writing/overwriting old file.
|
||||
if (!is_string($html) || ($html == '') || (html_to_text($html) == '')) {
|
||||
throw new Exception('Sanity check failed. Invalid contents on $html.');
|
||||
throw new invalid_state_exception('Sanity check failed. Invalid contents on $html.');
|
||||
}
|
||||
|
||||
$dir = dirname($file);
|
||||
if (!file_exists($dir) || !is_dir($dir)) {
|
||||
throw new Exception('Directory must exists: ' . $dir);
|
||||
throw new file_exception('Directory must exists: '.$dir);
|
||||
}
|
||||
file_put_contents($file, $html);
|
||||
}
|
||||
@@ -113,14 +114,13 @@ class infopage_controller {
|
||||
/**
|
||||
* Updates the static info page by (re)creating or deleting it as needed.
|
||||
* @param null $file
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function update_static_page($file = null) {
|
||||
if (is_null($file)) {
|
||||
$file = self::get_defaulttemplatefile();
|
||||
}
|
||||
if (!is_string($file)) {
|
||||
throw new InvalidArgumentException('$file is not a string.');
|
||||
throw new coding_exception('$file is not a string.', $file);
|
||||
}
|
||||
|
||||
$outage = outagedb::get_next_starting();
|
||||
@@ -129,7 +129,7 @@ class infopage_controller {
|
||||
if (is_file($file) && is_writable($file)) {
|
||||
unlink($file);
|
||||
} else {
|
||||
throw new Exception('Cannot remove: ' . $file);
|
||||
throw new file_exception('Cannot remove: '.$file);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -142,7 +142,7 @@ class infopage_controller {
|
||||
*/
|
||||
public static function get_defaulttemplatefile() {
|
||||
global $CFG;
|
||||
return $CFG->dataroot . '/climaintenance.template.html';
|
||||
return $CFG->dataroot.'/climaintenance.template.html';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,6 +152,7 @@ class infopage_controller {
|
||||
public function get_output() {
|
||||
ob_start();
|
||||
try {
|
||||
// TODO what if redirection occurs here?
|
||||
$this->output();
|
||||
return ob_get_contents();
|
||||
} finally {
|
||||
@@ -184,7 +185,7 @@ class infopage_controller {
|
||||
|
||||
$PAGE->set_context(context_system::instance());
|
||||
if ($this->static) {
|
||||
require($CFG->dirroot . '/auth/outage/views/info/static.php');
|
||||
require($CFG->dirroot.'/auth/outage/views/info/static.php');
|
||||
} else {
|
||||
$PAGE->set_title($this->outage->get_title());
|
||||
$PAGE->set_heading($this->outage->get_title());
|
||||
@@ -194,22 +195,22 @@ class infopage_controller {
|
||||
outagelib::inject();
|
||||
|
||||
echo $OUTPUT->header();
|
||||
require($CFG->dirroot . '/auth/outage/views/info/content.php');
|
||||
require($CFG->dirroot.'/auth/outage/views/info/content.php');
|
||||
echo $OUTPUT->footer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts the fields according to the given parameters.
|
||||
* @param array $params
|
||||
* @param mixed[] $params
|
||||
*/
|
||||
private function set_parameters(array $params) {
|
||||
if (!is_null($params['outage']) && !($params['outage'] instanceof outage)) {
|
||||
throw new InvalidArgumentException('Provided outage is not a valid outage object.');
|
||||
throw new coding_exception('Provided outage is not a valid outage object.', $params['outage']);
|
||||
}
|
||||
|
||||
if (!is_null($params['id']) && !is_null($params['outage']) && ($params['id'] !== $params['outage']->id)) {
|
||||
throw new InvalidArgumentException('Provided id and outage->id do not match.');
|
||||
throw new coding_exception('Provided id and outage->id do not match.', $params);
|
||||
}
|
||||
|
||||
if (is_null($params['id']) && is_null($params['outage'])) {
|
||||
@@ -14,16 +14,19 @@
|
||||
// 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\models;
|
||||
namespace auth_outage\local;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use coding_exception;
|
||||
use stdClass;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Outage class with all information about one specific outage.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class outage {
|
||||
@@ -104,8 +107,8 @@ class outage {
|
||||
|
||||
/**
|
||||
* outage constructor.
|
||||
* @param object|array|null The data for the outage.
|
||||
* @throws InvalidArgumentException
|
||||
* @param stdClass|mixed[]|null The data for the outage.
|
||||
* @throws coding_exception
|
||||
*/
|
||||
public function __construct($data = null) {
|
||||
if (is_null($data)) {
|
||||
@@ -115,7 +118,7 @@ class outage {
|
||||
$data = (array)$data;
|
||||
}
|
||||
if (!is_array($data)) {
|
||||
throw new InvalidArgumentException('$data is not an object, an array or null.');
|
||||
throw new coding_exception('$data is not an object, an array or null.', $data);
|
||||
}
|
||||
|
||||
// Load data from array.
|
||||
@@ -136,13 +139,14 @@ class outage {
|
||||
* Gets at which stage is this outage.
|
||||
* @param int|null $time Null to check the current stage or a timestamp to check for another time.
|
||||
* @return int Stage, compare with STAGE_* constants.
|
||||
* @throws coding_exception
|
||||
*/
|
||||
public function get_stage($time = null) {
|
||||
if ($time === null) {
|
||||
$time = time();
|
||||
}
|
||||
if (!is_int($time) || ($time <= 0)) {
|
||||
throw new InvalidArgumentException('$time must be an positive int.');
|
||||
throw new coding_exception('$time must be an positive int.', $time);
|
||||
}
|
||||
|
||||
if (!is_null($this->finished) && ($time >= $this->finished)) {
|
||||
@@ -218,27 +222,6 @@ class outage {
|
||||
return $this->finished - $this->starttime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the input string with all placeholders replaced.
|
||||
* @param $str string Input string.
|
||||
* @return string Output string.
|
||||
*/
|
||||
private function replace_placeholders($str) {
|
||||
return str_replace(
|
||||
[
|
||||
'{{start}}',
|
||||
'{{stop}}',
|
||||
'{{duration}}',
|
||||
],
|
||||
[
|
||||
userdate($this->starttime, get_string('datetimeformat', 'auth_outage')),
|
||||
userdate($this->stoptime, get_string('datetimeformat', 'auth_outage')),
|
||||
format_time($this->get_duration_planned()),
|
||||
],
|
||||
$str
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the planned duration of the outage (start to planned stop, warning not included).
|
||||
* @return int Duration in seconds.
|
||||
@@ -262,4 +245,25 @@ class outage {
|
||||
public function get_warning_duration() {
|
||||
return $this->starttime - $this->warntime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the input string with all placeholders replaced.
|
||||
* @param $str string Input string.
|
||||
* @return string Output string.
|
||||
*/
|
||||
private function replace_placeholders($str) {
|
||||
return str_replace(
|
||||
[
|
||||
'{{start}}',
|
||||
'{{stop}}',
|
||||
'{{duration}}',
|
||||
],
|
||||
[
|
||||
userdate($this->starttime, get_string('datetimeformat', 'auth_outage')),
|
||||
userdate($this->stoptime, get_string('datetimeformat', 'auth_outage')),
|
||||
format_time($this->get_duration_planned()),
|
||||
],
|
||||
$str
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -14,18 +14,18 @@
|
||||
// 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;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/calendar/lib.php');
|
||||
namespace auth_outage\local;
|
||||
|
||||
use auth_outage\event\outage_created;
|
||||
use auth_outage\event\outage_deleted;
|
||||
use auth_outage\event\outage_updated;
|
||||
use auth_outage\models\outage;
|
||||
use auth_outage\local\controllers\infopage;
|
||||
use calendar_event;
|
||||
use InvalidArgumentException;
|
||||
use coding_exception;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot.'/calendar/lib.php');
|
||||
|
||||
/**
|
||||
* The DB Context to manipulate Outages.
|
||||
@@ -33,7 +33,7 @@ use InvalidArgumentException;
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class outagedb {
|
||||
@@ -63,15 +63,13 @@ class outagedb {
|
||||
/**
|
||||
* @param $id int Outage id to get.
|
||||
* @return outage|null Returns the outage or null if not found.
|
||||
* @throws coding_exception
|
||||
*/
|
||||
public static function get_by_id($id) {
|
||||
global $DB;
|
||||
|
||||
if (!is_int($id)) {
|
||||
throw new InvalidArgumentException('$id must be an int.');
|
||||
}
|
||||
if ($id <= 0) {
|
||||
throw new InvalidArgumentException('$id must be positive.');
|
||||
if (!is_int($id) || ($id <= 0)) {
|
||||
throw new coding_exception('$id must be an positive int.', $id);
|
||||
}
|
||||
|
||||
$outage = $DB->get_record('auth_outage', ['id' => $id]);
|
||||
@@ -121,7 +119,7 @@ class outagedb {
|
||||
}
|
||||
|
||||
// Trigger static page update.
|
||||
infopage_controller::update_static_page();
|
||||
infopage::update_static_page();
|
||||
|
||||
// All done, return the id.
|
||||
return $outage->id;
|
||||
@@ -131,16 +129,13 @@ class outagedb {
|
||||
* Deletes an outage from the database.
|
||||
*
|
||||
* @param int $id Outage ID to delete
|
||||
* @throws InvalidArgumentException If ID is not valid.
|
||||
* @throws coding_exception
|
||||
*/
|
||||
public static function delete($id) {
|
||||
global $DB;
|
||||
|
||||
if (!is_int($id)) {
|
||||
throw new InvalidArgumentException('$id must be an int.');
|
||||
}
|
||||
if ($id <= 0) {
|
||||
throw new InvalidArgumentException('$id must be positive.');
|
||||
if (!is_int($id) || ($id <= 0)) {
|
||||
throw new coding_exception('$id must be an int.', $id);
|
||||
}
|
||||
|
||||
// Log it.
|
||||
@@ -154,7 +149,7 @@ class outagedb {
|
||||
self::calendar_delete($id);
|
||||
|
||||
// Trigger static page update.
|
||||
infopage_controller::update_static_page();
|
||||
infopage::update_static_page();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,6 +159,7 @@ class outagedb {
|
||||
* - Outages that stop later are more important.
|
||||
* @param int|null $time Timestamp considered to check for outages, null for current date/time.
|
||||
* @return outage|null The outage or null if no active outages were found.
|
||||
* @throws coding_exception
|
||||
*/
|
||||
public static function get_active($time = null) {
|
||||
global $DB;
|
||||
@@ -171,8 +167,8 @@ class outagedb {
|
||||
if ($time === null) {
|
||||
$time = time();
|
||||
}
|
||||
if (!is_int($time)) {
|
||||
throw new InvalidArgumentException('$time must be null or an int.');
|
||||
if (!is_int($time) || ($time <= 0)) {
|
||||
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.
|
||||
@@ -195,7 +191,8 @@ class outagedb {
|
||||
/**
|
||||
* Gets all outages that have not ended yet.
|
||||
* @param int|null $time Timestamp considered to check for outages, null for current date/time.
|
||||
* @return array An array of outages or an empty array if no unded outages were found.
|
||||
* @return outage[] An array of outages or an empty array if no unded outages were found.
|
||||
* @throws coding_exception
|
||||
*/
|
||||
public static function get_all_unended($time = null) {
|
||||
global $DB;
|
||||
@@ -203,8 +200,8 @@ class outagedb {
|
||||
if ($time === null) {
|
||||
$time = time();
|
||||
}
|
||||
if (!is_int($time)) {
|
||||
throw new InvalidArgumentException('$time must be null or an int.');
|
||||
if (!is_int($time) || ($time <= 0)) {
|
||||
throw new coding_exception('$time must be null or a positive int.');
|
||||
}
|
||||
|
||||
$outages = [];
|
||||
@@ -226,7 +223,8 @@ class outagedb {
|
||||
/**
|
||||
* Gets all ended outages.
|
||||
* @param int|null $time Timestamp considered to check for outages, null for current date/time.
|
||||
* @return array An array of outages or an empty array if no ended outages found.
|
||||
* @return outage[] An array of outages or an empty array if no ended outages found.
|
||||
* @throws coding_exception
|
||||
*/
|
||||
public static function get_all_ended($time = null) {
|
||||
global $DB;
|
||||
@@ -234,8 +232,8 @@ class outagedb {
|
||||
if ($time === null) {
|
||||
$time = time();
|
||||
}
|
||||
if (!is_int($time)) {
|
||||
throw new InvalidArgumentException('$time must be null or an int.');
|
||||
if (!is_int($time) || ($time <= 0)) {
|
||||
throw new coding_exception('$time must be null or a positive int.', $time);
|
||||
}
|
||||
|
||||
$outages = [];
|
||||
@@ -258,23 +256,24 @@ class outagedb {
|
||||
* Marks an outage as finished.
|
||||
* @param int $id Outage id.
|
||||
* @param int|null $time Timestamp to consider as finished date or null for current time.
|
||||
* @throws coding_exception
|
||||
*/
|
||||
public static function finish($id, $time = null) {
|
||||
if (is_null($time)) {
|
||||
$time = time();
|
||||
}
|
||||
if (!is_int($time) && ($time <= 0)) {
|
||||
throw new InvalidArgumentException('$time must be an int or null.');
|
||||
if (!is_int($time) || ($time <= 0)) {
|
||||
throw new coding_exception('$time must be null or a positive int.', $time);
|
||||
}
|
||||
|
||||
$outage = self::get_by_id($id);
|
||||
if (is_null($outage)) {
|
||||
debugging('Cannot finish outage #' . $id . ': outage not found.');
|
||||
debugging('Cannot finish outage #'.$id.': outage not found.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$outage->is_ongoing($time)) {
|
||||
debugging('Cannot finish outage #' . $id . ': outage not ongoing.');
|
||||
debugging('Cannot finish outage #'.$id.': outage not ongoing.');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -286,6 +285,7 @@ class outagedb {
|
||||
* Gets the next outage which has not started yet.
|
||||
* @param null $time Timestamp reference for current time.
|
||||
* @return outage|null The outage or null if not found.
|
||||
* @throws coding_exception
|
||||
*/
|
||||
public static function get_next_starting($time = null) {
|
||||
global $DB;
|
||||
@@ -294,7 +294,7 @@ class outagedb {
|
||||
$time = time();
|
||||
}
|
||||
if (!is_int($time) || ($time <= 0)) {
|
||||
throw new InvalidArgumentException('$time must be null or an positive int.');
|
||||
throw new coding_exception('$time must be null or a positive int.', $time);
|
||||
}
|
||||
|
||||
$select = ':datetime <= starttime'; // End condition.
|
||||
@@ -329,7 +329,7 @@ class outagedb {
|
||||
$event = self::calendar_load($outage->id);
|
||||
|
||||
if (is_null($event)) {
|
||||
debugging('Cannot update calendar entry for outage #' . $outage->id . ', event not found. Creating it...');
|
||||
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));
|
||||
@@ -345,7 +345,7 @@ class outagedb {
|
||||
|
||||
// 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...');
|
||||
debugging('Cannot delete calendar entry for outage #'.$outageid.', event not found. Ignoring it...');
|
||||
} else {
|
||||
$event->delete();
|
||||
}
|
||||
@@ -354,7 +354,7 @@ class outagedb {
|
||||
/**
|
||||
* 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 array Calendar event data.
|
||||
* @return mixed[] Calendar event data.
|
||||
*/
|
||||
private static function calendar_data(outage $outage) {
|
||||
return [
|
||||
@@ -14,11 +14,12 @@
|
||||
// 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;
|
||||
namespace auth_outage\local;
|
||||
|
||||
use auth_outage_renderer;
|
||||
use Exception;
|
||||
use moodle_url;
|
||||
use stdClass;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -27,7 +28,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class outagelib {
|
||||
@@ -37,7 +38,7 @@ class outagelib {
|
||||
* Initializes admin pages for outage.
|
||||
* @return auth_outage_renderer The outage renderer for the page.
|
||||
*/
|
||||
public static function pagesetup() {
|
||||
public static function page_setup() {
|
||||
global $PAGE;
|
||||
admin_externalpage_setup('auth_outage_manage');
|
||||
$PAGE->set_url(new moodle_url('/auth/outage/manage.php'));
|
||||
@@ -86,10 +87,10 @@ class outagelib {
|
||||
}
|
||||
|
||||
// There is a previewing or active outage.
|
||||
$CFG->additionalhtmltopofbody = self::get_renderer()->renderoutagebar($active, $time)
|
||||
. $CFG->additionalhtmltopofbody;
|
||||
$CFG->additionalhtmltopofbody = self::get_renderer()->renderoutagebar($active, $time).
|
||||
$CFG->additionalhtmltopofbody;
|
||||
} catch (Exception $e) {
|
||||
debugging('Exception occured while injecting our code: ' . $e->getMessage());
|
||||
debugging('Exception occured while injecting our code: '.$e->getMessage());
|
||||
debugging($e->getTraceAsString(), DEBUG_DEVELOPER);
|
||||
}
|
||||
}
|
||||
@@ -97,7 +98,7 @@ class outagelib {
|
||||
/**
|
||||
* Creates a configuration object ensuring all parameters are set,
|
||||
* loading defaults even if the plugin is not configured.
|
||||
* @return object Configuration object with all parameters set.
|
||||
* @return stdClass Configuration object with all parameters set.
|
||||
*/
|
||||
public static function get_config() {
|
||||
return (object)array_merge(self::get_config_defaults(), (array)get_config('auth_outage'));
|
||||
@@ -105,7 +106,7 @@ class outagelib {
|
||||
|
||||
/**
|
||||
* Creates the default configurations. If the plugin is not configured we should use those defaults.
|
||||
* @return array Default configuration.
|
||||
* @return mixed[] Default configuration.
|
||||
*/
|
||||
public static function get_config_defaults() {
|
||||
global $CFG;
|
||||
@@ -115,7 +116,7 @@ class outagelib {
|
||||
'warning_duration' => 60,
|
||||
'warning_title' => get_string('defaultwarningtitlevalue', 'auth_outage'),
|
||||
'warning_description' => get_string('defaultwarningdescriptionvalue', 'auth_outage'),
|
||||
'css' => file_get_contents($CFG->dirroot . '/auth/outage/views/warningbar.css'),
|
||||
'css' => file_get_contents($CFG->dirroot.'/auth/outage/views/warningbar.css'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -14,24 +14,26 @@
|
||||
// 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\tables\manage;
|
||||
namespace auth_outage\local\output\manage;
|
||||
|
||||
use auth_outage\models\outage;
|
||||
use auth_outage\local\outage;
|
||||
use flexible_table;
|
||||
use html_writer;
|
||||
use moodle_url;
|
||||
|
||||
require_once($CFG->libdir . '/tablelib.php');
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->libdir.'/tablelib.php');
|
||||
|
||||
/**
|
||||
* Manage outages table base.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <danielroperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class managebase extends flexible_table {
|
||||
class base_table extends flexible_table {
|
||||
private static $autoid = 0;
|
||||
|
||||
/**
|
||||
@@ -42,7 +44,7 @@ class managebase extends flexible_table {
|
||||
global $PAGE;
|
||||
|
||||
$id = (is_null($id) ? self::$autoid++ : $id);
|
||||
parent::__construct('auth_outage_manage_' . $id);
|
||||
parent::__construct('auth_outage_manage_'.$id);
|
||||
|
||||
$this->define_baseurl($PAGE->url);
|
||||
$this->set_attribute('class', 'generaltable admintable');
|
||||
@@ -80,7 +82,7 @@ class managebase extends flexible_table {
|
||||
html_writer::empty_tag('img', [
|
||||
'src' => $OUTPUT->pix_url('t/edit'),
|
||||
'alt' => get_string('edit'),
|
||||
'class' => 'iconsmall'
|
||||
'class' => 'iconsmall',
|
||||
]),
|
||||
['title' => get_string('edit')]
|
||||
);
|
||||
@@ -105,7 +107,7 @@ class managebase extends flexible_table {
|
||||
html_writer::empty_tag('img', [
|
||||
'src' => $OUTPUT->pix_url('t/check'),
|
||||
'alt' => get_string('finish', 'auth_outage'),
|
||||
'class' => 'iconsmall'
|
||||
'class' => 'iconsmall',
|
||||
]),
|
||||
['title' => get_string('finish', 'auth_outage')]
|
||||
);
|
||||
@@ -118,12 +120,12 @@ class managebase extends flexible_table {
|
||||
html_writer::empty_tag('img', [
|
||||
'src' => $OUTPUT->pix_url('t/delete'),
|
||||
'alt' => get_string('delete'),
|
||||
'class' => 'iconsmall'
|
||||
'class' => 'iconsmall',
|
||||
]),
|
||||
['title' => get_string('delete')]
|
||||
);
|
||||
}
|
||||
|
||||
return '<nobr>' . $buttons . '</nobr>';
|
||||
return '<nobr>'.$buttons.'</nobr>';
|
||||
}
|
||||
}
|
||||
@@ -14,23 +14,23 @@
|
||||
// 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\tables\manage;
|
||||
namespace auth_outage\local\output\manage;
|
||||
|
||||
use auth_outage\models\outage;
|
||||
use html_writer;
|
||||
use moodle_url;
|
||||
use auth_outage\local\outage;
|
||||
|
||||
require_once($CFG->libdir . '/tablelib.php');
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->libdir.'/tablelib.php');
|
||||
|
||||
/**
|
||||
* Manage outages table.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <danielroperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class history extends managebase {
|
||||
class history_table extends base_table {
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
@@ -58,22 +58,15 @@ class history extends managebase {
|
||||
*/
|
||||
public function set_data(array $outages) {
|
||||
foreach ($outages as $outage) {
|
||||
$title = html_writer::link(
|
||||
new moodle_url('/auth/outage/edit.php', ['id' => $outage->id]),
|
||||
$outage->get_title(),
|
||||
['title' => get_string('edit')]
|
||||
);
|
||||
|
||||
$finished = $outage->get_duration_actual();
|
||||
$finished = is_null($finished) ? '-' : format_time($finished);
|
||||
|
||||
$this->add_data([
|
||||
format_time($outage->get_warning_duration()),
|
||||
userdate($outage->starttime, get_string('datetimeformat', 'auth_outage')),
|
||||
format_time($outage->get_duration_planned()),
|
||||
$finished,
|
||||
$title,
|
||||
$this->set_data_buttons($outage, false),
|
||||
$outage->get_title(),
|
||||
$this->set_data_buttons($outage, true),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -14,21 +14,25 @@
|
||||
// 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\tables\manage;
|
||||
namespace auth_outage\local\output\manage;
|
||||
|
||||
use auth_outage\models\outage;
|
||||
use auth_outage\local\outage;
|
||||
use html_writer;
|
||||
use moodle_url;
|
||||
|
||||
require_once($CFG->libdir . '/tablelib.php');
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->libdir.'/tablelib.php');
|
||||
|
||||
/**
|
||||
* Manage outages table.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <danielroperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class planned extends managebase {
|
||||
class planned_table extends base_table {
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
@@ -55,12 +59,18 @@ class planned extends managebase {
|
||||
*/
|
||||
public function set_data(array $outages) {
|
||||
foreach ($outages as $outage) {
|
||||
$title = html_writer::link(
|
||||
new moodle_url('/auth/outage/edit.php', ['id' => $outage->id]),
|
||||
$outage->get_title(),
|
||||
['title' => get_string('edit')]
|
||||
);
|
||||
|
||||
$this->add_data([
|
||||
format_time($outage->get_warning_duration()),
|
||||
userdate($outage->starttime, get_string('datetimeformat', 'auth_outage')),
|
||||
format_time($outage->get_duration_planned()),
|
||||
$outage->get_title(),
|
||||
$this->set_data_buttons($outage, true),
|
||||
$title,
|
||||
$this->set_data_buttons($outage, false),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -19,16 +19,16 @@
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use auth_outage\cli\cliexception;
|
||||
use auth_outage\cli\create;
|
||||
use auth_outage\outagelib;
|
||||
use auth_outage\local\cli\cli_exception;
|
||||
use auth_outage\local\cli\create;
|
||||
use auth_outage\local\outagelib;
|
||||
|
||||
define('CLI_SCRIPT', true);
|
||||
require('../../config.php');
|
||||
require_once(__DIR__.'/../../../config.php');
|
||||
|
||||
$cli = new create();
|
||||
|
||||
@@ -44,6 +44,6 @@ $cli->set_defaults([
|
||||
|
||||
try {
|
||||
$cli->execute();
|
||||
} catch (cliexception $e) {
|
||||
} catch (cli_exception $e) {
|
||||
cli_error($e->getMessage());
|
||||
}
|
||||
|
||||
@@ -19,21 +19,21 @@
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use auth_outage\cli\cliexception;
|
||||
use auth_outage\cli\finish;
|
||||
use auth_outage\local\cli\cli_exception;
|
||||
use auth_outage\local\cli\finish;
|
||||
|
||||
define('CLI_SCRIPT', true);
|
||||
require('../../config.php');
|
||||
require_once(__DIR__.'/../../../config.php');
|
||||
|
||||
$cli = new finish();
|
||||
|
||||
try {
|
||||
$cli->execute();
|
||||
} catch (cliexception $e) {
|
||||
} catch (cli_exception $e) {
|
||||
cli_error($e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
@@ -19,21 +19,21 @@
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use auth_outage\cli\cliexception;
|
||||
use auth_outage\cli\waitforit;
|
||||
use auth_outage\local\cli\cli_exception;
|
||||
use auth_outage\local\cli\waitforit;
|
||||
|
||||
define('CLI_SCRIPT', true);
|
||||
require('../../config.php');
|
||||
require_once(__DIR__.'/../../../config.php');
|
||||
|
||||
$cli = new waitforit();
|
||||
|
||||
try {
|
||||
$cli->execute();
|
||||
} catch (cliexception $e) {
|
||||
} catch (cli_exception $e) {
|
||||
cli_error($e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
21
clone.php
21
clone.php
@@ -19,32 +19,33 @@
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use auth_outage\outagedb;
|
||||
use auth_outage\outagelib;
|
||||
use auth_outage\form\outage\edit;
|
||||
use auth_outage\local\outagedb;
|
||||
use auth_outage\local\outagelib;
|
||||
|
||||
require_once('../../config.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
require_once($CFG->libdir . '/formslib.php');
|
||||
require_once(__DIR__.'/../../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->libdir.'/formslib.php');
|
||||
|
||||
$renderer = outagelib::pagesetup();
|
||||
$renderer = outagelib::page_setup();
|
||||
|
||||
$mform = new \auth_outage\forms\outage\edit();
|
||||
$mform = new edit();
|
||||
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect('/auth/outage/manage.php');
|
||||
} else if ($outage = $mform->get_data()) {
|
||||
$id = outagedb::save($outage);
|
||||
redirect('/auth/outage/manage.php#auth_outage_id_' . $id);
|
||||
redirect('/auth/outage/manage.php#auth_outage_id_'.$id);
|
||||
}
|
||||
|
||||
$id = required_param('id', PARAM_INT);
|
||||
$outage = outagedb::get_by_id($id);
|
||||
if ($outage == null) {
|
||||
throw new invalid_parameter_exception('Outage #' . $id . ' not found.');
|
||||
throw new invalid_parameter_exception('Outage #'.$id.' not found.');
|
||||
}
|
||||
|
||||
// Remove outage id to force creating a new one.
|
||||
|
||||
@@ -1,28 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="auth/outage/db" VERSION="20160915" COMMENT="XMLDB file for Moodle auth/outage"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
|
||||
<XMLDB xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" PATH="auth/outage/db" VERSION="20160915"
|
||||
COMMENT="XMLDB file for Moodle auth/outage"
|
||||
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
<TABLES>
|
||||
<TABLE NAME="auth_outage" COMMENT="Table used for auth/outage plugin. Holds information about all past, current and future outages.">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||
<FIELD NAME="starttime" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="When outage starts."/>
|
||||
<FIELD NAME="stoptime" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="When outage ends."/>
|
||||
<FIELD NAME="warntime" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="When the outage will start showing a warning for that outage."/>
|
||||
<FIELD NAME="title" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" COMMENT="Title for the outage (short description)."/>
|
||||
<FIELD NAME="description" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="More information about the outage."/>
|
||||
<FIELD NAME="createdby" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Who created this entry."/>
|
||||
<FIELD NAME="modifiedby" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Who last modified this entry."/>
|
||||
<FIELD NAME="lastmodified" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="When was this entry last modified."/>
|
||||
<FIELD NAME="finished" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Timestamp of when the outage really finished."/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
</KEYS>
|
||||
<INDEXES>
|
||||
<INDEX NAME="start_stop_title" UNIQUE="false" FIELDS="starttime, stoptime, title"/>
|
||||
</INDEXES>
|
||||
</TABLE>
|
||||
</TABLES>
|
||||
</XMLDB>
|
||||
<TABLES>
|
||||
<TABLE NAME="auth_outage"
|
||||
COMMENT="Table used for auth/outage plugin. Holds information about all past, current and future outages.">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||
<FIELD NAME="starttime" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="When outage starts."/>
|
||||
<FIELD NAME="stoptime" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="When outage ends."/>
|
||||
<FIELD NAME="warntime" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"
|
||||
COMMENT="When the outage will start showing a warning for that outage."/>
|
||||
<FIELD NAME="title" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false"
|
||||
COMMENT="Title for the outage (short description)."/>
|
||||
<FIELD NAME="description" TYPE="text" NOTNULL="true" SEQUENCE="false"
|
||||
COMMENT="More information about the outage."/>
|
||||
<FIELD NAME="createdby" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Who created this entry."/>
|
||||
<FIELD NAME="modifiedby" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"
|
||||
COMMENT="Who last modified this entry."/>
|
||||
<FIELD NAME="lastmodified" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"
|
||||
COMMENT="When was this entry last modified."/>
|
||||
<FIELD NAME="finished" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"
|
||||
COMMENT="Timestamp of when the outage really finished."/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
</KEYS>
|
||||
<INDEXES>
|
||||
<INDEX NAME="start_stop_title" UNIQUE="false" FIELDS="starttime, stoptime, title"/>
|
||||
</INDEXES>
|
||||
</TABLE>
|
||||
</TABLES>
|
||||
</XMLDB>
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
19
delete.php
19
delete.php
@@ -19,20 +19,21 @@
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use auth_outage\outagedb;
|
||||
use auth_outage\outagelib;
|
||||
use auth_outage\form\outage\delete;
|
||||
use auth_outage\local\outagedb;
|
||||
use auth_outage\local\outagelib;
|
||||
|
||||
require_once('../../config.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
require_once($CFG->libdir . '/formslib.php');
|
||||
require_once(__DIR__.'/../../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->libdir.'/formslib.php');
|
||||
|
||||
$renderer = outagelib::pagesetup();
|
||||
$renderer = outagelib::page_setup();
|
||||
|
||||
$mform = new \auth_outage\forms\outage\delete();
|
||||
$mform = new delete();
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect('/auth/outage/manage.php');
|
||||
} else if ($fromform = $mform->get_data()) {
|
||||
@@ -43,7 +44,7 @@ if ($mform->is_cancelled()) {
|
||||
$id = required_param('id', PARAM_INT);
|
||||
$outage = outagedb::get_by_id($id);
|
||||
if ($outage == null) {
|
||||
throw new invalid_parameter_exception('Outage #' . $id . ' not found.');
|
||||
throw new invalid_parameter_exception('Outage #'.$id.' not found.');
|
||||
}
|
||||
|
||||
$dataid = new stdClass();
|
||||
|
||||
21
edit.php
21
edit.php
@@ -19,32 +19,33 @@
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use auth_outage\outagedb;
|
||||
use auth_outage\outagelib;
|
||||
use auth_outage\form\outage\edit;
|
||||
use auth_outage\local\outagedb;
|
||||
use auth_outage\local\outagelib;
|
||||
|
||||
require_once('../../config.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
require_once($CFG->libdir . '/formslib.php');
|
||||
require_once(__DIR__.'/../../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->libdir.'/formslib.php');
|
||||
|
||||
$renderer = outagelib::pagesetup();
|
||||
$renderer = outagelib::page_setup();
|
||||
|
||||
$mform = new \auth_outage\forms\outage\edit();
|
||||
$mform = new edit();
|
||||
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect('/auth/outage/manage.php');
|
||||
} else if ($outage = $mform->get_data()) {
|
||||
$id = outagedb::save($outage);
|
||||
redirect('/auth/outage/manage.php#auth_outage_id_' . $id);
|
||||
redirect('/auth/outage/manage.php#auth_outage_id_'.$id);
|
||||
}
|
||||
|
||||
$id = required_param('id', PARAM_INT);
|
||||
$outage = outagedb::get_by_id($id);
|
||||
if ($outage == null) {
|
||||
throw new invalid_parameter_exception('Outage #' . $id . ' not found.');
|
||||
throw new invalid_parameter_exception('Outage #'.$id.' not found.');
|
||||
}
|
||||
$mform->set_data($outage);
|
||||
|
||||
|
||||
19
finish.php
19
finish.php
@@ -19,20 +19,21 @@
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use auth_outage\outagedb;
|
||||
use auth_outage\outagelib;
|
||||
use auth_outage\form\outage\finish;
|
||||
use auth_outage\local\outagedb;
|
||||
use auth_outage\local\outagelib;
|
||||
|
||||
require_once('../../config.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
require_once($CFG->libdir . '/formslib.php');
|
||||
require_once(__DIR__.'/../../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->libdir.'/formslib.php');
|
||||
|
||||
$renderer = outagelib::pagesetup();
|
||||
$renderer = outagelib::page_setup();
|
||||
|
||||
$mform = new \auth_outage\forms\outage\finish();
|
||||
$mform = new finish();
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect('/auth/outage/manage.php');
|
||||
} else if ($fromform = $mform->get_data()) {
|
||||
@@ -43,7 +44,7 @@ if ($mform->is_cancelled()) {
|
||||
$id = required_param('id', PARAM_INT);
|
||||
$outage = outagedb::get_by_id($id);
|
||||
if ($outage == null) {
|
||||
throw new invalid_parameter_exception('Outage #' . $id . ' not found.');
|
||||
throw new invalid_parameter_exception('Outage #'.$id.' not found.');
|
||||
}
|
||||
|
||||
$dataid = new stdClass();
|
||||
|
||||
8
info.php
8
info.php
@@ -19,13 +19,13 @@
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use auth_outage\infopage_controller;
|
||||
use auth_outage\local\controllers\infopage;
|
||||
|
||||
require_once('../../config.php');
|
||||
require_once(__DIR__.'/../../config.php');
|
||||
|
||||
$info = new infopage_controller();
|
||||
$info = new infopage();
|
||||
$info->output();
|
||||
|
||||
6
lib.php
6
lib.php
@@ -19,7 +19,7 @@
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
@@ -27,9 +27,9 @@ defined('MOODLE_INTERNAL') || die;
|
||||
// FIXME hook not installing in courses/index.php page as guest.
|
||||
|
||||
function auth_outage_extend_navigation_user() {
|
||||
\auth_outage\outagelib::inject();
|
||||
\auth_outage\local\outagelib::inject();
|
||||
}
|
||||
|
||||
function auth_outage_extend_navigation_frontpage() {
|
||||
\auth_outage\outagelib::inject();
|
||||
\auth_outage\local\outagelib::inject();
|
||||
}
|
||||
|
||||
12
manage.php
12
manage.php
@@ -19,17 +19,17 @@
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use auth_outage\outagedb;
|
||||
use auth_outage\outagelib;
|
||||
use auth_outage\local\outagedb;
|
||||
use auth_outage\local\outagelib;
|
||||
|
||||
require_once('../../config.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
require_once(__DIR__.'/../../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
$renderer = outagelib::pagesetup();
|
||||
$renderer = outagelib::page_setup();
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
|
||||
23
new.php
23
new.php
@@ -19,26 +19,27 @@
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use auth_outage\models\outage;
|
||||
use auth_outage\outagedb;
|
||||
use auth_outage\outagelib;
|
||||
use auth_outage\form\outage\edit;
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\local\outagedb;
|
||||
use auth_outage\local\outagelib;
|
||||
|
||||
require_once('../../config.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
require_once($CFG->libdir . '/formslib.php');
|
||||
require_once(__DIR__.'/../../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->libdir.'/formslib.php');
|
||||
|
||||
outagelib::pagesetup();
|
||||
outagelib::page_setup();
|
||||
|
||||
$mform = new \auth_outage\forms\outage\edit();
|
||||
$mform = new edit();
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect('/auth/outage/manage.php');
|
||||
} else if ($outage = $mform->get_data()) {
|
||||
$id = outagedb::save($outage);
|
||||
redirect('/auth/outage/manage.php#auth_outage_id_' . $id);
|
||||
redirect('/auth/outage/manage.php#auth_outage_id_'.$id);
|
||||
}
|
||||
|
||||
$config = outagelib::get_config();
|
||||
@@ -47,7 +48,7 @@ $defaults = new outage([
|
||||
'stoptime' => time() + ($config->default_duration * 60),
|
||||
'warntime' => time() - ($config->warning_duration * 60),
|
||||
'title' => $config->warning_title,
|
||||
'description' => $config->warning_description
|
||||
'description' => $config->warning_description,
|
||||
]);
|
||||
$mform->set_data($defaults);
|
||||
|
||||
|
||||
153
renderer.php
153
renderer.php
@@ -14,19 +14,18 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use auth_outage\models\outage;
|
||||
use auth_outage\tables\manage\planned;
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\local\output\manage\history_table;
|
||||
use auth_outage\local\output\manage\planned_table;
|
||||
|
||||
if (!defined('MOODLE_INTERNAL')) {
|
||||
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
|
||||
}
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* auth_outage auth_outage_renderer
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class auth_outage_renderer extends plugin_renderer_base {
|
||||
@@ -37,7 +36,7 @@ class auth_outage_renderer extends plugin_renderer_base {
|
||||
*/
|
||||
public function rendersubtitle($subtitlekey) {
|
||||
if (!is_string($subtitlekey)) {
|
||||
throw new InvalidArgumentException('$subtitle is not a string.');
|
||||
throw new coding_exception('$subtitlekeym is not a string.', $subtitlekey);
|
||||
}
|
||||
return html_writer::tag('h2', get_string($subtitlekey, 'auth_outage'));
|
||||
}
|
||||
@@ -48,9 +47,9 @@ class auth_outage_renderer extends plugin_renderer_base {
|
||||
* @return string HTML for the page.
|
||||
*/
|
||||
public function renderdeleteconfirmation(outage $outage) {
|
||||
return $this->rendersubtitle('outagedelete')
|
||||
. html_writer::tag('p', get_string('outagedeletewarning', 'auth_outage'))
|
||||
. $this->renderoutage($outage, false);
|
||||
return $this->rendersubtitle('outagedelete').
|
||||
html_writer::tag('p', get_string('outagedeletewarning', 'auth_outage')).
|
||||
$this->renderoutage($outage, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,15 +58,15 @@ class auth_outage_renderer extends plugin_renderer_base {
|
||||
* @return string HTML for the page.
|
||||
*/
|
||||
public function renderfinishconfirmation(outage $outage) {
|
||||
return $this->rendersubtitle('outagefinish')
|
||||
. html_writer::tag('p', get_string('outagefinishwarning', 'auth_outage'))
|
||||
. $this->renderoutage($outage, false);
|
||||
return $this->rendersubtitle('outagefinish').
|
||||
html_writer::tag('p', get_string('outagefinishwarning', 'auth_outage')).
|
||||
$this->renderoutage($outage, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the HTML data listing all given outages.
|
||||
* @param array $future Outages to list as planned.
|
||||
* @param array $past Outages to list as history.
|
||||
* @param outage[] $future Outages to list as planned.
|
||||
* @param outage[] $past Outages to list as history.
|
||||
*/
|
||||
public function renderoutagelist(array $future, array $past) {
|
||||
global $OUTPUT;
|
||||
@@ -79,7 +78,7 @@ class auth_outage_renderer extends plugin_renderer_base {
|
||||
echo html_writer::tag('p',
|
||||
html_writer::link(
|
||||
$url,
|
||||
$img . ' ' . get_string('outagecreate', 'auth_outage'),
|
||||
$img.' '.get_string('outagecreate', 'auth_outage'),
|
||||
['title' => get_string('delete')]
|
||||
)
|
||||
);
|
||||
@@ -88,7 +87,7 @@ class auth_outage_renderer extends plugin_renderer_base {
|
||||
if (empty($future)) {
|
||||
echo html_writer::tag('p', html_writer::tag('small', get_string('notfound', 'auth_outage')));
|
||||
} else {
|
||||
$table = new planned();
|
||||
$table = new planned_table();
|
||||
$table->set_data($future);
|
||||
$table->finish_output();
|
||||
}
|
||||
@@ -97,12 +96,45 @@ class auth_outage_renderer extends plugin_renderer_base {
|
||||
if (empty($past)) {
|
||||
echo html_writer::tag('p', html_writer::tag('small', get_string('notfound', 'auth_outage')));
|
||||
} else {
|
||||
$table = new \auth_outage\tables\manage\history();
|
||||
$table = new history_table();
|
||||
$table->set_data($past);
|
||||
$table->finish_output();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the warning bar.
|
||||
* @param outage $outage The outage to show in the warning bar.
|
||||
* @param int|null $time Timestamp to send to the outage bar in order to render the outage. Null for current time.
|
||||
* @return string HTML of the warning bar.
|
||||
* @SuppressWarnings("unused") because $countdown is used inside require()
|
||||
*/
|
||||
public function renderoutagebar(outage $outage, $time = null) {
|
||||
global $CFG;
|
||||
|
||||
if (is_null($time)) {
|
||||
$time = time();
|
||||
}
|
||||
if (!is_int($time) || ($time <= 0)) {
|
||||
throw new coding_exception('$time is not an positive int or null.', $time);
|
||||
}
|
||||
|
||||
$start = userdate($outage->starttime, get_string('datetimeformat', 'auth_outage'));
|
||||
$stop = userdate($outage->stoptime, get_string('datetimeformat', 'auth_outage'));
|
||||
|
||||
$countdown = get_string(
|
||||
$outage->is_ongoing($time) ? 'messageoutageongoing' : 'messageoutagewarning',
|
||||
'auth_outage',
|
||||
['start' => $start, 'stop' => $stop]
|
||||
);
|
||||
|
||||
ob_start();
|
||||
require($CFG->dirroot.'/auth/outage/views/warningbar.php');
|
||||
$html = ob_get_contents();
|
||||
ob_end_clean();
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the HTML for displaying and outage information.
|
||||
* @param outage $outage Outage to display.
|
||||
@@ -118,7 +150,7 @@ class auth_outage_renderer extends plugin_renderer_base {
|
||||
$created = core_user::get_user($outage->createdby, 'firstname,lastname', MUST_EXIST);
|
||||
$created = html_writer::link(
|
||||
new moodle_url('/user/profile.php', ['id' => $outage->createdby]),
|
||||
trim($created->firstname . ' ' . $created->lastname)
|
||||
trim($created->firstname.' '.$created->lastname)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -128,7 +160,7 @@ class auth_outage_renderer extends plugin_renderer_base {
|
||||
$modified = core_user::get_user($outage->modifiedby, 'firstname,lastname', MUST_EXIST);
|
||||
$modified = html_writer::link(
|
||||
new moodle_url('/user/profile.php', ['id' => $outage->modifiedby]),
|
||||
trim($modified->firstname . ' ' . $modified->lastname)
|
||||
trim($modified->firstname.' '.$modified->lastname)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -155,66 +187,33 @@ class auth_outage_renderer extends plugin_renderer_base {
|
||||
|
||||
return html_writer::div(
|
||||
html_writer::tag('blockquote',
|
||||
html_writer::div(html_writer::tag('b', $outage->get_title(), ['data-id' => $outage->id]))
|
||||
. html_writer::div(html_writer::tag('i', $outage->get_description()))
|
||||
. html_writer::div(
|
||||
html_writer::tag('b', get_string('tableheaderwarnbefore', 'auth_outage') . ': ')
|
||||
. format_time($outage->get_warning_duration())
|
||||
)
|
||||
. html_writer::div(
|
||||
html_writer::tag('b', get_string('tableheaderstarttime', 'auth_outage') . ': ')
|
||||
. userdate($outage->starttime, get_string('datetimeformat', 'auth_outage'))
|
||||
)
|
||||
. html_writer::div(
|
||||
html_writer::tag('b', get_string('tableheaderdurationplanned', 'auth_outage') . ': ')
|
||||
. format_time($outage->get_duration_planned())
|
||||
)
|
||||
. html_writer::div(
|
||||
html_writer::tag('b', get_string('tableheaderdurationactual', 'auth_outage') . ': ')
|
||||
. $finished
|
||||
)
|
||||
. html_writer::div(
|
||||
html_writer::div(html_writer::tag('b', $outage->get_title(), ['data-id' => $outage->id])).
|
||||
html_writer::div(html_writer::tag('i', $outage->get_description())).
|
||||
html_writer::div(
|
||||
html_writer::tag('b', get_string('tableheaderwarnbefore', 'auth_outage').': ').
|
||||
format_time($outage->get_warning_duration())
|
||||
).
|
||||
html_writer::div(
|
||||
html_writer::tag('b', get_string('tableheaderstarttime', 'auth_outage').': ').
|
||||
userdate($outage->starttime, get_string('datetimeformat', 'auth_outage'))
|
||||
).
|
||||
html_writer::div(
|
||||
html_writer::tag('b', get_string('tableheaderdurationplanned', 'auth_outage').': ').
|
||||
format_time($outage->get_duration_planned())
|
||||
).
|
||||
html_writer::div(
|
||||
html_writer::tag('b', get_string('tableheaderdurationactual', 'auth_outage').': ').
|
||||
$finished
|
||||
).
|
||||
html_writer::div(
|
||||
html_writer::tag('small',
|
||||
'Created by ' . $created
|
||||
. ', modified by ' . $modified . ' on '
|
||||
. userdate($outage->lastmodified, get_string('datetimeformat', 'auth_outage'))
|
||||
'Created by '.$created.
|
||||
', modified by '.$modified.' on '.
|
||||
userdate($outage->lastmodified, get_string('datetimeformat', 'auth_outage'))
|
||||
)
|
||||
)
|
||||
. ($buttons ? html_writer::div($linkedit . $linkdelete) : '')
|
||||
).
|
||||
($buttons ? html_writer::div($linkedit.$linkdelete) : '')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the warning bar.
|
||||
* @param outage $outage The outage to show in the warning bar.
|
||||
* @param int|null $time Timestamp to send to the outage bar in order to render the outage. Null for current time.
|
||||
* @return string HTML of the warning bar.
|
||||
* @SuppressWarnings("unused") because $countdown is used inside require(...)
|
||||
*/
|
||||
public function renderoutagebar(outage $outage, $time = null) {
|
||||
global $CFG;
|
||||
|
||||
if (is_null($time)) {
|
||||
$time = time();
|
||||
}
|
||||
if (!is_int($time) || ($time <= 0)) {
|
||||
throw new InvalidArgumentException('$time is not an positive int or null.');
|
||||
}
|
||||
|
||||
$start = userdate($outage->starttime, get_string('datetimeformat', 'auth_outage'));
|
||||
$stop = userdate($outage->stoptime, get_string('datetimeformat', 'auth_outage'));
|
||||
|
||||
$countdown = get_string(
|
||||
$outage->is_ongoing($time) ? 'messageoutageongoing' : 'messageoutagewarning',
|
||||
'auth_outage',
|
||||
['start' => $start, 'stop' => $stop]
|
||||
);
|
||||
|
||||
ob_start();
|
||||
require($CFG->dirroot . '/auth/outage/views/warningbar.php');
|
||||
$html = ob_get_contents();
|
||||
ob_end_clean();
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,10 @@
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
use auth_outage\outagelib;
|
||||
use auth_outage\local\outagelib;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
@@ -76,7 +76,7 @@ if ($hassiteconfig && is_enabled_auth('outage')) {
|
||||
new admin_externalpage(
|
||||
'auth_outage_manage',
|
||||
get_string('menumanage', 'auth_outage'),
|
||||
new moodle_url($CFG->wwwroot . '/auth/outage/manage.php')
|
||||
new moodle_url($CFG->wwwroot.'/auth/outage/manage.php')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -14,32 +14,32 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use auth_outage\cli\cliexception;
|
||||
use auth_outage\cli\create;
|
||||
use auth_outage\local\cli\cli_exception;
|
||||
use auth_outage\local\cli\create;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once('cli_testcase.php');
|
||||
require_once(__DIR__.'/cli_testcase.php');
|
||||
|
||||
/**
|
||||
* Tests performed on CLI base and exception class.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \auth_outage\cli\clibase
|
||||
* @covers \auth_outage\cli\cliexception
|
||||
* @covers \auth_outage\local\cli\clibase
|
||||
* @covers \auth_outage\local\cli\cli_exception
|
||||
* @SuppressWarnings("public")
|
||||
*/
|
||||
class cli_test extends cli_testcase {
|
||||
public function test_invalidargumentparam() {
|
||||
$this->set_parameters(['--aninvalidparameter']);
|
||||
$this->setExpectedException(cliexception::class);
|
||||
$this->setExpectedException(cli_exception::class);
|
||||
new create();
|
||||
}
|
||||
|
||||
public function test_invalidargumentgiven() {
|
||||
$this->setExpectedException(cliexception::class);
|
||||
$this->setExpectedException(cli_exception::class);
|
||||
new create(['anotherinvalidparameter']);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ class cli_test extends cli_testcase {
|
||||
|
||||
public function test_setreferencetime_invalid() {
|
||||
$cli = new create(['start' => 0]);
|
||||
$this->setExpectedException(InvalidArgumentException::class);
|
||||
$this->setExpectedException(coding_exception::class);
|
||||
$cli->set_referencetime(-1);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ class cli_test extends cli_testcase {
|
||||
}
|
||||
|
||||
public function test_exception() {
|
||||
self::setExpectedException(cliexception::class, '*ERROR* An CLI exception.', 5);
|
||||
throw new cliexception('An CLI exception.', 5);
|
||||
self::setExpectedException(cli_exception::class, '*ERROR* An CLI exception.', 5);
|
||||
throw new cli_exception('An CLI exception.', 5);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use auth_outage\cli\clibase;
|
||||
use auth_outage\local\cli\clibase;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -23,7 +23,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class cli_testcase extends advanced_testcase {
|
||||
@@ -35,7 +35,7 @@ class cli_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Mocks the command line parameters.
|
||||
* @param array $options Options to use as parameters.
|
||||
* @param string[] $options Options to use as parameters.
|
||||
*/
|
||||
protected function set_parameters(array $options) {
|
||||
array_unshift($options, 'cli.php');
|
||||
|
||||
@@ -14,27 +14,27 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use auth_outage\cli\cliexception;
|
||||
use auth_outage\cli\create;
|
||||
use auth_outage\models\outage;
|
||||
use auth_outage\outagedb;
|
||||
use auth_outage\local\cli\cli_exception;
|
||||
use auth_outage\local\cli\create;
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\local\outagedb;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once('cli_testcase.php');
|
||||
require_once(__DIR__.'/cli_testcase.php');
|
||||
|
||||
/**
|
||||
* Tests performed on CLI create class.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @SuppressWarnings("public") Allow this test to have as many tests as necessary.
|
||||
*/
|
||||
class create_test extends cli_testcase {
|
||||
public function test_noarguments() {
|
||||
$cli = new create();
|
||||
$this->setExpectedException(cliexception::class);
|
||||
$this->setExpectedException(cli_exception::class);
|
||||
$this->execute($cli);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ class create_test extends cli_testcase {
|
||||
'title' => 'Default Title',
|
||||
'description' => 'Default Description',
|
||||
]);
|
||||
$this->setExpectedException(cliexception::class);
|
||||
$this->setExpectedException(cli_exception::class);
|
||||
$this->execute($cli);
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ class create_test extends cli_testcase {
|
||||
'title' => 'Default Title',
|
||||
'description' => 'Default Description',
|
||||
]);
|
||||
$this->setExpectedException(cliexception::class);
|
||||
$this->setExpectedException(cli_exception::class);
|
||||
$this->execute($cli);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ class create_test extends cli_testcase {
|
||||
'title' => 'Default Title',
|
||||
'description' => 'Default Description',
|
||||
]);
|
||||
$this->setExpectedException(cliexception::class);
|
||||
$this->setExpectedException(cli_exception::class);
|
||||
$this->execute($cli);
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ class create_test extends cli_testcase {
|
||||
'title' => 'Default Title',
|
||||
'description' => 'Default Description',
|
||||
]);
|
||||
$this->setExpectedException(cliexception::class);
|
||||
$this->setExpectedException(cli_exception::class);
|
||||
$this->execute($cli);
|
||||
}
|
||||
|
||||
@@ -101,12 +101,12 @@ class create_test extends cli_testcase {
|
||||
public function test_options() {
|
||||
$cli = new create();
|
||||
|
||||
$options = $cli->generateoptions();
|
||||
$options = $cli->generate_options();
|
||||
foreach (array_keys($options) as $k) {
|
||||
self::assertTrue(is_string($k));
|
||||
}
|
||||
|
||||
$shorts = $cli->generateshortcuts();
|
||||
$shorts = $cli->generate_shortcuts();
|
||||
foreach ($shorts as $s) {
|
||||
self::assertArrayHasKey($s, $options);
|
||||
}
|
||||
@@ -209,7 +209,7 @@ class create_test extends cli_testcase {
|
||||
$this->set_parameters([
|
||||
'--onlyid',
|
||||
'--start=60',
|
||||
'--clone=' . $id,
|
||||
'--clone='.$id,
|
||||
]);
|
||||
$cli = new create();
|
||||
$cli->set_referencetime($now);
|
||||
@@ -224,7 +224,7 @@ class create_test extends cli_testcase {
|
||||
}
|
||||
|
||||
public function test_create_withclone_invalid() {
|
||||
$this->setExpectedException(cliexception::class);
|
||||
$this->setExpectedException(cli_exception::class);
|
||||
$this->set_parameters([
|
||||
'--start=60',
|
||||
'--clone=-1',
|
||||
|
||||
@@ -14,22 +14,22 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use auth_outage\cli\cliexception;
|
||||
use auth_outage\cli\finish;
|
||||
use auth_outage\models\outage;
|
||||
use auth_outage\outagedb;
|
||||
use auth_outage\local\cli\cli_exception;
|
||||
use auth_outage\local\cli\finish;
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\local\outagedb;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once('cli_testcase.php');
|
||||
require_once(__DIR__.'/cli_testcase.php');
|
||||
|
||||
/**
|
||||
* Tests performed on CLI finish class.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \auth_outage\cli\finish
|
||||
* @covers \auth_outage\local\cli\finish
|
||||
*/
|
||||
class finish_test extends cli_testcase {
|
||||
public function test_constructor() {
|
||||
@@ -40,12 +40,12 @@ class finish_test extends cli_testcase {
|
||||
public function test_options() {
|
||||
$cli = new finish();
|
||||
|
||||
$options = $cli->generateoptions();
|
||||
$options = $cli->generate_options();
|
||||
foreach (array_keys($options) as $k) {
|
||||
self::assertTrue(is_string($k));
|
||||
}
|
||||
|
||||
$shorts = $cli->generateshortcuts();
|
||||
$shorts = $cli->generate_shortcuts();
|
||||
foreach ($shorts as $s) {
|
||||
self::assertArrayHasKey($s, $options);
|
||||
}
|
||||
@@ -61,7 +61,7 @@ class finish_test extends cli_testcase {
|
||||
|
||||
public function test_noarguments() {
|
||||
$cli = new finish();
|
||||
$this->setExpectedException(cliexception::class);
|
||||
$this->setExpectedException(cli_exception::class);
|
||||
$this->execute($cli);
|
||||
}
|
||||
|
||||
@@ -75,10 +75,10 @@ class finish_test extends cli_testcase {
|
||||
'title' => 'Title',
|
||||
'description' => 'Description',
|
||||
]));
|
||||
$this->set_parameters(['-id=' . $id]);
|
||||
$this->set_parameters(['-id='.$id]);
|
||||
$cli = new finish();
|
||||
$cli->set_referencetime($now);
|
||||
$this->setExpectedException(cliexception::class);
|
||||
$this->setExpectedException(cli_exception::class);
|
||||
$this->execute($cli);
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ class finish_test extends cli_testcase {
|
||||
'title' => 'Title',
|
||||
'description' => 'Description',
|
||||
]));
|
||||
$this->set_parameters(['-id=' . $id]);
|
||||
$this->set_parameters(['-id='.$id]);
|
||||
$cli = new finish();
|
||||
$cli->set_referencetime($now);
|
||||
$this->execute($cli);
|
||||
@@ -102,7 +102,7 @@ class finish_test extends cli_testcase {
|
||||
$this->setAdminUser();
|
||||
$this->set_parameters(['-a']);
|
||||
$cli = new finish();
|
||||
$this->setExpectedException(cliexception::class);
|
||||
$this->setExpectedException(cli_exception::class);
|
||||
$this->execute($cli);
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ class finish_test extends cli_testcase {
|
||||
$this->setAdminUser();
|
||||
$this->set_parameters(['-id=theid']);
|
||||
$cli = new finish();
|
||||
$this->setExpectedException(cliexception::class);
|
||||
$this->setExpectedException(cli_exception::class);
|
||||
$this->execute($cli);
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ class finish_test extends cli_testcase {
|
||||
$this->setAdminUser();
|
||||
$this->set_parameters(['-id=99999']);
|
||||
$cli = new finish();
|
||||
$this->setExpectedException(cliexception::class);
|
||||
$this->setExpectedException(cli_exception::class);
|
||||
$this->execute($cli);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,22 +14,22 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use auth_outage\cli\cliexception;
|
||||
use auth_outage\cli\waitforit;
|
||||
use auth_outage\models\outage;
|
||||
use auth_outage\outagedb;
|
||||
use auth_outage\local\cli\cli_exception;
|
||||
use auth_outage\local\cli\waitforit;
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\local\outagedb;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once('cli_testcase.php');
|
||||
require_once(__DIR__.'/cli_testcase.php');
|
||||
|
||||
/**
|
||||
* Tests performed on CLI waitforit class.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \auth_outage\cli\waitforit
|
||||
* @covers \auth_outage\local\cli\waitforit
|
||||
* @SuppressWarnings("public")
|
||||
*/
|
||||
class waitforit_test extends cli_testcase {
|
||||
@@ -40,7 +40,7 @@ class waitforit_test extends cli_testcase {
|
||||
|
||||
public function test_generateoptions() {
|
||||
$cli = new waitforit();
|
||||
$options = $cli->generateoptions();
|
||||
$options = $cli->generate_options();
|
||||
foreach (array_keys($options) as $k) {
|
||||
self::assertTrue(is_string($k));
|
||||
}
|
||||
@@ -48,8 +48,8 @@ class waitforit_test extends cli_testcase {
|
||||
|
||||
public function test_generateshortcuts() {
|
||||
$cli = new waitforit();
|
||||
$options = $cli->generateoptions();
|
||||
$shorts = $cli->generateshortcuts();
|
||||
$options = $cli->generate_options();
|
||||
$shorts = $cli->generate_shortcuts();
|
||||
foreach ($shorts as $s) {
|
||||
self::assertArrayHasKey($s, $options);
|
||||
}
|
||||
@@ -66,21 +66,21 @@ class waitforit_test extends cli_testcase {
|
||||
public function test_bothparams() {
|
||||
$this->set_parameters(['--outageid=1', '--active']);
|
||||
$cli = new waitforit();
|
||||
$this->setExpectedException(cliexception::class);
|
||||
$this->setExpectedException(cli_exception::class);
|
||||
$cli->execute();
|
||||
}
|
||||
|
||||
public function test_invalidoutageid() {
|
||||
$this->set_parameters(['-id=-1']);
|
||||
$cli = new waitforit();
|
||||
$this->setExpectedException(cliexception::class);
|
||||
$this->setExpectedException(cli_exception::class);
|
||||
$this->execute($cli);
|
||||
}
|
||||
|
||||
public function test_outagenotfound() {
|
||||
$this->set_parameters(['-a']);
|
||||
$cli = new waitforit();
|
||||
$this->setExpectedException(cliexception::class);
|
||||
$this->setExpectedException(cli_exception::class);
|
||||
$this->execute($cli);
|
||||
}
|
||||
|
||||
@@ -94,10 +94,10 @@ class waitforit_test extends cli_testcase {
|
||||
'title' => 'Title',
|
||||
'description' => 'Description',
|
||||
]));
|
||||
$this->set_parameters(['-id=' . $id]);
|
||||
$this->set_parameters(['-id='.$id]);
|
||||
$cli = new waitforit();
|
||||
$cli->set_referencetime($now);
|
||||
$this->setExpectedException(cliexception::class);
|
||||
$this->setExpectedException(cli_exception::class);
|
||||
$this->execute($cli);
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ class waitforit_test extends cli_testcase {
|
||||
// Pretend it is time to start, but it should get an error instead.
|
||||
return $outage->starttime;
|
||||
});
|
||||
$this->setExpectedException(cliexception::class);
|
||||
$this->setExpectedException(cli_exception::class);
|
||||
$this->execute($cli);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use auth_outage\models\outage;
|
||||
use auth_outage\outagedb;
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\local\outagedb;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -61,7 +61,7 @@ class events_test extends advanced_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $ids
|
||||
* @param int[] $ids
|
||||
* @depends test_save
|
||||
*/
|
||||
public function test_update($ids) {
|
||||
@@ -90,7 +90,7 @@ class events_test extends advanced_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $ids
|
||||
* @param int[] $ids
|
||||
* @depends test_update
|
||||
*/
|
||||
public function test_delete($ids) {
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use auth_outage\infopage_controller;
|
||||
use auth_outage\models\outage;
|
||||
use auth_outage\local\controllers\infopage;
|
||||
use auth_outage\local\outage;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \auth_outage\infopage_controller
|
||||
*/
|
||||
@@ -34,7 +34,7 @@ class infopagecontroller_test extends advanced_testcase {
|
||||
if (is_file($this->get_file())) {
|
||||
unlink($this->get_file());
|
||||
} else {
|
||||
self::fail('Invalid temp file: ' . $this->get_file());
|
||||
self::fail('Invalid temp file: '.$this->get_file());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ class infopagecontroller_test extends advanced_testcase {
|
||||
* @return string Default file.
|
||||
*/
|
||||
public function get_file() {
|
||||
return sys_get_temp_dir() . '/phpunit_authoutage.tmp';
|
||||
return sys_get_temp_dir().'/phpunit_authoutage.tmp';
|
||||
}
|
||||
|
||||
public function test_staticpage_output() {
|
||||
@@ -61,13 +61,13 @@ class infopagecontroller_test extends advanced_testcase {
|
||||
'title' => 'Outage Title at {{start}}',
|
||||
'description' => 'This is an <b>important</b> outage, starting at {{start}}.',
|
||||
]);
|
||||
$info = new infopage_controller(['static' => true, 'outage' => $outage]);
|
||||
$info = new infopage(['static' => true, 'outage' => $outage]);
|
||||
$html = $info->get_output();
|
||||
self::assertContains('<!DOCTYPE html>', $html);
|
||||
self::assertContains('</html>', $html);
|
||||
self::assertContains($outage->get_title(), $html);
|
||||
self::assertContains($outage->get_description(), $html);
|
||||
self::assertSame($outage->id, infopage_controller::find_outageid_from_infopage($html));
|
||||
self::assertSame($outage->id, infopage::find_outageid_from_infopage($html));
|
||||
}
|
||||
|
||||
public function test_staticpage_file() {
|
||||
@@ -80,17 +80,17 @@ class infopagecontroller_test extends advanced_testcase {
|
||||
'title' => 'Title',
|
||||
'description' => 'Description',
|
||||
]);
|
||||
infopage_controller::save_static_page($outage, $this->get_file());
|
||||
infopage::save_static_page($outage, $this->get_file());
|
||||
self::assertFileExists($this->get_file());
|
||||
|
||||
$id = infopage_controller::find_outageid_from_infopage(file_get_contents($this->get_file()));
|
||||
$id = infopage::find_outageid_from_infopage(file_get_contents($this->get_file()));
|
||||
self::assertSame($outage->id, $id);
|
||||
|
||||
unlink($this->get_file());
|
||||
}
|
||||
|
||||
public function test_getdefaulttemplatefile() {
|
||||
$file = infopage_controller::get_defaulttemplatefile();
|
||||
$file = infopage::get_defaulttemplatefile();
|
||||
self::assertTrue(is_string($file));
|
||||
self::assertContains('template', $file);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use auth_outage\models\outage;
|
||||
use auth_outage\local\outage;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -23,9 +23,9 @@ defined('MOODLE_INTERNAL') || die();
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \auth_outage\models\outage
|
||||
* @covers \auth_outage\local\outage
|
||||
*/
|
||||
class outage_test extends basic_testcase {
|
||||
public function test_constructor() {
|
||||
@@ -47,7 +47,7 @@ class outage_test extends basic_testcase {
|
||||
'stoptime' => $now - (2 * 60 * 60),
|
||||
'warntime' => $now - (2 * 60 * 60),
|
||||
'title' => '',
|
||||
'description' => ''
|
||||
'description' => '',
|
||||
]);
|
||||
self::assertFalse($outage->is_ongoing($now));
|
||||
|
||||
@@ -57,7 +57,7 @@ class outage_test extends basic_testcase {
|
||||
'stoptime' => $now + (1 * 60 * 60),
|
||||
'warntime' => $now - (2 * 60 * 60),
|
||||
'title' => '',
|
||||
'description' => ''
|
||||
'description' => '',
|
||||
]);
|
||||
self::assertTrue($outage->is_ongoing($now));
|
||||
|
||||
@@ -67,7 +67,7 @@ class outage_test extends basic_testcase {
|
||||
'stoptime' => $now + (2 * 60 * 60),
|
||||
'warntime' => $now - (2 * 60 * 60),
|
||||
'title' => '',
|
||||
'description' => ''
|
||||
'description' => '',
|
||||
]);
|
||||
self::assertFalse($outage->is_ongoing($now));
|
||||
}
|
||||
@@ -81,7 +81,7 @@ class outage_test extends basic_testcase {
|
||||
'stoptime' => $now - (2 * 60 * 60),
|
||||
'warntime' => $now - (2 * 60 * 60),
|
||||
'title' => '',
|
||||
'description' => ''
|
||||
'description' => '',
|
||||
]);
|
||||
self::assertFalse($outage->is_active($now));
|
||||
|
||||
@@ -91,7 +91,7 @@ class outage_test extends basic_testcase {
|
||||
'stoptime' => $now + (1 * 60 * 60),
|
||||
'warntime' => $now - (2 * 60 * 60),
|
||||
'title' => '',
|
||||
'description' => ''
|
||||
'description' => '',
|
||||
]);
|
||||
self::assertTrue($outage->is_active($now));
|
||||
|
||||
@@ -101,7 +101,7 @@ class outage_test extends basic_testcase {
|
||||
'stoptime' => $now + (2 * 60 * 60),
|
||||
'warntime' => $now - (2 * 60 * 60),
|
||||
'title' => '',
|
||||
'description' => ''
|
||||
'description' => '',
|
||||
]);
|
||||
self::assertTrue($outage->is_active($now));
|
||||
|
||||
@@ -111,7 +111,7 @@ class outage_test extends basic_testcase {
|
||||
'stoptime' => $now + (3 * 60 * 60),
|
||||
'warntime' => $now + (1 * 60 * 60),
|
||||
'title' => '',
|
||||
'description' => ''
|
||||
'description' => '',
|
||||
]);
|
||||
self::assertFalse($outage->is_active($now));
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use auth_outage\models\outage;
|
||||
use auth_outage\outagedb;
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\local\outagedb;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -24,22 +24,14 @@ defined('MOODLE_INTERNAL') || die();
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class outagedb_test extends advanced_testcase {
|
||||
/**
|
||||
* Ensure DB tests run as admin.
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->setAdminUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an array of ids in from the given outages array.
|
||||
* @param array $outages An array of outages.
|
||||
* @return array An array with the keys of the outages as values.
|
||||
* @param outage[] $outages An array of outages.
|
||||
* @return int[] An array with the keys of the outages as values.
|
||||
*/
|
||||
private static function createidarray(array $outages) {
|
||||
$ids = [];
|
||||
@@ -49,6 +41,36 @@ class outagedb_test extends advanced_testcase {
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to create an outage then save it to the database.
|
||||
*
|
||||
* @param int $now Timestamp for now, such as time().
|
||||
* @param int $warning In how many hours the warning starts. Can be negative.
|
||||
* @param int $start In how many hours this outage starts. Can be negative.
|
||||
* @param int $stop In how many hours this outage finishes. Can be negative.
|
||||
* @param string $title Title for the outage.
|
||||
* @param int|null $finished In how many hours this outage is marked as finished. Can be negative or null.
|
||||
* @return int Id the of created outage.
|
||||
*/
|
||||
private static function saveoutage($now, $warning, $start, $stop, $title, $finished = null) {
|
||||
return outagedb::save(new outage([
|
||||
'warntime' => $now + ($warning * 60 * 60),
|
||||
'starttime' => $now + ($start * 60 * 60),
|
||||
'stoptime' => $now + ($stop * 60 * 60),
|
||||
'finished' => is_null($finished) ? null : ($now + ($finished * 60 * 60)),
|
||||
'title' => $title,
|
||||
'description' => 'Test Outage Description.',
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure DB tests run as admin.
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->setAdminUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure we can save and update.
|
||||
*/
|
||||
@@ -150,7 +172,7 @@ class outagedb_test extends advanced_testcase {
|
||||
self::assertNotNull($inserted);
|
||||
// Check its data.
|
||||
foreach (['starttime', 'stoptime', 'warntime', 'title', 'description'] as $field) {
|
||||
self::assertSame($outage->$field, $inserted->$field, 'Field ' . $field . ' does not match.');
|
||||
self::assertSame($outage->$field, $inserted->$field, 'Field '.$field.' does not match.');
|
||||
}
|
||||
// Check generated data.
|
||||
self::assertGreaterThan(0, $inserted->id);
|
||||
@@ -158,11 +180,11 @@ class outagedb_test extends advanced_testcase {
|
||||
self::assertNotNull($inserted->createdby);
|
||||
self::assertNotNull($inserted->modifiedby);
|
||||
// Change it.
|
||||
$inserted->title = 'Title ID' . $id;
|
||||
$inserted->title = 'Title ID'.$id;
|
||||
outagedb::save($inserted);
|
||||
// Get it again and check data.
|
||||
$updated = outagedb::get_by_id($id);
|
||||
self::assertSame('Title ID' . $id, $updated->title);
|
||||
self::assertSame('Title ID'.$id, $updated->title);
|
||||
self::assertSame($inserted->description, $updated->description);
|
||||
// Delete it.
|
||||
outagedb::delete($id);
|
||||
@@ -295,28 +317,6 @@ class outagedb_test extends advanced_testcase {
|
||||
self::createidarray(outagedb::get_all_ended($now)), 'Wrong past data.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to create an outage then save it to the database.
|
||||
*
|
||||
* @param int $now Timestamp for now, such as time().
|
||||
* @param int $warning In how many hours the warning starts. Can be negative.
|
||||
* @param int $start In how many hours this outage starts. Can be negative.
|
||||
* @param int $stop In how many hours this outage finishes. Can be negative.
|
||||
* @param string $title Title for the outage.
|
||||
* @param int|null $finished In how many hours this outage is marked as finished. Can be negative or null.
|
||||
* @return int Id the of created outage.
|
||||
*/
|
||||
private static function saveoutage($now, $warning, $start, $stop, $title, $finished = null) {
|
||||
return outagedb::save(new outage([
|
||||
'warntime' => $now + ($warning * 60 * 60),
|
||||
'starttime' => $now + ($start * 60 * 60),
|
||||
'stoptime' => $now + ($stop * 60 * 60),
|
||||
'finished' => is_null($finished) ? null : ($now + ($finished * 60 * 60)),
|
||||
'title' => $title,
|
||||
'description' => 'Test Outage Description.'
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to create an outage for tests.
|
||||
*
|
||||
@@ -328,8 +328,8 @@ class outagedb_test extends advanced_testcase {
|
||||
'starttime' => $i * 100,
|
||||
'stoptime' => $i * 100 + 50,
|
||||
'warntime' => $i * 60,
|
||||
'title' => 'The Title ' . $i,
|
||||
'description' => 'A <b>description</b> in HTML.'
|
||||
'title' => 'The Title '.$i,
|
||||
'description' => 'A <b>description</b> in HTML.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
12
version.php
12
version.php
@@ -25,12 +25,10 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
if (!defined('MOODLE_INTERNAL')) {
|
||||
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
|
||||
}
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2016091500; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->release = $plugin->version; // Same as version
|
||||
$plugin->requires = 2014051200; // Requires Moodle 2.7 or later.
|
||||
$plugin->version = 2016091500; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->release = $plugin->version; // Same as version
|
||||
$plugin->requires = 2014051200; // Requires Moodle 2.7 or later.
|
||||
$plugin->component = "auth_outage";
|
||||
$plugin->maturity = MATURITY_ALPHA; // Not suitable for PRODUCTION environments yet!
|
||||
$plugin->maturity = MATURITY_ALPHA; // Not suitable for PRODUCTION environments yet!
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
@@ -28,11 +28,11 @@ defined('MOODLE_INTERNAL') || die();
|
||||
if ($this->has_admin_options()) {
|
||||
$adminlinks = [];
|
||||
foreach ([
|
||||
'startofwarning' => -$this->outage->get_warning_duration(),
|
||||
'15secondsbefore' => -15,
|
||||
'start' => 0,
|
||||
'endofoutage' => $this->outage->get_duration_planned(),
|
||||
] as $title => $delta) {
|
||||
'startofwarning' => -$this->outage->get_warning_duration(),
|
||||
'15secondsbefore' => -15,
|
||||
'start' => 0,
|
||||
'endofoutage' => $this->outage->get_duration_planned(),
|
||||
] as $title => $delta) {
|
||||
$adminlinks[] = html_writer::link(
|
||||
new moodle_url(
|
||||
'/auth/outage/info.php',
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
@@ -56,7 +56,7 @@ require($CFG->dirroot.'/auth/outage/views/warningbar.php');
|
||||
|
||||
<section>
|
||||
<h2><?php echo $this->outage->get_title(); ?></h2>
|
||||
<?php require('content.php'); ?>
|
||||
<?php require(__DIR__.'/content.php'); ?>
|
||||
</section>
|
||||
|
||||
<!-- <?php echo
|
||||
|
||||
@@ -19,11 +19,11 @@
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use auth_outage\outagelib;
|
||||
use auth_outage\local\outagelib;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -64,11 +64,11 @@ echo html_writer::tag('style', outagelib::get_config()->css);
|
||||
$text = html_writer::empty_tag('img', [
|
||||
'src' => $OUTPUT->pix_url('t/check'),
|
||||
'alt' => get_string('finish', 'auth_outage'),
|
||||
'class' => 'iconsmall'
|
||||
]) . ' ' . get_string('finish', 'auth_outage');
|
||||
'class' => 'iconsmall',
|
||||
]).' '.get_string('finish', 'auth_outage');
|
||||
$attr = [
|
||||
'title' => get_string('finish', 'auth_outage'),
|
||||
'class' => 'auth_outage_warningbar_box_finish'
|
||||
'class' => 'auth_outage_warningbar_box_finish',
|
||||
];
|
||||
echo html_writer::link($url, $text, $attr);
|
||||
}
|
||||
@@ -79,7 +79,7 @@ echo html_writer::tag('style', outagelib::get_config()->css);
|
||||
|
||||
<?php if (!$static && !$outage->is_ongoing($time)): ?>
|
||||
<script>
|
||||
<?php require($CFG->dirroot . '/auth/outage/views/warningbar.js'); ?>
|
||||
<?php require($CFG->dirroot.'/auth/outage/views/warningbar.js'); ?>
|
||||
auth_outage_countdown.init(
|
||||
<?php echo($outage->starttime - $time); ?>,
|
||||
<?php echo(is_siteadmin() ? 'true' : 'false'); ?>,
|
||||
|
||||
Reference in New Issue
Block a user