Skip to content

Commit

Permalink
now() throws error when using SQLite3
Browse files Browse the repository at this point in the history
  • Loading branch information
grimpirate authored Oct 16, 2024
1 parent 81e6289 commit ea225a1
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 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', $this->now(), 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', $this->now(), false)->update($updateData)) {
return $this->fail();
}

Expand Down Expand Up @@ -287,7 +287,7 @@ public function gc($max_lifetime)

return $this->db->table($this->table)->where(
'timestamp <',
"now() - INTERVAL {$interval}",
$this->now($interval),
false
)->delete() ? 1 : $this->fail();
}
Expand All @@ -304,4 +304,25 @@ protected function releaseLock(): bool
// Unsupported DB? Let the parent handle the simple version.
return parent::releaseLock();
}

/**
* 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
{
$DBDriver = service('settings')->get("Database.{$this->DBGroup}")['DBDriver'];

Check failure on line 315 in system/Session/Handlers/DatabaseHandler.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

Call to unknown service method 'settings'.

Check failure on line 315 in system/Session/Handlers/DatabaseHandler.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

Cannot call method get() on null.
return !is_null($interval)
? match($DBDriver)
{
'SQLite3' => "datetime('now', '-{$interval}')",
default => "now() - INTERVAL {$interval}",
}
: match($DBDriver)
{
'SQLite3' => "datetime('now')",
default => "now()",
};
}
}

0 comments on commit ea225a1

Please sign in to comment.