mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-17 01:42:19 +00:00
Migrate notes in upgrade database routine.
This commit is contained in:
@@ -20,9 +20,11 @@ use FireflyIII\Models\AccountMeta;
|
|||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\BudgetLimit;
|
use FireflyIII\Models\BudgetLimit;
|
||||||
use FireflyIII\Models\LimitRepetition;
|
use FireflyIII\Models\LimitRepetition;
|
||||||
|
use FireflyIII\Models\Note;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
|
use FireflyIII\Models\TransactionJournalMeta;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
@@ -76,6 +78,8 @@ class UpgradeDatabase extends Command
|
|||||||
$this->line('Updating currency information..');
|
$this->line('Updating currency information..');
|
||||||
$this->updateTransferCurrencies();
|
$this->updateTransferCurrencies();
|
||||||
$this->updateOtherCurrencies();
|
$this->updateOtherCurrencies();
|
||||||
|
$this->line('Done updating currency information..');
|
||||||
|
$this->migrateNotes();
|
||||||
$this->info('Firefly III database is up to date.');
|
$this->info('Firefly III database is up to date.');
|
||||||
|
|
||||||
return;
|
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.
|
* This method makes sure that the transaction journal uses the currency given in the transaction.
|
||||||
|
Reference in New Issue
Block a user