src/Versioned.php
public static function choose_site_stage(HTTPRequest $request)
    {
        $mode = static::get_default_reading_mode();

        // Check any pre-existing session mode
        $useSession = Config::inst()->get(static::class, 'use_session');
        $updateSession = false;
        if ($useSession) {
            // Boot reading mode from session
            $mode = $request->getSession()->get('readingMode') ?: $mode;

            // Set draft site security if disabled for this session
            if ($request->getSession()->get('unsecuredDraftSite')) {
                static::set_draft_site_secured(false);
            }
        }

        // Verify if querystring contains valid reading mode
        $queryMode = ReadingMode::fromQueryString($request->getVars());
        if ($queryMode) {
            $mode = $queryMode;
            $updateSession = true;
        }

        // Save reading mode
        Versioned::set_reading_mode($mode);

        // Set mode if session enabled
        if ($useSession && $updateSession) {
            $request->getSession()->set('readingMode', $mode);
        }

        if (!headers_sent() && !Director::is_cli()) {
            if (Versioned::get_stage() === static::LIVE) {
                // clear the cookie if it's set
                if (Cookie::get('bypassStaticCache')) {
                    Cookie::force_expiry('bypassStaticCache', null, null, false, true /* httponly */);
                }
            } else {
                // set the cookie if it's cleared
                if (!Cookie::get('bypassStaticCache')) {
                    Cookie::set('bypassStaticCache', '1', 0, null, null, false, true /* httponly */);
                }
            }
        }
    }
public static function choose_site_stage(HTTPRequest $request)
    {
        $mode = static::get_default_reading_mode();

        // Check any pre-existing session mode
        $useSession = Config::inst()->get(static::class, 'use_session');
        $updateSession = false;
        if ($useSession) {
            // Boot reading mode from session
            $mode = $request->getSession()->get('readingMode') ?: $mode;

            // Set draft site security if disabled for this session
            if ($request->getSession()->get('unsecuredDraftSite')) {
                static::set_draft_site_secured(false);
            }
        }

        // Verify if querystring contains valid reading mode
        $queryMode = ReadingMode::fromQueryString($request->getVars());
        if ($queryMode) {
            $mode = $queryMode;
            $updateSession = true;
        }

        // Save reading mode
        Versioned::set_reading_mode($mode);

        // Set mode if session enabled
        if ($useSession && $updateSession) {
            $request->getSession()->set('readingMode', $mode);
        }

        if (!headers_sent() && !Director::is_cli()) {
            if (Versioned::get_stage() === static::LIVE) {
                // clear the cookie if it's set
                if (Cookie::get('bypassStaticCache')) {
                    Cookie::force_expiry('bypassStaticCache', null, null, false, true /* httponly */);
                }
            } else {
                // set the cookie if it's cleared
                if (!Cookie::get('bypassStaticCache')) {
                    Cookie::set('bypassStaticCache', '1', 0, null, null, false, true /* httponly */);
                }
            }
        }
    }
public static function choose_site_stage ( HTTPRequest $ request ) { $ mode = static :: get_default_reading_mode ( ) ; // Check any pre-existing session mode $ useSession = Config :: inst ( ) -> get ( static :: class , 'use_session' ) ; $ updateSession = false ; if ( $ useSession ) { // Boot reading mode from session $ mode = $ request -> getSession ( ) -> get ( 'readingMode' ) ? : $ mode ; // Set draft site security if disabled for this session if ( $ request -> getSession ( ) -> get ( 'unsecuredDraftSite' ) ) { static :: set_draft_site_secured ( false ) ; } } // Verify if querystring contains valid reading mode $ queryMode = ReadingMode :: fromQueryString ( $ request -> getVars ( ) ) ; if ( $ queryMode ) { $ mode = $ queryMode ; $ updateSession = true ; } // Save reading mode Versioned :: set_reading_mode ( $ mode ) ; // Set mode if session enabled if ( $ useSession && $ updateSession ) { $ request -> getSession ( ) -> set ( 'readingMode' , $ mode ) ; } if ( ! headers_sent ( ) && ! Director :: is_cli ( ) ) { if ( Versioned :: get_stage ( ) === static :: LIVE ) { // clear the cookie if it's set if ( Cookie :: get ( 'bypassStaticCache' ) ) { Cookie :: force_expiry ( 'bypassStaticCache' , null , null , false , true /* httponly */ ) ; } } else { // set the cookie if it's cleared if ( ! Cookie :: get ( 'bypassStaticCache' ) ) { Cookie :: set ( 'bypassStaticCache' , '1' , 0 , null , null , false , true /* httponly */ ) ; } } } }
Choose the stage the site is currently on.

If $_GET['stage'] is set, then it will use that stage, and store it in
the session.

if $_GET['archiveDate'] is set, it will use that date, and store it in
the session.

If neither of these are set, it checks the session, otherwise the stage
is set to 'Live'.
@param HTTPRequest $request
Choose the stage the site is currently on .