2014-02-04 23:38:22 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2014-02-09 06:38:58 +01:00
|
|
|
* Responsible for starting and finalizing test sessions.
|
|
|
|
* Since these session span across multiple requests, session information is persisted
|
|
|
|
* in a file. This file is stored in the webroot by default, and the test session
|
|
|
|
* is considered "in progress" as long as this file exists.
|
2014-02-04 23:38:22 +01:00
|
|
|
*
|
2014-02-09 06:38:58 +01:00
|
|
|
* This allows for cross-request, cross-client sharing of the same testsession,
|
|
|
|
* for example: Behat CLI starts a testsession, then opens a web browser which
|
|
|
|
* makes a separate request picking up the same testsession.
|
|
|
|
*
|
2014-03-01 06:28:34 +01:00
|
|
|
* An environment can have an optional identifier ({@link id}), which allows
|
|
|
|
* multiple environments to exist at the same time in the same webroot.
|
2014-07-21 00:10:54 +02:00
|
|
|
* This enables parallel testing with (mostly) isolated state.
|
2014-03-01 06:28:34 +01:00
|
|
|
*
|
|
|
|
* For a valid test session to exist, this needs to contain at least:
|
|
|
|
* - database: The alternate database name that is being used for this test session (e.g. ss_tmpdb_1234567)
|
|
|
|
* It can optionally contain other details that should be passed through many separate requests:
|
|
|
|
* - datetime: Mocked SS_DateTime ({@see TestSessionRequestFilter})
|
|
|
|
* - mailer: Mocked Email sender ({@see TestSessionRequestFilter})
|
|
|
|
* - stubfile: Path to PHP stub file for setup ({@see TestSessionRequestFilter})
|
|
|
|
* Extensions of TestSessionEnvironment can add extra fields in here to be saved and restored on each request.
|
|
|
|
*
|
2014-02-09 06:38:58 +01:00
|
|
|
* See {@link $state} for default information stored in the test session.
|
2014-02-04 23:38:22 +01:00
|
|
|
*/
|
|
|
|
class TestSessionEnvironment extends Object {
|
2014-07-21 00:10:54 +02:00
|
|
|
|
2014-02-04 23:38:22 +01:00
|
|
|
/**
|
2014-03-01 06:28:34 +01:00
|
|
|
* @var int Optional identifier for the session.
|
2014-02-04 23:38:22 +01:00
|
|
|
*/
|
2014-03-01 06:28:34 +01:00
|
|
|
protected $id;
|
2014-02-04 23:38:22 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string The original database name, before we overrode it with our tmpdb.
|
|
|
|
*
|
|
|
|
* Used in {@link self::resetDatabaseName()} when we want to restore the normal DB connection.
|
|
|
|
*/
|
|
|
|
private $oldDatabaseName;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @config
|
|
|
|
* @var string Path (from web-root) to the test state file that indicates a testsession is in progress.
|
|
|
|
* Defaults to value stored in testsession/_config/_config.yml
|
|
|
|
*/
|
2014-03-01 08:31:22 +01:00
|
|
|
private static $test_state_file = 'TESTS_RUNNING.json';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @config
|
|
|
|
* @var [type]
|
|
|
|
*/
|
|
|
|
private static $test_state_id_file = 'TESTS_RUNNING-%s.json';
|
2014-02-04 23:38:22 +01:00
|
|
|
|
2014-03-01 06:28:34 +01:00
|
|
|
public function __construct($id = null) {
|
2014-03-01 00:57:59 +01:00
|
|
|
parent::__construct();
|
|
|
|
|
2014-03-03 04:19:38 +01:00
|
|
|
if($id) {
|
|
|
|
$this->id = $id;
|
|
|
|
} else {
|
|
|
|
Session::start();
|
2014-05-15 07:28:53 +02:00
|
|
|
// $_SESSION != Session::get() in some execution paths, suspect Controller->pushCurrent()
|
|
|
|
// as part of the issue, easiest resolution is to use session directly for now
|
|
|
|
$this->id = (isset($_SESSION['TestSessionId'])) ? $_SESSION['TestSessionId'] : null;
|
2014-03-03 04:19:38 +01:00
|
|
|
}
|
2014-03-01 06:28:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return String Absolute path to the file persisting our state.
|
|
|
|
*/
|
|
|
|
public function getFilePath() {
|
|
|
|
if($this->id) {
|
2014-07-21 00:10:54 +02:00
|
|
|
$path = Director::getAbsFile(sprintf($this->config()->test_state_id_file, $this->id));
|
2014-03-01 00:57:59 +01:00
|
|
|
} else {
|
2014-07-21 00:10:54 +02:00
|
|
|
$path = Director::getAbsFile($this->config()->test_state_file);
|
2014-03-01 00:57:59 +01:00
|
|
|
}
|
2014-03-16 05:14:43 +01:00
|
|
|
|
|
|
|
return $path;
|
2014-03-01 00:57:59 +01:00
|
|
|
}
|
|
|
|
|
2014-02-04 23:38:22 +01:00
|
|
|
/**
|
|
|
|
* Tests for the existence of the file specified by $this->test_state_file
|
|
|
|
*/
|
|
|
|
public function isRunningTests() {
|
2014-03-01 06:28:34 +01:00
|
|
|
return(file_exists($this->getFilePath()));
|
2014-02-04 23:38:22 +01:00
|
|
|
}
|
|
|
|
|
2014-03-03 04:19:38 +01:00
|
|
|
/**
|
|
|
|
* @param String $id
|
|
|
|
*/
|
|
|
|
public function setId($id) {
|
|
|
|
$this->id = $id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return String
|
|
|
|
*/
|
|
|
|
public function getId() {
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
2014-02-04 23:38:22 +01:00
|
|
|
/**
|
|
|
|
* Creates a temp database, sets up any extra requirements, and writes the state file. The database will be
|
|
|
|
* connected to as part of {@link self::applyState()}, so if you're continuing script execution after calling this
|
|
|
|
* method, be aware that the database will be different - so various things may break (e.g. administrator logins
|
|
|
|
* using the SS_DEFAULT_USERNAME / SS_DEFAULT_PASSWORD constants).
|
|
|
|
*
|
|
|
|
* If something isn't explicitly handled here, and needs special handling, then it should be taken care of by an
|
|
|
|
* extension to TestSessionEnvironment. You can either extend onBeforeStartTestSession() or
|
|
|
|
* onAfterStartTestSession(). Alternatively, for more fine-grained control, you can also extend
|
|
|
|
* onBeforeApplyState() and onAfterApplyState(). See the {@link self::applyState()} method for more.
|
|
|
|
*
|
|
|
|
* @param array $state An array of test state options to write.
|
|
|
|
*/
|
2014-03-18 07:10:36 +01:00
|
|
|
public function startTestSession($state = null, $id = null) {
|
|
|
|
if(!$state) $state = array();
|
2014-03-01 06:28:34 +01:00
|
|
|
$this->removeStateFile();
|
2014-03-01 08:31:22 +01:00
|
|
|
$this->id = $id;
|
2014-03-01 06:28:34 +01:00
|
|
|
|
2014-05-08 04:13:49 +02:00
|
|
|
// Assumes state will be modified by reference
|
|
|
|
$this->extend('onBeforeStartTestSession', $state);
|
2014-02-04 23:38:22 +01:00
|
|
|
|
2014-02-09 06:38:58 +01:00
|
|
|
// Convert to JSON and back so we can share the applyState() code between this and ->loadFromFile()
|
|
|
|
$json = json_encode($state, JSON_FORCE_OBJECT);
|
|
|
|
$state = json_decode($json);
|
2014-02-04 23:38:22 +01:00
|
|
|
|
|
|
|
$this->applyState($state);
|
|
|
|
|
|
|
|
$this->extend('onAfterStartTestSession');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function updateTestSession($state) {
|
|
|
|
$this->extend('onBeforeUpdateTestSession', $state);
|
|
|
|
|
|
|
|
// Convert to JSON and back so we can share the appleState() code between this and ->loadFromFile()
|
2014-02-09 06:38:58 +01:00
|
|
|
$json = json_encode($state, JSON_FORCE_OBJECT);
|
|
|
|
$state = json_decode($json);
|
2014-02-04 23:38:22 +01:00
|
|
|
|
|
|
|
$this->applyState($state);
|
|
|
|
|
|
|
|
$this->extend('onAfterUpdateTestSession');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assumes the database has already been created in startTestSession(), as this method can be called from
|
|
|
|
* _config.php where we don't yet have a DB connection.
|
|
|
|
*
|
2014-03-01 06:28:34 +01:00
|
|
|
* Persists the state to the filesystem.
|
2014-02-04 23:38:22 +01:00
|
|
|
*
|
|
|
|
* You can extend this by creating an Extension object and implementing either onBeforeApplyState() or
|
|
|
|
* onAfterApplyState() to add your own test state handling in.
|
|
|
|
*
|
|
|
|
* @throws LogicException
|
|
|
|
* @throws InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function applyState($state) {
|
2014-03-17 10:59:05 +01:00
|
|
|
$this->extend('onBeforeApplyState', $state);
|
2014-03-16 05:16:34 +01:00
|
|
|
|
2014-03-18 07:10:36 +01:00
|
|
|
$database = (isset($state->database)) ? $state->database : null;
|
|
|
|
|
|
|
|
// back up source
|
|
|
|
global $databaseConfig;
|
|
|
|
$this->oldDatabaseName = $databaseConfig['database'];
|
|
|
|
|
2014-02-04 23:38:22 +01:00
|
|
|
// Load existing state from $this->state into $state, if there is any
|
2014-03-01 06:28:34 +01:00
|
|
|
$oldState = $this->getState();
|
2014-03-18 07:10:36 +01:00
|
|
|
|
2014-03-01 06:28:34 +01:00
|
|
|
if($oldState) {
|
|
|
|
foreach($oldState as $k => $v) {
|
2014-03-18 07:10:36 +01:00
|
|
|
if(!isset($state->$k)) {
|
|
|
|
$state->$k = $v; // Don't overwrite stuff in $state, as that's the new state
|
|
|
|
}
|
2014-02-04 23:38:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-18 07:10:36 +01:00
|
|
|
// ensure we have a connection to the database
|
2014-03-17 10:59:05 +01:00
|
|
|
if(isset($state->database) && $state->database) {
|
2014-07-21 00:10:54 +02:00
|
|
|
if(!DB::get_conn()) {
|
2014-03-17 10:59:05 +01:00
|
|
|
// No connection, so try and connect to tmpdb if it exists
|
|
|
|
if(isset($state->database)) {
|
|
|
|
$this->oldDatabaseName = $databaseConfig['database'];
|
|
|
|
$databaseConfig['database'] = $state->database;
|
|
|
|
}
|
2014-02-04 23:38:22 +01:00
|
|
|
|
2014-03-17 10:59:05 +01:00
|
|
|
// Connect to database
|
2014-03-17 09:42:47 +01:00
|
|
|
DB::connect($databaseConfig);
|
2014-03-17 10:59:05 +01:00
|
|
|
} else {
|
|
|
|
// We've already connected to the database, do a fast check to see what database we're currently using
|
2014-07-21 00:10:54 +02:00
|
|
|
$db = DB::get_conn()->getSelectedDatabase();
|
2014-03-17 10:59:05 +01:00
|
|
|
if(isset($state->database) && $db != $state->database) {
|
|
|
|
$this->oldDatabaseName = $databaseConfig['database'];
|
|
|
|
$databaseConfig['database'] = $state->database;
|
|
|
|
DB::connect($databaseConfig);
|
|
|
|
}
|
2014-02-04 23:38:22 +01:00
|
|
|
}
|
2014-03-16 05:16:34 +01:00
|
|
|
}
|
2014-02-04 23:38:22 +01:00
|
|
|
|
2014-03-16 05:16:34 +01:00
|
|
|
// Database
|
2014-03-18 07:10:36 +01:00
|
|
|
if(!$this->isRunningTests()) {
|
2014-03-17 10:59:05 +01:00
|
|
|
$dbName = (isset($state->database)) ? $state->database : null;
|
|
|
|
|
|
|
|
if($dbName) {
|
2014-07-21 00:10:54 +02:00
|
|
|
$dbExists = DB::get_conn()->databaseExists($dbName);
|
2014-03-17 10:59:05 +01:00
|
|
|
} else {
|
|
|
|
$dbExists = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!$dbExists) {
|
|
|
|
// Create a new one with a randomized name
|
|
|
|
$dbName = SapphireTest::create_temp_db();
|
|
|
|
|
|
|
|
$state->database = $dbName; // In case it's changed by the call to SapphireTest::create_temp_db();
|
|
|
|
|
|
|
|
// Set existing one, assumes it already has been created
|
|
|
|
$prefix = defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : 'ss_';
|
|
|
|
$pattern = strtolower(sprintf('#^%stmpdb\d{7}#', $prefix));
|
|
|
|
if(!preg_match($pattern, $dbName)) {
|
|
|
|
throw new InvalidArgumentException("Invalid database name format");
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->oldDatabaseName = $databaseConfig['database'];
|
|
|
|
$databaseConfig['database'] = $dbName; // Instead of calling DB::set_alternative_db_name();
|
|
|
|
|
|
|
|
// Connect to the new database, overwriting the old DB connection (if any)
|
|
|
|
DB::connect($databaseConfig);
|
|
|
|
}
|
2014-02-04 23:38:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mailer
|
|
|
|
$mailer = (isset($state->mailer)) ? $state->mailer : null;
|
2014-03-18 07:10:36 +01:00
|
|
|
|
2014-02-04 23:38:22 +01:00
|
|
|
if($mailer) {
|
|
|
|
if(!class_exists($mailer) || !is_subclass_of($mailer, 'Mailer')) {
|
|
|
|
throw new InvalidArgumentException(sprintf(
|
|
|
|
'Class "%s" is not a valid class, or subclass of Mailer',
|
|
|
|
$mailer
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Date and time
|
|
|
|
if(isset($state->datetime)) {
|
|
|
|
require_once 'Zend/Date.php';
|
|
|
|
// Convert DatetimeField format
|
|
|
|
if(!Zend_Date::isDate($state->datetime, 'yyyy-MM-dd HH:mm:ss')) {
|
|
|
|
throw new LogicException(sprintf(
|
|
|
|
'Invalid date format "%s", use yyyy-MM-dd HH:mm:ss',
|
|
|
|
$state->datetime
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-18 07:10:36 +01:00
|
|
|
$this->saveState($state);
|
|
|
|
$this->extend('onAfterApplyState');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Import the database
|
|
|
|
*
|
|
|
|
* @param String $path Absolute path to a SQL dump (include DROP TABLE commands)
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function importDatabase($path, $requireDefaultRecords = false) {
|
|
|
|
$sql = file_get_contents($path);
|
|
|
|
|
|
|
|
// Split into individual query commands, removing comments
|
|
|
|
$sqlCmds = array_filter(
|
2014-05-08 02:51:32 +02:00
|
|
|
preg_split('/;\n/',
|
2014-03-18 07:10:36 +01:00
|
|
|
preg_replace(array('/^$\n/m', '/^(\/|#).*$\n/m'), '', $sql)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Execute each query
|
|
|
|
foreach($sqlCmds as $sqlCmd) {
|
|
|
|
DB::query($sqlCmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
// In case the dump involved CREATE TABLE commands, we need to ensure the schema is still up to date
|
|
|
|
$dbAdmin = new DatabaseAdmin();
|
|
|
|
Versioned::set_reading_mode('');
|
|
|
|
$dbAdmin->doBuild(true, $requireDefaultRecords);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build the database with default records, see {@link DataObject->requireDefaultRecords()}.
|
|
|
|
*/
|
|
|
|
public function requireDefaultRecords() {
|
|
|
|
$dbAdmin = new DatabaseAdmin();
|
|
|
|
Versioned::set_reading_mode('');
|
|
|
|
$dbAdmin->doBuild(true, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-07-21 00:10:54 +02:00
|
|
|
* Sliented as if the file already exists by another process, we don't want
|
2014-03-18 07:10:36 +01:00
|
|
|
* to modify.
|
|
|
|
*/
|
|
|
|
public function saveState($state) {
|
2014-04-01 04:48:12 +02:00
|
|
|
if (defined('JSON_PRETTY_PRINT')) {
|
|
|
|
$content = json_encode($state, JSON_PRETTY_PRINT);
|
|
|
|
} else {
|
|
|
|
$content = json_encode($state);
|
|
|
|
}
|
2014-11-05 20:43:38 +01:00
|
|
|
$old = umask(0);
|
2014-03-18 07:10:36 +01:00
|
|
|
file_put_contents($this->getFilePath(), $content, LOCK_EX);
|
2014-11-05 20:43:38 +01:00
|
|
|
umask($old);
|
2014-02-04 23:38:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function loadFromFile() {
|
|
|
|
if($this->isRunningTests()) {
|
|
|
|
try {
|
2014-03-01 06:28:34 +01:00
|
|
|
$contents = file_get_contents($this->getFilePath());
|
2014-02-09 06:38:58 +01:00
|
|
|
$json = json_decode($contents);
|
2014-02-04 23:38:22 +01:00
|
|
|
|
2014-02-09 06:38:58 +01:00
|
|
|
$this->applyState($json);
|
2014-02-04 23:38:22 +01:00
|
|
|
} catch(Exception $e) {
|
|
|
|
throw new \Exception("A test session appears to be in progress, but we can't retrieve the details. "
|
2014-03-01 06:28:34 +01:00
|
|
|
. "Try removing the " . $this->getFilePath() . " file. Inner "
|
2014-02-04 23:38:22 +01:00
|
|
|
. "error: " . $e->getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function removeStateFile() {
|
2014-03-01 06:28:34 +01:00
|
|
|
$file = $this->getFilePath();
|
2014-03-18 07:10:36 +01:00
|
|
|
|
2014-02-09 06:38:58 +01:00
|
|
|
if(file_exists($file)) {
|
|
|
|
if(!unlink($file)) {
|
2014-02-04 23:38:22 +01:00
|
|
|
throw new \Exception('Unable to remove the testsession state file, please remove it manually. File '
|
2014-02-09 06:38:58 +01:00
|
|
|
. 'path: ' . $file);
|
2014-02-04 23:38:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cleans up the test session state by restoring the normal database connect (for the rest of this request, if any)
|
|
|
|
* and removes the {@link self::$test_state_file} so that future requests don't use this test state.
|
|
|
|
*
|
|
|
|
* Can be extended by implementing either onBeforeEndTestSession() or onAfterEndTestSession().
|
|
|
|
*
|
|
|
|
* This should implement itself cleanly in case it is called twice (e.g. don't throw errors when the state file
|
|
|
|
* doesn't exist anymore because it's already been cleaned up etc.) This is because during behat test runs where
|
|
|
|
* a queueing system (e.g. silverstripe-resque) is used, the behat module may call this first, and then the forked
|
|
|
|
* worker will call it as well - but there is only one state file that is created.
|
|
|
|
*/
|
|
|
|
public function endTestSession() {
|
|
|
|
$this->extend('onBeforeEndTestSession');
|
|
|
|
|
|
|
|
if(SapphireTest::using_temp_db()) {
|
|
|
|
$this->resetDatabaseName();
|
2014-03-18 07:10:36 +01:00
|
|
|
|
|
|
|
SapphireTest::set_is_running_test(false);
|
2014-02-04 23:38:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->removeStateFile();
|
|
|
|
|
|
|
|
$this->extend('onAfterEndTestSession');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads a YAML fixture into the database as part of the {@link TestSessionController}.
|
|
|
|
*
|
|
|
|
* @param string $fixtureFile The .yml file to load
|
|
|
|
* @return FixtureFactory The loaded fixture
|
|
|
|
* @throws LogicException
|
|
|
|
*/
|
2014-03-18 07:10:36 +01:00
|
|
|
public function loadFixtureIntoDb($fixtureFile) {
|
2014-02-04 23:38:22 +01:00
|
|
|
$realFile = realpath(BASE_PATH.'/'.$fixtureFile);
|
|
|
|
$baseDir = realpath(Director::baseFolder());
|
|
|
|
if(!$realFile || !file_exists($realFile)) {
|
|
|
|
throw new LogicException("Fixture file doesn't exist");
|
|
|
|
} else if(substr($realFile,0,strlen($baseDir)) != $baseDir) {
|
|
|
|
throw new LogicException("Fixture file must be inside $baseDir");
|
|
|
|
} else if(substr($realFile,-4) != '.yml') {
|
|
|
|
throw new LogicException("Fixture file must be a .yml file");
|
|
|
|
} else if(!preg_match('/^([^\/.][^\/]+)\/tests\//', $fixtureFile)) {
|
|
|
|
throw new LogicException("Fixture file must be inside the tests subfolder of one of your modules.");
|
|
|
|
}
|
|
|
|
|
|
|
|
$factory = Injector::inst()->create('FixtureFactory');
|
|
|
|
$fixture = Injector::inst()->create('YamlFixture', $fixtureFile);
|
|
|
|
$fixture->writeInto($factory);
|
|
|
|
|
2014-03-01 06:28:34 +01:00
|
|
|
$state = $this->getState();
|
|
|
|
$state->fixtures[] = $fixtureFile;
|
|
|
|
$this->applyState($state);
|
2014-02-04 23:38:22 +01:00
|
|
|
|
|
|
|
return $fixture;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset the database connection to use the original database. Called by {@link self::endTestSession()}.
|
|
|
|
*/
|
|
|
|
public function resetDatabaseName() {
|
2014-03-18 07:10:36 +01:00
|
|
|
if($this->oldDatabaseName) {
|
|
|
|
global $databaseConfig;
|
|
|
|
|
|
|
|
$databaseConfig['database'] = $this->oldDatabaseName;
|
2014-02-04 23:38:22 +01:00
|
|
|
|
2014-07-21 00:10:54 +02:00
|
|
|
$conn = DB::get_conn();
|
2014-03-16 05:16:34 +01:00
|
|
|
|
2014-03-18 07:10:36 +01:00
|
|
|
if($conn) {
|
2014-07-21 00:10:54 +02:00
|
|
|
$conn->selectDatabase($this->oldDatabaseName, false, false);
|
2014-03-18 07:10:36 +01:00
|
|
|
}
|
|
|
|
}
|
2014-02-04 23:38:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return stdClass Data as taken from the JSON object in {@link self::loadFromFile()}
|
|
|
|
*/
|
|
|
|
public function getState() {
|
2014-03-04 05:49:41 +01:00
|
|
|
$path = Director::getAbsFile($this->getFilePath());
|
2014-03-01 06:28:34 +01:00
|
|
|
return (file_exists($path)) ? json_decode(file_get_contents($path)) : new stdClass;
|
2014-02-04 23:38:22 +01:00
|
|
|
}
|
2014-06-12 04:44:55 +02:00
|
|
|
}
|