From dd9528f531186d29570b63597577670fa0d5412c Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 3 Oct 2017 10:41:29 +0200 Subject: [PATCH] Migrate notes in upgrade database routine. --- app/Console/Commands/UpgradeDatabase.php | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/app/Console/Commands/UpgradeDatabase.php b/app/Console/Commands/UpgradeDatabase.php index 62fdc69d14..f04c9ddc21 100644 --- a/app/Console/Commands/UpgradeDatabase.php +++ b/app/Console/Commands/UpgradeDatabase.php @@ -20,9 +20,11 @@ use FireflyIII\Models\AccountMeta; use FireflyIII\Models\AccountType; use FireflyIII\Models\BudgetLimit; use FireflyIII\Models\LimitRepetition; +use FireflyIII\Models\Note; use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionJournal; +use FireflyIII\Models\TransactionJournalMeta; use FireflyIII\Models\TransactionType; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use Illuminate\Console\Command; @@ -76,6 +78,8 @@ class UpgradeDatabase extends Command $this->line('Updating currency information..'); $this->updateTransferCurrencies(); $this->updateOtherCurrencies(); + $this->line('Done updating currency information..'); + $this->migrateNotes(); $this->info('Firefly III database is up to date.'); return; @@ -281,6 +285,29 @@ class UpgradeDatabase extends Command ); } + /** + * Move all the journal_meta notes to their note object counter parts. + */ + private function migrateNotes(): void + { + $set = TransactionJournalMeta::whereName('notes')->get(); + /** @var TransactionJournalMeta $meta */ + foreach ($set as $meta) { + $journal = $meta->transactionJournal; + $note = $journal->notes()->first(); + if (is_null($note)) { + $note = new Note; + $note->noteable()->associate($journal); + } + + $note->text = $meta->data; + $note->save(); + Log::debug(sprintf('Migrated meta note #%d to Note #%d', $meta->id, $note->id)); + $meta->delete(); + + } + } + /** * This method makes sure that the transaction journal uses the currency given in the transaction.