Skip to content

Firefly III: a personal finances manager

Verify currency data routine.

James Cole0e929602a801
diff --git a/app/Console/Commands/UpgradeDatabase.php b/app/Console/Commands/UpgradeDatabase.php
index 7a185d004b..654267b9d0 100644
--- a/app/Console/Commands/UpgradeDatabase.php
+++ b/app/Console/Commands/UpgradeDatabase.php
@@ -74,6 +74,7 @@ class UpgradeDatabase extends Command
$this->updateAccountCurrencies();
$this->updateJournalCurrencies();
$this->currencyInfoToTransactions();
+ $this->verifyCurrencyInfo();
$this->info('Firefly III database is up to date.');
}
@@ -386,4 +387,25 @@ class UpgradeDatabase extends Command
}
}
}
+
+ /**
+ *
+ */
+ private function verifyCurrencyInfo()
+ {
+ $count = 0;
+ $transactions = Transaction::get();
+ /** @var Transaction $transaction */
+ foreach ($transactions as $transaction) {
+ $currencyId = intval($transaction->transaction_currency_id);
+ $foreignId = intval($transaction->foreign_currency_id);
+ if ($currencyId === $foreignId) {
+ $transaction->foreign_currency_id = null;
+ $transaction->foreign_amount = null;
+ $transaction->save();
+ $count++;
+ }
+ }
+ $this->line(sprintf('Updated currency information for %d transactions', $count));
+ }
}