mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Upgrade fix for Softaculous.
This commit is contained in:
parent
7610d9e0db
commit
38c79c3dc4
@ -268,11 +268,11 @@ class UpgradeDatabase extends Command
|
|||||||
if (!Schema::hasTable('transaction_journals')) {
|
if (!Schema::hasTable('transaction_journals')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$subQuery = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
$subQuery = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||||
->whereNull('transaction_journals.deleted_at')
|
->whereNull('transaction_journals.deleted_at')
|
||||||
->whereNull('transactions.deleted_at')
|
->whereNull('transactions.deleted_at')
|
||||||
->groupBy(['transaction_journals.id'])
|
->groupBy(['transaction_journals.id'])
|
||||||
->select(['transaction_journals.id', DB::raw('COUNT(transactions.id) AS t_count')]);
|
->select(['transaction_journals.id', DB::raw('COUNT(transactions.id) AS t_count')]);
|
||||||
/** @noinspection PhpStrictTypeCheckingInspection */
|
/** @noinspection PhpStrictTypeCheckingInspection */
|
||||||
$result = DB::table(DB::raw('(' . $subQuery->toSql() . ') AS derived'))
|
$result = DB::table(DB::raw('(' . $subQuery->toSql() . ') AS derived'))
|
||||||
->mergeBindings($subQuery->getQuery())
|
->mergeBindings($subQuery->getQuery())
|
||||||
@ -294,23 +294,38 @@ class UpgradeDatabase extends Command
|
|||||||
*/
|
*/
|
||||||
public function updateAccountCurrencies(): void
|
public function updateAccountCurrencies(): void
|
||||||
{
|
{
|
||||||
|
Log::debug('Now in updateAccountCurrencies()');
|
||||||
|
|
||||||
|
$defaultConfig = (string)config('firefly.default_currency', 'EUR');
|
||||||
|
Log::debug(sprintf('System default currency is "%s"', $defaultConfig));
|
||||||
|
|
||||||
$accounts = Account::leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
$accounts = Account::leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||||
->whereIn('account_types.type', [AccountType::DEFAULT, AccountType::ASSET])->get(['accounts.*']);
|
->whereIn('account_types.type', [AccountType::DEFAULT, AccountType::ASSET])->get(['accounts.*']);
|
||||||
/** @var AccountRepositoryInterface $repository */
|
/** @var AccountRepositoryInterface $repository */
|
||||||
$repository = app(AccountRepositoryInterface::class);
|
$repository = app(AccountRepositoryInterface::class);
|
||||||
$accounts->each(
|
$accounts->each(
|
||||||
function (Account $account) use ($repository) {
|
function (Account $account) use ($repository, $defaultConfig) {
|
||||||
$repository->setUser($account->user);
|
$repository->setUser($account->user);
|
||||||
// get users preference, fall back to system pref.
|
// get users preference, fall back to system pref.
|
||||||
$defaultCurrencyCode = app('preferences')->getForUser($account->user, 'currencyPreference', config('firefly.default_currency', 'EUR'))->data;
|
|
||||||
$defaultCurrency = TransactionCurrency::where('code', $defaultCurrencyCode)->first();
|
// expand and debug routine.
|
||||||
$accountCurrency = (int)$repository->getMetaValue($account, 'currency_id');
|
$defaultCurrencyCode = app('preferences')->getForUser($account->user, 'currencyPreference', $defaultConfig)->data;
|
||||||
$openingBalance = $account->getOpeningBalance();
|
Log::debug(sprintf('Default currency code is "%s"', var_export($defaultCurrencyCode, true)));
|
||||||
$obCurrency = (int)$openingBalance->transaction_currency_id;
|
if (!is_string($defaultCurrencyCode)) {
|
||||||
|
$defaultCurrencyCode = $defaultConfig;
|
||||||
|
Log::debug(sprintf('Default currency code is not a string, now set to "%s"', $defaultCurrencyCode));
|
||||||
|
}
|
||||||
|
$defaultCurrency = TransactionCurrency::where('code', $defaultCurrencyCode)->first();
|
||||||
|
$accountCurrency = (int)$repository->getMetaValue($account, 'currency_id');
|
||||||
|
$openingBalance = $account->getOpeningBalance();
|
||||||
|
$obCurrency = (int)$openingBalance->transaction_currency_id;
|
||||||
|
|
||||||
if (null === $defaultCurrency) {
|
if (null === $defaultCurrency) {
|
||||||
throw new UnexpectedValueException('The default currency is NULL, and this is more or less impossible.');
|
throw new UnexpectedValueException(sprintf('User has a preference for "%s", but this currency does not exist.', $defaultCurrencyCode));
|
||||||
}
|
}
|
||||||
|
Log::debug(
|
||||||
|
sprintf('Found default currency #%d (%s) while searching for "%s"', $defaultCurrency->id, $defaultCurrency->code, $defaultCurrencyCode)
|
||||||
|
);
|
||||||
|
|
||||||
// both 0? set to default currency:
|
// both 0? set to default currency:
|
||||||
if (0 === $accountCurrency && 0 === $obCurrency) {
|
if (0 === $accountCurrency && 0 === $obCurrency) {
|
||||||
|
Loading…
Reference in New Issue
Block a user