Skip to content

Firefly III: a personal finances manager

Create link types when they do not exist in verify routine. #826

James Cole0bcc010de860
diff --git a/app/Console/Commands/VerifyDatabase.php b/app/Console/Commands/VerifyDatabase.php
index 4f1ab1938f..4f66dddd94 100644
--- a/app/Console/Commands/VerifyDatabase.php
+++ b/app/Console/Commands/VerifyDatabase.php
@@ -17,6 +17,7 @@ use Crypt;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Budget;
+use FireflyIII\Models\LinkType;
use FireflyIII\Models\PiggyBankEvent;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
@@ -98,6 +99,33 @@ class VerifyDatabase extends Command
// report (and fix) piggy banks
$this->repairPiggyBanks();
+ // create default link types if necessary
+ $this->createLinkTypes();
+
+ }
+
+ /**
+ *
+ */
+ private function createLinkTypes()
+ {
+ $set = [
+ 'Relates' => ['relates to', 'relates to'],
+ 'Refund' => ['(partially) refunds', 'is (partially) refunded by'],
+ 'Paid' => ['(partially) pays for', 'is (partially) paid for by'],
+ 'Reimbursement' => ['(partially) reimburses', 'is (partially) reimbursed by'],
+ ];
+ foreach ($set as $name => $values) {
+ $link = LinkType::where('name', $name)->where('outward', $values[0])->where('inward', $values[1])->first();
+ if (is_null($link)) {
+ $link = new LinkType;
+ $link->name = $name;
+ $link->outward = $values[0];
+ $link->inward = $values[1];
+ }
+ $link->editable = false;
+ $link->save();
+ }
}
/**
diff --git a/app/Models/LinkType.php b/app/Models/LinkType.php
index 94d5cf74a1..300f77cc47 100644
--- a/app/Models/LinkType.php
+++ b/app/Models/LinkType.php
@@ -37,6 +37,9 @@ class LinkType extends Model
'editable' => 'boolean',
];
+ /** @var array */
+ protected $fillable = ['name', 'inward', 'outward', 'editable'];
+
/**
* @param $value
*