From af62f7ec9514713e734e02e372a524f92ad2c931 Mon Sep 17 00:00:00 2001 From: Christopher Darling Date: Thu, 27 Oct 2016 14:58:14 +0100 Subject: [PATCH] FIX CMSPreview 500 error A bit of a crude fix for https://github.com/heyday/silverstripe-cacheinclude/issues/23 CMS Preview of Live mode doesn't require a DB connection to check if the user can view the stage so is still allowed to run --- main.php | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/main.php b/main.php index 91df3b2..0f195fd 100644 --- a/main.php +++ b/main.php @@ -2,25 +2,31 @@ require_once __DIR__.'/../framework/core/Core.php'; -$request = new SS_HTTPRequest( - $_SERVER['REQUEST_METHOD'], - isset($_GET['url']) ? $_GET['url'] : '', - $_GET -); +\Versioned::choose_site_stage(); -$headers = Director::extract_request_headers($_SERVER); +// Only skip framework/main.php if live stage +if (\Versioned::current_stage() == \Versioned::get_live_stage()) { -foreach ($headers as $header => $value) { - $request->addHeader($header, $value); -} + $request = new SS_HTTPRequest( + $_SERVER['REQUEST_METHOD'], + isset($_GET['url']) ? $_GET['url'] : '', + $_GET + ); -$container = Injector::inst(); + $headers = Director::extract_request_headers($_SERVER); -$session = $container->create('Session', array()); -if (Session::request_contains_session_id()) { - $session->inst_start(); -} + foreach ($headers as $header => $value) { + $request->addHeader($header, $value); + } + + $container = Injector::inst(); -$container->get('RequestProcessor')->preRequest($request, $session, DataModel::inst()); + $session = $container->create('Session', array()); + if (Session::request_contains_session_id()) { + $session->inst_start(); + } + + $container->get('RequestProcessor')->preRequest($request, $session, DataModel::inst()); +} require_once __DIR__.'/../framework/main.php';