Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Will also upgrade database. #508
James Cole6a13dd317d98
diff --git a/app/Console/Commands/UpgradeDatabase.php b/app/Console/Commands/UpgradeDatabase.phpindex a526e31a5a..7b3e905b88 100644--- a/app/Console/Commands/UpgradeDatabase.php+++ b/app/Console/Commands/UpgradeDatabase.php@@ -15,6 +15,8 @@ namespace FireflyIII\Console\Commands;use DB;+use FireflyIII\Models\BudgetLimit;+use FireflyIII\Models\LimitRepetition;use FireflyIII\Models\Transaction;use FireflyIII\Models\TransactionJournal;use Illuminate\Console\Command;@@ -57,6 +59,29 @@ class UpgradeDatabase extends Commandpublic function handle(){$this->setTransactionIdentifier();+ $this->migrateRepetitions();+ }++ private function migrateRepetitions()+ {+ if (!Schema::hasTable('budget_limits')) {+ return;+ }+ // get all budget limits with end_date NULL+ $set = BudgetLimit::whereNull('end_date')->get();+ $this->line(sprintf('Found %d budget limit(s) to update', $set->count()));+ /** @var BudgetLimit $budgetLimit */+ foreach ($set as $budgetLimit) {+ // get limit repetition (should be just one):+ /** @var LimitRepetition $repetition */+ $repetition = $budgetLimit->limitrepetitions()->first();+ if (!is_null($repetition)) {+ $budgetLimit->end_date = $repetition->enddate;+ $budgetLimit->save();+ $this->line(sprintf('Updated budget limit #%d', $budgetLimit->id));+ $repetition->delete();+ }+ }}/**@@ -83,7 +108,7 @@ class UpgradeDatabase extends Command$journalIds = array_unique($result->pluck('id')->toArray());foreach ($journalIds as $journalId) {- $this->updateJournal($journalId);+ $this->updateJournal(intval($journalId));}}diff --git a/database/migrations/2016_12_28_203205_changes_for_v431.php b/database/migrations/2016_12_28_203205_changes_for_v431.phpindex ad640bf06c..310ccac5a8 100644--- a/database/migrations/2016_12_28_203205_changes_for_v431.php+++ b/database/migrations/2016_12_28_203205_changes_for_v431.php@@ -25,24 +25,30 @@ class ChangesForV431 extends Migration// reinstate "repeats" and "repeat_freq".Schema::table('budget_limits', function (Blueprint $table) {- $table->string('repeat_freq', 30);- $table->boolean('repeats')->default(0);+ $table->string('repeat_freq', 30)->nullable();});- // remove date field "end_date"Schema::table('budget_limits', function (Blueprint $table) {- $table->dropColumn('end_date');+ $table->boolean('repeats')->default(0);});- // change field "start_date" to "startdate"++ // remove date field "end_date"Schema::table('budget_limits', function (Blueprint $table) {- $table->renameColumn('startdate', 'start_date');+ $table->dropColumn('end_date');});+ // change field "start_date" to "startdate"+// Schema::table(+// 'budget_limits', function (Blueprint $table) {+// $table->renameColumn('startdate', 'start_date');+// }+// );+}/**@@ -77,9 +83,15 @@ class ChangesForV431 extends MigrationSchema::table('budget_limits', function (Blueprint $table) {$table->dropColumn('repeats');++ }+ );+ Schema::table(+ 'budget_limits', function (Blueprint $table) {$table->dropColumn('repeat_freq');});+}}