} } // And if we can flush, reload with an authority token if ($canFlush) { $token->reloadWithToken(); } } } function silverstripe_main_flushOnError() { global $token; if ($token->parameterProvided() && !$token->tokenProvided()) { $token->reloadWithToken(); } } $chain->then('silverstripe_main')->thenIfErrored('silverstripe_main_flushOnError')->execute(); // Redirect to the installer if no database is selected if (!isset($databaseConfig) || !isset($databaseConfig['database']) || !$databaseConfig['database']) { $s = isset($_SERVER['SSL']) || isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 's' : ''; $installURL = "http{$s}://" . $_SERVER['HTTP_HOST'] . BASE_URL . '/install.php'; // The above dirname() will equate to "\" on Windows when installing directly from http://localhost (not using // a sub-directory), this really messes things up in some browsers. Let's get rid of the backslashes $installURL = str_replace('\\', '', $installURL); header("Location: {$installURL}"); die; } if (isset($_GET['debug_profile'])) { Profiler::unmark('main.php init'); } // Direct away - this is the "main" function, that hands control to the appropriate controller Director::direct($url);
$chain->then(function ($chain) use($reloadToken) { // If no redirection is necessary then we can disable error supression if (!$reloadToken) { $chain->setSuppression(false); } // Load in core require_once 'core/Core.php'; // Connect to database require_once 'model/DB.php'; global $databaseConfig; if ($databaseConfig) { DB::connect($databaseConfig); } // Check if a token is requesting a redirect if (!$reloadToken) { return; } // Otherwise, we start up the session if needed if (!isset($_SESSION) && Session::request_contains_session_id()) { Session::start(); } // Next, check if we're in dev mode, or the database doesn't have any security data, or we are admin if (Director::isDev() || !Security::database_is_ready() || Permission::check('ADMIN')) { return $reloadToken->reloadWithToken(); } // Fail and redirect the user to the login page $loginPage = Director::absoluteURL(Config::inst()->get('Security', 'login_url')); $loginPage .= "?BackURL=" . urlencode($_SERVER['REQUEST_URI']); header('location: ' . $loginPage, true, 302); die; })->thenIfErrored(function () use($reloadToken) {
$chain->then(function ($chain) use($token) { // First, if $_GET['flush'] was set, but no valid token, suppress the flush if (isset($_GET['flush']) && !$token->tokenProvided()) { unset($_GET['flush']); } else { $chain->setSuppression(false); } // Load in core require_once 'core/Core.php'; // Connect to database require_once 'model/DB.php'; global $databaseConfig; if ($databaseConfig) { DB::connect($databaseConfig); } // Then if a flush was requested, redirect to it if ($token->parameterProvided() && !$token->tokenProvided()) { // First, check if we're in dev mode, or the database doesn't have any security data $canFlush = Director::isDev() || !Security::database_is_ready(); // Otherwise, we start up the session if needed, then check for admin if (!$canFlush) { if (!isset($_SESSION) && Session::request_contains_session_id()) { Session::start(); } if (Permission::check('ADMIN')) { $canFlush = true; } else { $loginPage = Director::absoluteURL(Config::inst()->get('Security', 'login_url')); $loginPage .= "?BackURL=" . urlencode($_SERVER['REQUEST_URI']); header('location: ' . $loginPage, true, 302); die; } } // And if we can flush, reload with an authority token if ($canFlush) { $token->reloadWithToken(); } } })->thenIfErrored(function () use($token) {