Skip to content

Commit

Permalink
fix(core): prevent exceptions on session save
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalsem committed Jun 15, 2021
1 parent 91d4f03 commit 90345ba
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions engine/classes/Elgg/Http/DatabaseSessionHandler.php
Expand Up @@ -68,24 +68,23 @@ public function write($session_id, $session_data) {
return true;
}

$update = Update::table(self::TABLE_NAME);
$update->set('data', $update->param($session_data, ELGG_VALUE_STRING))
->set('ts', $update->param(time(), ELGG_VALUE_TIMESTAMP))
->where($update->compare('session', '=', $session_id, ELGG_VALUE_STRING));

if (!$this->db->updateData($update, true)) {
// update failed, try insert
$insert = Insert::intoTable(self::TABLE_NAME);
$insert->values([
'session' => $insert->param($session_id, ELGG_VALUE_STRING),
'data' => $insert->param($session_data, ELGG_VALUE_STRING),
'ts' => $insert->param($this->getCurrentTime()->getTimestamp(), ELGG_VALUE_TIMESTAMP),
]);
if ($this->read($session_id)) {
$update = Update::table(self::TABLE_NAME);
$update->set('data', $update->param($session_data, ELGG_VALUE_STRING))
->set('ts', $update->param(time(), ELGG_VALUE_TIMESTAMP))
->where($update->compare('session', '=', $session_id, ELGG_VALUE_STRING));

return $this->db->insertData($insert) !== false;
return $this->db->updateData($update);
}

return true;
$insert = Insert::intoTable(self::TABLE_NAME);
$insert->values([
'session' => $insert->param($session_id, ELGG_VALUE_STRING),
'data' => $insert->param($session_data, ELGG_VALUE_STRING),
'ts' => $insert->param($this->getCurrentTime()->getTimestamp(), ELGG_VALUE_TIMESTAMP),
]);

return $this->db->insertData($insert) !== false;
}

/**
Expand Down

0 comments on commit 90345ba

Please sign in to comment.