From d80ae326fd03f58856a31d65facaf5c9fffb39a6 Mon Sep 17 00:00:00 2001 From: Daniel Thee Roperto Date: Thu, 2 Mar 2017 18:13:44 +1100 Subject: [PATCH] Fixes #107 - Check in bootstrap.php if this is a behat environment. --- README.md | 2 +- bootstrap.php | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bb42c62..6aba6dd 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/bootstrap.php b/bootstrap.php index 6355386..82c6d5d 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -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. @@ -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; +}