Will also upgrade database. #508

This commit is contained in:
James Cole 2016-12-29 20:19:20 +01:00
parent a442d3d952
commit 6a13dd317d
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
2 changed files with 44 additions and 7 deletions

View File

@ -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 Command
public 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));
}
}

View File

@ -25,10 +25,16 @@ class ChangesForV431 extends Migration
// reinstate "repeats" and "repeat_freq".
Schema::table(
'budget_limits', function (Blueprint $table) {
$table->string('repeat_freq', 30);
$table->string('repeat_freq', 30)->nullable();
}
);
Schema::table(
'budget_limits', function (Blueprint $table) {
$table->boolean('repeats')->default(0);
}
);
// remove date field "end_date"
Schema::table(
'budget_limits', function (Blueprint $table) {
@ -37,11 +43,11 @@ class ChangesForV431 extends Migration
);
// change field "start_date" to "startdate"
Schema::table(
'budget_limits', function (Blueprint $table) {
$table->renameColumn('startdate', 'start_date');
}
);
// Schema::table(
// 'budget_limits', function (Blueprint $table) {
// $table->renameColumn('startdate', 'start_date');
// }
// );
}
@ -77,9 +83,15 @@ class ChangesForV431 extends Migration
Schema::table(
'budget_limits', function (Blueprint $table) {
$table->dropColumn('repeats');
}
);
Schema::table(
'budget_limits', function (Blueprint $table) {
$table->dropColumn('repeat_freq');
}
);
}
}