BUG Fix access to protected Session::current_session()

Fixes #3144
This commit is contained in:
Damian Mooyman 2014-05-20 09:47:34 +12:00
parent 08ea44d458
commit 4a34c364e6
2 changed files with 25 additions and 11 deletions

View File

@ -939,23 +939,28 @@ class Versioned extends DataExtension implements TemplateGlobalProvider {
* @param Session $session Optional session within which to store the resulting stage
*/
public static function choose_site_stage($session = null) {
if(!$session) $session = Session::current_session();
// Default to Live
$mode = 'Stage.Live';
// Get reading mode
if(isset($_GET['stage'])) {
$stage = ucfirst(strtolower($_GET['stage']));
if(!in_array($stage, array('Stage', 'Live'))) $stage = 'Live';
$session->inst_set('readingMode', 'Stage.' . $stage);
}
if(isset($_GET['archiveDate']) && strtotime($_GET['archiveDate'])) {
$session->inst_set('readingMode', 'Archive.' . $_GET['archiveDate']);
$mode = 'Stage.' . $stage;
} elseif (isset($_GET['archiveDate']) && strtotime($_GET['archiveDate'])) {
$mode = 'Archive.' . $_GET['archiveDate'];
} elseif($session) {
$mode = $session->inst_get('readingMode') ?: $mode;
} else {
$mode = Session::get('readingMode') ?: $mode;
}
if($mode = $session->inst_get('readingMode')) {
Versioned::set_reading_mode($mode);
// Save reading mode
Versioned::set_reading_mode($mode);
if($session) {
$session->inst_set('readingMode', $mode);
} else {
Versioned::reading_stage("Live");
Session::set('readingMode', $mode);
}
if(!headers_sent() && !Director::is_cli()) {

View File

@ -439,7 +439,6 @@ class VersionedTest extends SapphireTest {
$testData->Content = 'After Content';
$testData->write();
$_GET['archiveDate'] = '2009-01-01 19:00:00';
Versioned::reading_archived_date('2009-01-01 19:00:00');
$fetchedData = VersionedTest_DataObject::get()->byId($id);
@ -568,6 +567,16 @@ class VersionedTest extends SapphireTest {
'Check that subsequent requests in the same session remain in Live mode'
);
// Test choose_site_stage
Session::set('readingMode', 'Stage.Stage');
Versioned::choose_site_stage();
$this->assertEquals('Stage.Stage', Versioned::get_reading_mode());
Session::set('readingMode', 'Archive.2014-01-01');
Versioned::choose_site_stage();
$this->assertEquals('Archive.2014-01-01', Versioned::get_reading_mode());
Session::clear('readingMode');
Versioned::choose_site_stage();
$this->assertEquals('Stage.Live', Versioned::get_reading_mode());
}
}