Skip to content

Commit

Permalink
now() throws error when using SQLite3
Browse files Browse the repository at this point in the history
Use config instead of settings

Use CURRENT_TIMESTAMP

Strict parameter type

Lint fix

Lint fix

Removed unneeded functions/variables
  • Loading branch information
grimpirate committed Oct 16, 2024
1 parent 81e6289 commit 251ab95
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 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', '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', 'now()', false)->update($updateData)) {
if (! $builder->set('timestamp', 'CURRENT_TIMESTAMP', false)->update($updateData)) {
return $this->fail();
}

Expand Down Expand Up @@ -282,12 +282,12 @@ public function destroy($id): bool
#[ReturnTypeWillChange]
public function gc($max_lifetime)
{
$separator = ' ';
$interval = implode($separator, ['', "{$max_lifetime} second", '']);

return $this->db->table($this->table)->where(
'timestamp <',
"now() - INTERVAL {$interval}",
match (config(Database::class)->{$this->DBGroup}['DBDriver']) {
'SQLite3' => "datetime('now', '-{$max_lifetime} second')",
default => "now() - INTERVAL {$max_lifetime} second",
},
false
)->delete() ? 1 : $this->fail();
}
Expand Down

0 comments on commit 251ab95

Please sign in to comment.