Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #107 - Check in bootstrap.php if this is a behat environment. #108

Merged
merged 1 commit into from
Mar 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ https://github.com/catalyst/moodle-auth_outage/issues
enable the `Outage manager` plugin and place it on the top.

4. If you need to use the IP Blocking, please add the following lines into your `config.php`
after your `$CFG->dataroot` is set:
before the `require('/lib/setup.php')` call:

```
// Insert this after $CFG->dataroot is defined.
Expand Down
35 changes: 32 additions & 3 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,36 @@
return;
}

// 1) Check and run the hook.
// 1) Make sure we replace the configurations for behat as we have not ran 'lib/setup.php' yet.
if (!empty($CFG->behat_wwwroot) or !empty($CFG->behat_dataroot) or !empty($CFG->behat_prefix)) {
require_once(__DIR__.'/../../lib/behat/lib.php');
behat_update_vars_for_process();
if (behat_is_test_site()) {
$beforebehatcfg = $CFG;
$CFG = clone($CFG);
clearstatcache();
behat_check_config_vars();
behat_clean_init_config();
$CFG->wwwroot = $CFG->behat_wwwroot;
$CFG->dataroot = $CFG->behat_dataroot;
// We should not access database in bootstrap.
$CFG->dbtype = null;
$CFG->dblibrary = null;
$CFG->dbhost = null;
$CFG->dbname = null;
$CFG->dbuser = null;
$CFG->dbpass = null;
$CFG->prefix = null;
$CFG->dboptions = null;
}
}

// 2) Check and run the hook.
if (is_callable('auth_outage_bootstrap_callback')) {
call_user_func('auth_outage_bootstrap_callback');
}

// 2) Check for allowed scripts or IPs during outages.
// 3) Check for allowed scripts or IPs during outages.
$allowed = !file_exists($CFG->dataroot.'/climaintenance.php') // Not in maintenance mode.
|| (defined('ABORT_AFTER_CONFIG') && ABORT_AFTER_CONFIG) // Only config requested.
|| (defined('CLI_SCRIPT') && CLI_SCRIPT); // Allow CLI scripts.
Expand All @@ -52,5 +76,10 @@
require($CFG->dataroot.'/climaintenance.php'); // This call may terminate the script here or not.
}

// 3) Set flag this file was loaded.
// 4) Set flag this file was loaded.
$CFG->auth_outage_bootstrap_loaded = true;

// 5) Restore behat config as needed (let setup.php execute which is more complex than our quick-check).
if (isset($beforebehatcfg)) {
$CFG = $beforebehatcfg;
}