Migrate notes in upgrade database routine.

This commit is contained in:
James Cole 2017-10-03 10:41:29 +02:00
parent d1a6b37eb3
commit dd9528f531
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E

View File

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