mirror of
https://github.com/silverstripe/silverstripe-testsession
synced 2024-10-22 14:06:00 +02:00
29 lines
882 B
PHP
29 lines
882 B
PHP
<?php
|
|
/**
|
|
* Stores the currently logged in user in the database in addition to
|
|
* PHP session. This means the information can be shared with other processes
|
|
* such as a Behat CLI execution, without requiring this information to be available
|
|
* through the UI (and potentially cause another page load via Selenium).
|
|
*/
|
|
class TestSessionMemberExtension extends DataExtension {
|
|
|
|
public function memberLoggedIn() {
|
|
if(!SapphireTest::using_temp_db()) return;
|
|
|
|
$state = TestSessionDatabaseState::get()->find('Key', 'CurrentMemberID');
|
|
if(!$state) {
|
|
$state = new TestSessionDatabaseState(array(
|
|
'Key' => 'CurrentMemberID'
|
|
));
|
|
}
|
|
$state->Value = $this->owner->ID;
|
|
$state->write();
|
|
}
|
|
|
|
public function memberLoggedOut() {
|
|
if(!SapphireTest::using_temp_db()) return;
|
|
|
|
$state = TestSessionDatabaseState::get()->filter('Key', 'CurrentMemberID')->removeAll();
|
|
}
|
|
|
|
} |