diff --git a/core/Classes/SessionHandler.class.php b/core/Classes/SessionHandler.class.php index 877a72f..04ef1da 100644 --- a/core/Classes/SessionHandler.class.php +++ b/core/Classes/SessionHandler.class.php @@ -27,7 +27,7 @@ public static function Read($sessionId) { $session = new \Models\Session(); $session->SessionId = $sessionId; - \Database\Controller::getInstance()->Sessions->LoadBySessionId($session); + \Database\Controller::getInstance()->Sessions->Load($session); self::$_session = $session; return self::$_session->Data; } diff --git a/core/Database/Collections/MongoDB/SessionCollection.class.php b/core/Database/Collections/MongoDB/SessionCollection.class.php index 61e6fd0..480b45d 100644 --- a/core/Database/Collections/MongoDB/SessionCollection.class.php +++ b/core/Database/Collections/MongoDB/SessionCollection.class.php @@ -10,7 +10,7 @@ class SessionCollection extends Collection implements \Database\Collections\SessionInterface { - const FIELD_DATA = 'Data'; + const FIELD_DATA = 'Data'; const FIELD_LASTACCESS = 'LastAccess'; const FIELD_SESSIONID = 'SessionId'; @@ -21,7 +21,7 @@ protected function toArray(\Models\Model $model) return $result; } - public function LoadBySessionId(\Models\Model $model) + public function Load(\Models\Model $model) { $id = $model->SessionId; $data = $this->Collection->findOne(array(self::FIELD_SESSIONID => $id)); @@ -36,6 +36,31 @@ public function LoadBySessionId(\Models\Model $model) } } + public function Save(\Models\Model $model, $returnId = true) + { + try + { + $array = $this->toArray($model); + $this->Collection->save($array, array('safe'=>true)); + if($returnId) + $model->Id = (string)$array[self::FIELD_ID]; + } + catch(\Exception $e) + { + return false; + } + return true; + } + + public function Remove(\Models\Model $model) + { + $id = new \MongoId($model->SessionId); + $data = $this->Collection->remove(array(self::FIELD_SESSIONID => $id)); + return true; + } + + + public function Cleanup($time) { try