]> BookStack Code Mirror - bookstack/commitdiff
Swapped injected db instance with facade
authorDan Brown <redacted>
Tue, 31 Aug 2021 20:50:23 +0000 (21:50 +0100)
committerDan Brown <redacted>
Tue, 31 Aug 2021 20:50:23 +0000 (21:50 +0100)
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.

app/Auth/Access/UserTokenService.php

index 565dcb948b4caab36ee2056784d200241417fa27..ffd828ab5095194b8df7ab638a73980215095c52 100644 (file)
@@ -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();
     }