Move notes for attachments to different object. This sacrifices the original notes.

This commit is contained in:
James Cole
2018-03-19 15:28:35 +01:00
parent 6a1d39d5f8
commit 909f72e6be
9 changed files with 144 additions and 31 deletions

View File

@@ -26,6 +26,7 @@ use DB;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Attachment;
use FireflyIII\Models\Note;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency;
@@ -86,6 +87,7 @@ class UpgradeDatabase extends Command
$this->updateOtherCurrencies();
$this->line('Done updating currency information..');
$this->migrateNotes();
$this->migrateAttachmentData();
$this->info('Firefly III database is up to date.');
return;
@@ -281,6 +283,38 @@ class UpgradeDatabase extends Command
}
}
/**
* Move the description of each attachment (when not NULL) to the notes or to a new note object
* for all attachments.
*/
private function migrateAttachmentData(): void
{
$attachments = Attachment::get();
/** @var Attachment $att */
foreach ($attachments as $att) {
// move description:
$description = strval($att->description);
if (strlen($description) > 0) {
// find or create note:
$note = $att->notes()->first();
if (is_null($note)) {
$note = new Note;
$note->noteable()->associate($att);
}
$note->text = $description;
$note->save();
// clear description:
$att->description = '';
$att->save();
Log::debug(sprintf('Migrated attachment #%s description to note #%d', $att->id, $note->id));
}
}
}
/**
* Move all the journal_meta notes to their note object counter parts.
*