From: Dan Brown Date: Tue, 31 Aug 2021 20:50:23 +0000 (+0100) Subject: Swapped injected db instance with facade X-Git-Tag: v21.08~1^2~3 X-Git-Url: http://source.bookstackapp.com/bookstack/commitdiff_plain/a641b4da2c08e9533a20174d7a3543694f6b7c4c Swapped injected db instance with facade Injected db instance was causing the DB connection to be made a lot earlier than desired or required. Swapped to a facade for now but ideally this extension of services needs to be cleaned up with a better approach in general. --- diff --git a/app/Auth/Access/UserTokenService.php b/app/Auth/Access/UserTokenService.php index 565dcb948..ffd828ab5 100644 --- a/app/Auth/Access/UserTokenService.php +++ b/app/Auth/Access/UserTokenService.php @@ -6,7 +6,7 @@ use BookStack\Auth\User; use BookStack\Exceptions\UserTokenExpiredException; use BookStack\Exceptions\UserTokenNotFoundException; use Carbon\Carbon; -use Illuminate\Database\Connection as Database; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; use stdClass; @@ -26,18 +26,6 @@ class UserTokenService */ protected $expiryTime = 24; - protected $db; - - /** - * UserTokenService constructor. - * - * @param Database $db - */ - public function __construct(Database $db) - { - $this->db = $db; - } - /** * Delete all email confirmations that belong to a user. * @@ -47,7 +35,7 @@ class UserTokenService */ public function deleteByUser(User $user) { - return $this->db->table($this->tokenTable) + return DB::table($this->tokenTable) ->where('user_id', '=', $user->id) ->delete(); } @@ -102,7 +90,7 @@ class UserTokenService protected function createTokenForUser(User $user): string { $token = $this->generateToken(); - $this->db->table($this->tokenTable)->insert([ + DB::table($this->tokenTable)->insert([ 'user_id' => $user->id, 'token' => $token, 'created_at' => Carbon::now(), @@ -121,7 +109,7 @@ class UserTokenService */ protected function tokenExists(string $token): bool { - return $this->db->table($this->tokenTable) + return DB::table($this->tokenTable) ->where('token', '=', $token)->exists(); } @@ -134,7 +122,7 @@ class UserTokenService */ protected function getEntryByToken(string $token) { - return $this->db->table($this->tokenTable) + return DB::table($this->tokenTable) ->where('token', '=', $token) ->first(); }