Centralize the current-timestamp SQL expression
"strftime('%Y-%m-%dT%H:%M:%SZ', 'now')" was a private nowExpr()
method copy-pasted identically in CardRepository, CardStatusRepository
and ProjectRepository, and inlined as a raw literal directly in
PasskeyRepository, WebAuthnChallengeRepository, UserRepository and
EmailVerificationRepository -- 7 files, ~12 occurrences of the same
string. Now one Database::nowExpr() static method (Support/Database
already being the natural home for SQLite-specific concerns), used
everywhere a repository sets a timestamp explicitly.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Support\Database;
|
||||
use PDO;
|
||||
use PDOException;
|
||||
|
||||
@@ -88,10 +89,9 @@ final class UserRepository
|
||||
|
||||
public function markEmailVerified(int $id): void
|
||||
{
|
||||
$now = Database::nowExpr();
|
||||
$this->pdo->prepare(
|
||||
"UPDATE users SET email_verified_at = strftime('%Y-%m-%dT%H:%M:%SZ', 'now'),
|
||||
updated_at = strftime('%Y-%m-%dT%H:%M:%SZ', 'now')
|
||||
WHERE id = :id"
|
||||
"UPDATE users SET email_verified_at = {$now}, updated_at = {$now} WHERE id = :id"
|
||||
)->execute(['id' => $id]);
|
||||
}
|
||||
|
||||
@@ -100,18 +100,16 @@ final class UserRepository
|
||||
*/
|
||||
public function updateEmail(int $id, string $email): void
|
||||
{
|
||||
$now = Database::nowExpr();
|
||||
$this->pdo->prepare(
|
||||
"UPDATE users SET email = :email,
|
||||
email_verified_at = strftime('%Y-%m-%dT%H:%M:%SZ', 'now'),
|
||||
updated_at = strftime('%Y-%m-%dT%H:%M:%SZ', 'now')
|
||||
WHERE id = :id"
|
||||
"UPDATE users SET email = :email, email_verified_at = {$now}, updated_at = {$now} WHERE id = :id"
|
||||
)->execute(['email' => $email, 'id' => $id]);
|
||||
}
|
||||
|
||||
public function markVerificationEmailSent(int $id): void
|
||||
{
|
||||
$this->pdo->prepare(
|
||||
"UPDATE users SET verification_email_sent_at = strftime('%Y-%m-%dT%H:%M:%SZ', 'now') WHERE id = :id"
|
||||
'UPDATE users SET verification_email_sent_at = ' . Database::nowExpr() . ' WHERE id = :id'
|
||||
)->execute(['id' => $id]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user