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.
This commit is contained in:
Dan Brown 2021-08-31 21:50:23 +01:00
parent 4f85ce02c6
commit a641b4da2c
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9

View 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();
}