mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Database upgrade routine.
This commit is contained in:
parent
0868aac750
commit
d37b46effc
@ -32,6 +32,7 @@ use Illuminate\Database\QueryException;
|
|||||||
use Log;
|
use Log;
|
||||||
use Preferences;
|
use Preferences;
|
||||||
use Schema;
|
use Schema;
|
||||||
|
use Steam;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class UpgradeDatabase
|
* Class UpgradeDatabase
|
||||||
@ -72,9 +73,54 @@ class UpgradeDatabase extends Command
|
|||||||
$this->repairPiggyBanks();
|
$this->repairPiggyBanks();
|
||||||
$this->updateAccountCurrencies();
|
$this->updateAccountCurrencies();
|
||||||
$this->updateJournalCurrencies();
|
$this->updateJournalCurrencies();
|
||||||
|
$this->currencyInfoToTransactions();
|
||||||
$this->info('Firefly III database is up to date.');
|
$this->info('Firefly III database is up to date.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves the currency id info to the transaction instead of the journal.
|
||||||
|
*/
|
||||||
|
private function currencyInfoToTransactions()
|
||||||
|
{
|
||||||
|
$count = 0;
|
||||||
|
$expanded = 0;
|
||||||
|
$set = TransactionJournal::with('transactions')->get();
|
||||||
|
/** @var TransactionJournal $journal */
|
||||||
|
foreach ($set as $journal) {
|
||||||
|
/** @var Transaction $transaction */
|
||||||
|
foreach ($journal->transactions as $transaction) {
|
||||||
|
if (is_null($transaction->transaction_currency_id)) {
|
||||||
|
$transaction->transaction_currency_id = $journal->transaction_currency_id;
|
||||||
|
$transaction->save();
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// read and use the foreign amounts when present.
|
||||||
|
if ($journal->hasMeta('foreign_amount')) {
|
||||||
|
$amount = Steam::positive($journal->getMeta('foreign_amount'));
|
||||||
|
|
||||||
|
// update both transactions:
|
||||||
|
foreach ($journal->transactions as $transaction) {
|
||||||
|
$transaction->foreign_amount = $amount;
|
||||||
|
if (bccomp($transaction->amount, '0') === -1) {
|
||||||
|
// update with negative amount:
|
||||||
|
$transaction->foreign_amount = bcmul($amount, '-1');
|
||||||
|
}
|
||||||
|
// set foreign currency id:
|
||||||
|
$transaction->foreign_currency_id = intval($journal->getMeta('foreign_currency_id'));
|
||||||
|
$transaction->save();
|
||||||
|
}
|
||||||
|
$journal->deleteMeta('foreign_amount');
|
||||||
|
$journal->deleteMeta('foreign_currency_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->line(sprintf('Updated currency information for %d transactions', $count));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Migrate budget repetitions to new format.
|
* Migrate budget repetitions to new format.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user