Skip to content

Commit

Permalink
Use CURRENT_TIMESTAMP
Browse files Browse the repository at this point in the history
  • Loading branch information
grimpirate authored Oct 16, 2024
1 parent 5d5d946 commit b36d4be
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions system/Session/Handlers/DatabaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function write($id, $data): bool
'data' => $this->prepareData($data),
];

if (! $this->db->table($this->table)->set('timestamp', $this->now(), false)->insert($insertData)) {
if (! $this->db->table($this->table)->set('timestamp', 'CURRENT_TIMESTAMP', false)->insert($insertData)) {
return $this->fail();
}

Expand All @@ -218,7 +218,7 @@ public function write($id, $data): bool
$updateData['data'] = $this->prepareData($data);
}

if (! $builder->set('timestamp', $this->now(), false)->update($updateData)) {
if (! $builder->set('timestamp', 'CURRENT_TIMESTAMP', false)->update($updateData)) {
return $this->fail();
}

Expand Down Expand Up @@ -307,20 +307,13 @@ protected function releaseLock(): bool

/**
* Determines which NOW function to use based on DBDriver
*
*
* @param string $interval Amount of time to subtract from NOW
*/
private function now($interval = null): string
private function now($interval): string
{
$DBDriver = config(Database::class)->{$this->DBGroup}['DBDriver'];
return null === $interval
? match($DBDriver)
{
'SQLite3' => "datetime('now')",
default => "now()",
}
: match($DBDriver)
{
return match($DBDriver) {
'SQLite3' => "datetime('now', '-{$interval}')",
default => "now() - INTERVAL {$interval}",
};
Expand Down

0 comments on commit b36d4be

Please sign in to comment.