Skip to content

Firefly III: a personal finances manager

Clean up references to static Facade.

James Cole369839e01219
diff --git a/app/Api/V1/Controllers/PreferenceController.php b/app/Api/V1/Controllers/PreferenceController.php
index e7d40c0091..a954ef90ec 100644
--- a/app/Api/V1/Controllers/PreferenceController.php
+++ b/app/Api/V1/Controllers/PreferenceController.php
@@ -34,7 +34,6 @@ use League\Fractal\Manager;
use League\Fractal\Resource\Collection as FractalCollection;
use League\Fractal\Resource\Item;
use League\Fractal\Serializer\JsonApiSerializer;
-use Preferences;
/**
*
@@ -60,7 +59,7 @@ class PreferenceController extends Controller
];
$preferences = new Collection;
foreach ($available as $name) {
- $pref = Preferences::getForUser($user, $name);
+ $pref = app('preferences')->getForUser($user, $name);
if (null !== $pref) {
$preferences->push($pref);
}
@@ -130,7 +129,7 @@ class PreferenceController extends Controller
$newValue = 1 === (int)$data['data'];
break;
}
- $result = Preferences::set($preference->name, $newValue);
+ $result = app('preferences')->set($preference->name, $newValue);
// create some objects:
$manager = new Manager;
diff --git a/app/Console/Commands/CreateImport.php b/app/Console/Commands/CreateImport.php
index f9a8fb8633..8831fa56b9 100644
--- a/app/Console/Commands/CreateImport.php
+++ b/app/Console/Commands/CreateImport.php
@@ -34,7 +34,6 @@ use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Console\Command;
use Log;
-use Preferences;
/**
* Class CreateImport.
@@ -232,7 +231,7 @@ class CreateImport extends Command
}
}
// clear cache for user:
- Preferences::setForUser($user, 'lastActivity', microtime());
+ app('preferences')->setForUser($user, 'lastActivity', microtime());
return 0;
}
diff --git a/app/Console/Commands/UpgradeDatabase.php b/app/Console/Commands/UpgradeDatabase.php
index 37f72b8db4..5c328ac60f 100644
--- a/app/Console/Commands/UpgradeDatabase.php
+++ b/app/Console/Commands/UpgradeDatabase.php
@@ -54,7 +54,6 @@ use Illuminate\Console\Command;
use Illuminate\Database\QueryException;
use Illuminate\Support\Collection;
use Log;
-use Preferences;
use Schema;
use UnexpectedValueException;
@@ -110,10 +109,10 @@ class UpgradeDatabase extends Command
{
foreach (User::get() as $user) {
/** @var Preference $lang */
- $lang = Preferences::getForUser($user, 'language', 'en_US');
+ $lang = app('preferences')->getForUser($user, 'language', 'en_US');
$groupName = (string)trans('firefly.rulegroup_for_bills_title', [], $lang->data);
$ruleGroup = $user->ruleGroups()->where('title', $groupName)->first();
- $currencyPreference = Preferences::getForUser($user, 'currencyPreference', config('firefly.default_currency', 'EUR'));
+ $currencyPreference = app('preferences')->getForUser($user, 'currencyPreference', config('firefly.default_currency', 'EUR'));
if (null === $currencyPreference) {
$this->error('User has no currency preference. Impossible.');
@@ -294,7 +293,7 @@ class UpgradeDatabase extends Command
function (Account $account) use ($repository) {
$repository->setUser($account->user);
// get users preference, fall back to system pref.
- $defaultCurrencyCode = Preferences::getForUser($account->user, 'currencyPreference', config('firefly.default_currency', 'EUR'))->data;
+ $defaultCurrencyCode = app('preferences')->getForUser($account->user, 'currencyPreference', config('firefly.default_currency', 'EUR'))->data;
$defaultCurrency = TransactionCurrency::where('code', $defaultCurrencyCode)->first();
$accountCurrency = (int)$repository->getMetaValue($account, 'currency_id');
$openingBalance = $account->getOpeningBalance();
diff --git a/app/Console/Commands/VerifiesAccessToken.php b/app/Console/Commands/VerifiesAccessToken.php
index b82beee8ab..857aeaa30b 100644
--- a/app/Console/Commands/VerifiesAccessToken.php
+++ b/app/Console/Commands/VerifiesAccessToken.php
@@ -25,7 +25,6 @@ namespace FireflyIII\Console\Commands;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Log;
-use Preferences;
/**
* Trait VerifiesAccessToken.
@@ -61,7 +60,7 @@ trait VerifiesAccessToken
return false;
}
- $accessToken = Preferences::getForUser($user, 'access_token', null);
+ $accessToken = app('preferences')->getForUser($user, 'access_token', null);
if (null === $accessToken) {
Log::error(sprintf('User #%d has no access token, so cannot access command line options.', $userId));
diff --git a/app/Console/Commands/VerifyDatabase.php b/app/Console/Commands/VerifyDatabase.php
index 8ca22eef33..dc43c373bb 100644
--- a/app/Console/Commands/VerifyDatabase.php
+++ b/app/Console/Commands/VerifyDatabase.php
@@ -42,7 +42,6 @@ use Illuminate\Console\Command;
use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Database\Eloquent\Builder;
use Log;
-use Preferences;
use Schema;
use stdClass;
@@ -106,10 +105,10 @@ class VerifyDatabase extends Command
$users = User::get();
/** @var User $user */
foreach ($users as $user) {
- $pref = Preferences::getForUser($user, 'access_token', null);
+ $pref = app('preferences')->getForUser($user, 'access_token', null);
if (null === $pref) {
$token = $user->generateAccessToken();
- Preferences::setForUser($user, 'access_token', $token);
+ app('preferences')->setForUser($user, 'access_token', $token);
$this->line(sprintf('Generated access token for user %s', $user->email));
++$count;
}
diff --git a/app/Handlers/Events/UserEventHandler.php b/app/Handlers/Events/UserEventHandler.php
index 530562ab60..e40ff67b55 100644
--- a/app/Handlers/Events/UserEventHandler.php
+++ b/app/Handlers/Events/UserEventHandler.php
@@ -36,7 +36,6 @@ use FireflyIII\User;
use Illuminate\Auth\Events\Login;
use Log;
use Mail;
-use Preferences;
/**
* Class UserEventHandler.
@@ -138,7 +137,7 @@ class UserEventHandler
$oldEmail = $event->oldEmail;
$user = $event->user;
$ipAddress = $event->ipAddress;
- $token = Preferences::getForUser($user, 'email_change_confirm_token', 'invalid');
+ $token = app('preferences')->getForUser($user, 'email_change_confirm_token', 'invalid');
$uri = route('profile.confirm-email-change', [$token->data]);
try {
Mail::to($newEmail)->send(new ConfirmEmailChangeMail($newEmail, $oldEmail, $uri, $ipAddress));
@@ -164,7 +163,7 @@ class UserEventHandler
$oldEmail = $event->oldEmail;
$user = $event->user;
$ipAddress = $event->ipAddress;
- $token = Preferences::getForUser($user, 'email_change_undo_token', 'invalid');
+ $token = app('preferences')->getForUser($user, 'email_change_undo_token', 'invalid');
$uri = route('profile.undo-email-change', [$token->data, hash('sha256', $oldEmail)]);
try {
Mail::to($oldEmail)->send(new UndoEmailChangeMail($newEmail, $oldEmail, $uri, $ipAddress));
diff --git a/app/Helpers/FiscalHelper.php b/app/Helpers/FiscalHelper.php
index b34de8da9f..b3641939bc 100644
--- a/app/Helpers/FiscalHelper.php
+++ b/app/Helpers/FiscalHelper.php
@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Helpers;
use Carbon\Carbon;
-use Preferences;
/**
* Class FiscalHelper.
@@ -38,7 +37,7 @@ class FiscalHelper implements FiscalHelperInterface
*/
public function __construct()
{
- $this->useCustomFiscalYear = Preferences::get('customFiscalYear', false)->data;
+ $this->useCustomFiscalYear = app('preferences')->get('customFiscalYear', false)->data;
}
/**
@@ -72,7 +71,7 @@ class FiscalHelper implements FiscalHelperInterface
// get start mm-dd. Then create a start date in the year passed.
$startDate = clone $date;
if (true === $this->useCustomFiscalYear) {
- $prefStartStr = Preferences::get('fiscalYearStart', '01-01')->data;
+ $prefStartStr = app('preferences')->get('fiscalYearStart', '01-01')->data;
[$mth, $day] = explode('-', $prefStartStr);
$startDate->month((int)$mth)->day((int)$day);
diff --git a/app/Models/AccountType.php b/app/Models/AccountType.php
index c4a1c4d19e..2a0c2fa7ca 100644
--- a/app/Models/AccountType.php
+++ b/app/Models/AccountType.php
@@ -30,7 +30,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
*
* @property string $type
* @method whereType(string $type)
- * @property int $id
+ * @property int $id
*
*/
class AccountType extends Model
diff --git a/app/Models/Bill.php b/app/Models/Bill.php
index 668f8f0d2d..73b5ad5426 100644
--- a/app/Models/Bill.php
+++ b/app/Models/Bill.php
@@ -50,7 +50,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property int $skip
* @property bool $automatch
* @property User $user
- * @property string $match
+ * @property string $match
*/
class Bill extends Model
{
diff --git a/app/Models/Budget.php b/app/Models/Budget.php
index eb46d21f79..1ee29963e0 100644
--- a/app/Models/Budget.php
+++ b/app/Models/Budget.php
@@ -32,10 +32,10 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class Budget.
*
- * @property int $id
- * @property string $name
- * @property bool $active
- * @property int $user_id
+ * @property int $id
+ * @property string $name
+ * @property bool $active
+ * @property int $user_id
* @property-read string $email
*/
class Budget extends Model
diff --git a/app/Models/ImportJob.php b/app/Models/ImportJob.php
index 58256cd9a5..29715e55ba 100644
--- a/app/Models/ImportJob.php
+++ b/app/Models/ImportJob.php
@@ -40,7 +40,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property string $file_type
* @property int $tag_id
* @property Tag $tag
- * @property array $errors
+ * @property array $errors
*/
class ImportJob extends Model
{
diff --git a/app/Models/Note.php b/app/Models/Note.php
index 59d786d642..487dca8146 100644
--- a/app/Models/Note.php
+++ b/app/Models/Note.php
@@ -34,7 +34,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @property Carbon $updated_at
* @property string $text
* @property string $title
- * @property int $noteable_id
+ * @property int $noteable_id
*/
class Note extends Model
{
diff --git a/app/Models/RecurrenceTransaction.php b/app/Models/RecurrenceTransaction.php
index bea0b38ff6..a38f0a09b6 100644
--- a/app/Models/RecurrenceTransaction.php
+++ b/app/Models/RecurrenceTransaction.php
@@ -73,7 +73,7 @@ class RecurrenceTransaction extends Model
*/
public function destinationAccount(): BelongsTo
{
- return $this->belongsTo(Account::class,'destination_id');
+ return $this->belongsTo(Account::class, 'destination_id');
}
/**
@@ -109,7 +109,7 @@ class RecurrenceTransaction extends Model
*/
public function sourceAccount(): BelongsTo
{
- return $this->belongsTo(Account::class,'source_id');
+ return $this->belongsTo(Account::class, 'source_id');
}
/**
diff --git a/app/Models/RuleGroup.php b/app/Models/RuleGroup.php
index 142ec71bda..bc3ba014fe 100644
--- a/app/Models/RuleGroup.php
+++ b/app/Models/RuleGroup.php
@@ -32,14 +32,14 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class RuleGroup.
*
- * @property bool $active
- * @property User $user
- * @property Carbon $created_at
- * @property Carbon $updated_at
- * @property string $title
- * @property string $text
- * @property int $id
- * @property int $order
+ * @property bool $active
+ * @property User $user
+ * @property Carbon $created_at
+ * @property Carbon $updated_at
+ * @property string $title
+ * @property string $text
+ * @property int $id
+ * @property int $order
* @property Collection $rules
*/
class RuleGroup extends Model
diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php
index 25df6439cc..dc00497da4 100644
--- a/app/Models/TransactionJournal.php
+++ b/app/Models/TransactionJournal.php
@@ -34,7 +34,6 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Collection;
use Log;
-use Preferences;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
@@ -396,7 +395,7 @@ class TransactionJournal extends Model
}
$entry->data = $value;
$entry->save();
- Preferences::mark();
+ app('preferences')->mark();
return $entry;
}
diff --git a/app/Models/TransactionJournalMeta.php b/app/Models/TransactionJournalMeta.php
index 5f12ed1567..0842e5d2d1 100644
--- a/app/Models/TransactionJournalMeta.php
+++ b/app/Models/TransactionJournalMeta.php
@@ -32,8 +32,8 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @property string $name
* @property int $transaction_journal_id
* @property TransactionJournal $transactionJournal
- * @property string $data
- * @property int $id
+ * @property string $data
+ * @property int $id
*/
class TransactionJournalMeta extends Model
{
diff --git a/app/Repositories/Currency/CurrencyRepository.php b/app/Repositories/Currency/CurrencyRepository.php
index f754c1bf0a..f3a0ea12d1 100644
--- a/app/Repositories/Currency/CurrencyRepository.php
+++ b/app/Repositories/Currency/CurrencyRepository.php
@@ -32,7 +32,6 @@ use FireflyIII\Services\Internal\Update\CurrencyUpdateService;
use FireflyIII\User;
use Illuminate\Support\Collection;
use Log;
-use Preferences;
/**
* Class CurrencyRepository.
@@ -66,7 +65,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
}
// is the default currency for the user or the system
- $defaultCode = Preferences::getForUser($this->user, 'currencyPreference', config('firefly.default_currency', 'EUR'))->data;
+ $defaultCode = app('preferences')->getForUser($this->user, 'currencyPreference', config('firefly.default_currency', 'EUR'))->data;
if ($currency->code === $defaultCode) {
return false;
}
diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php
index f3397e1d6b..e79df9d0a5 100644
--- a/app/Repositories/Journal/JournalRepository.php
+++ b/app/Repositories/Journal/JournalRepository.php
@@ -42,7 +42,6 @@ use FireflyIII\User;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;
use Log;
-use Preferences;
/**
* Class JournalRepository.
@@ -107,7 +106,7 @@ class JournalRepository implements JournalRepositoryInterface
$journal->save();
}
- Preferences::mark();
+ app('preferences')->mark();
return new MessageBag;
}
diff --git a/app/Repositories/LinkType/LinkTypeRepositoryInterface.php b/app/Repositories/LinkType/LinkTypeRepositoryInterface.php
index eb584560dc..a43ddaaefd 100644
--- a/app/Repositories/LinkType/LinkTypeRepositoryInterface.php
+++ b/app/Repositories/LinkType/LinkTypeRepositoryInterface.php
@@ -63,13 +63,6 @@ interface LinkTypeRepositoryInterface
*/
public function find(int $id): LinkType;
- /**
- * Set the user for this instance.
- *
- * @param User $user
- */
- public function setUser(User $user): void;
-
/**
* Find link type by name.
*
@@ -128,6 +121,13 @@ interface LinkTypeRepositoryInterface
*/
public function getLinks(TransactionJournal $journal): Collection;
+ /**
+ * Set the user for this instance.
+ *
+ * @param User $user
+ */
+ public function setUser(User $user): void;
+
/**
* @param array $data
*
diff --git a/app/Repositories/User/UserRepository.php b/app/Repositories/User/UserRepository.php
index 8b26d88ef5..95df481da5 100644
--- a/app/Repositories/User/UserRepository.php
+++ b/app/Repositories/User/UserRepository.php
@@ -27,7 +27,6 @@ use FireflyIII\Models\Role;
use FireflyIII\User;
use Illuminate\Support\Collection;
use Log;
-use Preferences;
/**
* Class UserRepository.
@@ -73,12 +72,12 @@ class UserRepository implements UserRepositoryInterface
$oldEmail = $user->email;
// save old email as pref
- Preferences::setForUser($user, 'previous_email_latest', $oldEmail);
- Preferences::setForUser($user, 'previous_email_' . date('Y-m-d-H-i-s'), $oldEmail);
+ app('preferences')->setForUser($user, 'previous_email_latest', $oldEmail);
+ app('preferences')->setForUser($user, 'previous_email_' . date('Y-m-d-H-i-s'), $oldEmail);
// set undo and confirm token:
- Preferences::setForUser($user, 'email_change_undo_token', (string)bin2hex(random_bytes(16)));
- Preferences::setForUser($user, 'email_change_confirm_token', (string)bin2hex(random_bytes(16)));
+ app('preferences')->setForUser($user, 'email_change_undo_token', (string)bin2hex(random_bytes(16)));
+ app('preferences')->setForUser($user, 'email_change_confirm_token', (string)bin2hex(random_bytes(16)));
// update user
$user->email = $newEmail;
@@ -222,8 +221,8 @@ class UserRepository implements UserRepositoryInterface
$return = [];
// two factor:
- $is2faEnabled = Preferences::getForUser($user, 'twoFactorAuthEnabled', false)->data;
- $has2faSecret = null !== Preferences::getForUser($user, 'twoFactorAuthSecret');
+ $is2faEnabled = app('preferences')->getForUser($user, 'twoFactorAuthEnabled', false)->data;
+ $has2faSecret = null !== app('preferences')->getForUser($user, 'twoFactorAuthSecret');
$return['has_2fa'] = false;
if ($is2faEnabled && $has2faSecret) {
$return['has_2fa'] = true;
@@ -329,8 +328,8 @@ class UserRepository implements UserRepositoryInterface
$oldEmail = $user->email;
// save old email as pref
- Preferences::setForUser($user, 'admin_previous_email_latest', $oldEmail);
- Preferences::setForUser($user, 'admin_previous_email_' . date('Y-m-d-H-i-s'), $oldEmail);
+ app('preferences')->setForUser($user, 'admin_previous_email_latest', $oldEmail);
+ app('preferences')->setForUser($user, 'admin_previous_email_' . date('Y-m-d-H-i-s'), $oldEmail);
$user->email = $newEmail;
$user->save();
diff --git a/app/Support/Import/Information/BunqInformation.php b/app/Support/Import/Information/BunqInformation.php
index afd170c1b5..33dbf1a273 100644
--- a/app/Support/Import/Information/BunqInformation.php
+++ b/app/Support/Import/Information/BunqInformation.php
@@ -123,9 +123,9 @@ class BunqInformation implements InformationInterface
private function closeSession(SessionToken $sessionToken): void
{
Log::debug('Going to close session');
- $apiKey = Preferences::getForUser($this->user, 'bunq_api_key')->data;
- $serverPublicKey = Preferences::getForUser($this->user, 'bunq_server_public_key')->data;
- $privateKey = Preferences::getForUser($this->user, 'bunq_private_key')->data;
+ $apiKey = app('preferences')->getForUser($this->user, 'bunq_api_key')->data;
+ $serverPublicKey = app('preferences')->getForUser($this->user, 'bunq_server_public_key')->data;
+ $privateKey = app('preferences')->getForUser($this->user, 'bunq_private_key')->data;
$request = new DeleteDeviceSessionRequest();
$request->setSecret($apiKey);
$request->setPrivateKey($privateKey);
@@ -144,9 +144,9 @@ class BunqInformation implements InformationInterface
*/
private function getMonetaryAccounts(SessionToken $sessionToken, int $userId): Collection
{
- $apiKey = Preferences::getForUser($this->user, 'bunq_api_key')->data;
- $serverPublicKey = Preferences::getForUser($this->user, 'bunq_server_public_key')->data;
- $privateKey = Preferences::getForUser($this->user, 'bunq_private_key')->data;
+ $apiKey = app('preferences')->getForUser($this->user, 'bunq_api_key')->data;
+ $serverPublicKey = app('preferences')->getForUser($this->user, 'bunq_server_public_key')->data;
+ $privateKey = app('preferences')->getForUser($this->user, 'bunq_private_key')->data;
$request = new ListMonetaryAccountRequest;
$request->setSessionToken($sessionToken);
@@ -168,9 +168,9 @@ class BunqInformation implements InformationInterface
*/
private function getUserInformation(SessionToken $sessionToken): int
{
- $apiKey = Preferences::getForUser($this->user, 'bunq_api_key')->data;
- $serverPublicKey = Preferences::getForUser($this->user, 'bunq_server_public_key')->data;
- $privateKey = Preferences::getForUser($this->user, 'bunq_private_key')->data;
+ $apiKey = app('preferences')->getForUser($this->user, 'bunq_api_key')->data;
+ $serverPublicKey = app('preferences')->getForUser($this->user, 'bunq_server_public_key')->data;
+ $privateKey = app('preferences')->getForUser($this->user, 'bunq_private_key')->data;
$request = new ListUserRequest;
$request->setSessionToken($sessionToken);
$request->setSecret($apiKey);
@@ -196,10 +196,10 @@ class BunqInformation implements InformationInterface
private function startSession(): SessionToken
{
Log::debug('Now in startSession.');
- $apiKey = Preferences::getForUser($this->user, 'bunq_api_key')->data;
- $serverPublicKey = Preferences::getForUser($this->user, 'bunq_server_public_key')->data;
- $privateKey = Preferences::getForUser($this->user, 'bunq_private_key')->data;
- $installationToken = Preferences::getForUser($this->user, 'bunq_installation_token')->data;
+ $apiKey = app('preferences')->getForUser($this->user, 'bunq_api_key')->data;
+ $serverPublicKey = app('preferences')->getForUser($this->user, 'bunq_server_public_key')->data;
+ $privateKey = app('preferences')->getForUser($this->user, 'bunq_private_key')->data;
+ $installationToken = app('preferences')->getForUser($this->user, 'bunq_installation_token')->data;
$request = new DeviceSessionRequest();
$request->setSecret($apiKey);
$request->setServerPublicKey($serverPublicKey);