Clean up references to static Facade.

This commit is contained in:
James Cole 2018-07-15 09:27:38 +02:00
parent 8fde16422e
commit 369839e012
21 changed files with 64 additions and 75 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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();

View File

@ -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));

View File

@ -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;
}

View File

@ -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));

View File

@ -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);

View File

@ -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

View File

@ -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
{

View File

@ -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

View File

@ -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
{

View File

@ -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
{

View File

@ -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');
}
/**

View File

@ -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

View File

@ -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;
}

View File

@ -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
{

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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
*

View File

@ -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();

View File

@ -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);