mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-16 21:41:31 +02:00
Issue #47 - CLI will fail if outage plugin is not enabled.
This commit is contained in:
@@ -64,6 +64,11 @@ class cli_exception extends Exception {
|
||||
*/
|
||||
const ERROR_OUTAGE_CHANGED = 7;
|
||||
|
||||
/**
|
||||
* The outage plugin is not enabled.
|
||||
*/
|
||||
const ERROR_PLUGIN_DISABLED = 8;
|
||||
|
||||
/**
|
||||
* cliexception constructor.
|
||||
* @param string $message An explanation of the exception.
|
||||
|
||||
@@ -20,6 +20,7 @@ use coding_exception;
|
||||
use core\session\manager;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once($CFG->libdir.'/clilib.php');
|
||||
|
||||
/**
|
||||
* Outage CLI base class.
|
||||
@@ -47,7 +48,9 @@ abstract class clibase {
|
||||
*/
|
||||
public function __construct(array $options = null) {
|
||||
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);
|
||||
}
|
||||
|
||||
$this->become_admin_user();
|
||||
|
||||
|
||||
@@ -29,20 +29,19 @@ use auth_outage\local\outagelib;
|
||||
|
||||
define('CLI_SCRIPT', true);
|
||||
require_once(__DIR__.'/../../../config.php');
|
||||
|
||||
$cli = new create();
|
||||
|
||||
$config = outagelib::get_config();
|
||||
$cli->set_defaults([
|
||||
'help' => false,
|
||||
'warn' => (int)($config->default_warning_duration),
|
||||
'start' => null,
|
||||
'duration' => (int)($config->default_duration),
|
||||
'title' => $config->default_title,
|
||||
'description' => $config->default_description,
|
||||
]);
|
||||
require_once($CFG->libdir.'/clilib.php');
|
||||
|
||||
try {
|
||||
$cli = new create();
|
||||
$config = outagelib::get_config();
|
||||
$cli->set_defaults([
|
||||
'help' => false,
|
||||
'warn' => (int)($config->default_warning_duration),
|
||||
'start' => null,
|
||||
'duration' => (int)($config->default_duration),
|
||||
'title' => $config->default_title,
|
||||
'description' => $config->default_description,
|
||||
]);
|
||||
$cli->execute();
|
||||
} catch (cli_exception $e) {
|
||||
cli_error($e->getMessage());
|
||||
|
||||
@@ -28,10 +28,10 @@ use auth_outage\local\cli\finish;
|
||||
|
||||
define('CLI_SCRIPT', true);
|
||||
require_once(__DIR__.'/../../../config.php');
|
||||
|
||||
$cli = new finish();
|
||||
require_once($CFG->libdir.'/clilib.php');
|
||||
|
||||
try {
|
||||
$cli = new finish();
|
||||
$cli->execute();
|
||||
} catch (cli_exception $e) {
|
||||
cli_error($e->getMessage());
|
||||
|
||||
@@ -28,10 +28,10 @@ use auth_outage\local\cli\waitforit;
|
||||
|
||||
define('CLI_SCRIPT', true);
|
||||
require_once(__DIR__.'/../../../config.php');
|
||||
|
||||
$cli = new waitforit();
|
||||
require_once($CFG->libdir.'/clilib.php');
|
||||
|
||||
try {
|
||||
$cli = new waitforit();
|
||||
$cli->execute();
|
||||
} catch (cli_exception $e) {
|
||||
cli_error($e->getMessage());
|
||||
|
||||
@@ -42,6 +42,7 @@ $string['clifinishnotongoing'] = 'Outage is not ongoing.';
|
||||
$string['clifinishparamhelp'] = 'shows parameters help.';
|
||||
$string['clifinishparamactive'] = 'finishes the currently active outage.';
|
||||
$string['clifinishparamoutageid'] = 'the id of the outage to finish.';
|
||||
$string['cliplugindisabled'] = 'The authentication plugin \'Outage\' is disabled. Please enable it in the site administration it and try again.';
|
||||
$string['cliwaitforiterroridxoractive'] = 'You must use --outageid=# or --active parameter but not both.';
|
||||
$string['cliwaitforithelp'] = 'Waits until an outage starts.';
|
||||
$string['cliwaitforitoutagestarted'] = 'Outage started!';
|
||||
|
||||
@@ -79,4 +79,17 @@ class cli_test extends cli_testcase {
|
||||
public function test_exception() {
|
||||
throw new cli_exception('An CLI exception.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException auth_outage\local\cli\cli_exception
|
||||
* @expectedExceptionCode 8
|
||||
*/
|
||||
public function test_authdisabled() {
|
||||
// Disable all auth plugins.
|
||||
set_config('auth', '');
|
||||
\core\session\manager::gc(); // Remove stale sessions.
|
||||
core_plugin_manager::reset_caches();
|
||||
// Try to create an CLI
|
||||
$cli = new create();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,11 @@ defined('MOODLE_INTERNAL') || die();
|
||||
*/
|
||||
class cli_testcase extends advanced_testcase {
|
||||
public function setUp() {
|
||||
// Enable auth plugins.
|
||||
set_config('auth', 'outage');
|
||||
\core\session\manager::gc(); // Remove stale sessions.
|
||||
core_plugin_manager::reset_caches();
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
$this->set_parameters([]);
|
||||
parent::setUp();
|
||||
|
||||
Reference in New Issue
Block a user