Run SessionHandler::write() into a transaction

This commit is contained in:
Frédéric Guillot 2018-02-13 15:06:51 -08:00
parent 2c4a3cb7e0
commit b096e907cf
1 changed files with 13 additions and 7 deletions

View File

@ -54,17 +54,23 @@ class SessionHandler implements SessionHandlerInterface
{
$lifetime = time() + (ini_get('session.gc_maxlifetime') ?: 1440);
$this->db->startTransaction();
if ($this->db->table(self::TABLE)->eq('id', $sessionID)->exists()) {
return $this->db->table(self::TABLE)->eq('id', $sessionID)->update(array(
$this->db->table(self::TABLE)->eq('id', $sessionID)->update([
'expire_at' => $lifetime,
'data' => $data,
));
]);
} else {
$this->db->table(self::TABLE)->insert([
'id' => $sessionID,
'expire_at' => $lifetime,
'data' => $data,
]);
}
return $this->db->table(self::TABLE)->insert(array(
'id' => $sessionID,
'expire_at' => $lifetime,
'data' => $data,
));
$this->db->closeTransaction();
return true;
}
}