Skip to content

Commit

Permalink
Fixed sessions adding erroneous objects in the database
Browse files Browse the repository at this point in the history
  • Loading branch information
DorianGray committed Mar 9, 2012
1 parent df2cdd9 commit 55ebb19
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/Classes/SessionHandler.class.php
Expand Up @@ -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;
}
Expand Down
29 changes: 27 additions & 2 deletions core/Database/Collections/MongoDB/SessionCollection.class.php
Expand Up @@ -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';

Expand All @@ -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));
Expand All @@ -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
Expand Down

0 comments on commit 55ebb19

Please sign in to comment.