public function writeSession($id, $data)
{
// exception must be caught in session write handler
// http://us.php.net/manual/en/function.session-set-save-handler.php#refsect1-function.session-set-save-handler-notes
try {
$query = new Query();
$exists = $query->select(['id'])->from($this->sessionTable)->where(['id' => $id])->createCommand($this->db)->queryScalar();
$fields = $this->composeFields($id, $data);
if ($exists === false) {
$this->db->createCommand()->insert($this->sessionTable, $fields)->execute();
} else {
unset($fields['id']);
$this->db->createCommand()->update($this->sessionTable, $fields, ['id' => $id])->execute();
}
} catch (\Exception $e) {
$exception = ErrorHandler::convertExceptionToString($e);
// its too late to use Yii logging here
error_log($exception);
if (YII_DEBUG) {
echo $exception;
}
return false;
}
return true;
}