Added warnings in case plugin is not properly configured.

This commit is contained in:
Daniel Thee Roperto
2016-11-14 15:02:30 +11:00
parent 739c92e94e
commit 3360d357d4
10 changed files with 53 additions and 14 deletions

View File

@@ -74,9 +74,9 @@ class cli_exception extends Exception {
const ERROR_OUTAGE_CHANGED = 7;
/**
* The outage plugin is not enabled.
* The outage plugin is not properly configured.
*/
const ERROR_PLUGIN_DISABLED = 8;
const ERROR_PLUGIN_CONFIGURATION = 8;
/**
* Moodle maintenance mode is enabled.

View File

@@ -25,6 +25,7 @@
namespace auth_outage\local\cli;
use auth_outage\local\outagelib;
use coding_exception;
use core\session\manager;
@@ -58,8 +59,9 @@ abstract class clibase {
global $CFG;
require_once($CFG->libdir.'/clilib.php');
if (!is_enabled_auth('outage')) {
throw new cli_exception(get_string('cliplugindisabled', 'auth_outage'), cli_exception::ERROR_PLUGIN_DISABLED);
$warning = outagelib::generate_plugin_configuration_warning();
if ($warning) {
throw new cli_exception($warning, cli_exception::ERROR_PLUGIN_CONFIGURATION);
}
$this->become_admin_user();

View File

@@ -104,7 +104,7 @@ class outagelib {
// There is a previewing or active outage.
$CFG->additionalhtmltopofbody = renderer::get()->render_warningbar($active, $time, false, $preview).
$CFG->additionalhtmltopofbody;
$CFG->additionalhtmltopofbody;
} catch (Exception $e) {
debugging('Exception occured while injecting our code: '.$e->getMessage());
debugging($e->getTraceAsString(), DEBUG_DEVELOPER);
@@ -144,7 +144,7 @@ class outagelib {
'default_warning_duration' => (string)(60 * 60),
'default_title' => get_string('defaulttitlevalue', 'auth_outage'),
'default_description' => get_string('defaultdescriptionvalue', 'auth_outage'),
'remove_selectors' => '.usermenu',
'remove_selectors' => ".usermenu\n.logininfo\n.homelink",
];
}
@@ -290,4 +290,38 @@ EOT;
file_put_contents($file, $code);
}
}
/**
* Generates a warning message in case the plugin is not active and configured.
*
* @return string
*
* @internal stdClass $CFG
* @internal bootstrap_renderer $OUTPUT
*/
public static function generate_plugin_configuration_warning() {
global $CFG, $OUTPUT;
$message = [];
if (!isset($CFG->auth_outage_bootstrap_loaded) || !$CFG->auth_outage_bootstrap_loaded) {
$message[] = get_string('configurationwarning', 'auth_outage');
}
if (!is_enabled_auth('outage')) {
$message[] = get_string('configurationdisabled', 'auth_outage');
}
if (count($message) == 0) {
return '';
}
if (CLI_SCRIPT) {
$message = html_to_text(implode("; ", $message));
} else {
$message = $OUTPUT->notification(implode("<br />", $message), 'notifyfailure');
}
return $message;
}
}