mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Will also upgrade database. #508
This commit is contained in:
parent
a442d3d952
commit
6a13dd317d
@ -15,6 +15,8 @@ namespace FireflyIII\Console\Commands;
|
|||||||
|
|
||||||
|
|
||||||
use DB;
|
use DB;
|
||||||
|
use FireflyIII\Models\BudgetLimit;
|
||||||
|
use FireflyIII\Models\LimitRepetition;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
@ -57,6 +59,29 @@ class UpgradeDatabase extends Command
|
|||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$this->setTransactionIdentifier();
|
$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());
|
$journalIds = array_unique($result->pluck('id')->toArray());
|
||||||
|
|
||||||
foreach ($journalIds as $journalId) {
|
foreach ($journalIds as $journalId) {
|
||||||
$this->updateJournal($journalId);
|
$this->updateJournal(intval($journalId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,10 +25,16 @@ class ChangesForV431 extends Migration
|
|||||||
// reinstate "repeats" and "repeat_freq".
|
// reinstate "repeats" and "repeat_freq".
|
||||||
Schema::table(
|
Schema::table(
|
||||||
'budget_limits', function (Blueprint $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);
|
$table->boolean('repeats')->default(0);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// remove date field "end_date"
|
// remove date field "end_date"
|
||||||
Schema::table(
|
Schema::table(
|
||||||
'budget_limits', function (Blueprint $table) {
|
'budget_limits', function (Blueprint $table) {
|
||||||
@ -37,11 +43,11 @@ class ChangesForV431 extends Migration
|
|||||||
);
|
);
|
||||||
|
|
||||||
// change field "start_date" to "startdate"
|
// change field "start_date" to "startdate"
|
||||||
Schema::table(
|
// Schema::table(
|
||||||
'budget_limits', function (Blueprint $table) {
|
// 'budget_limits', function (Blueprint $table) {
|
||||||
$table->renameColumn('startdate', 'start_date');
|
// $table->renameColumn('startdate', 'start_date');
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,9 +83,15 @@ class ChangesForV431 extends Migration
|
|||||||
Schema::table(
|
Schema::table(
|
||||||
'budget_limits', function (Blueprint $table) {
|
'budget_limits', function (Blueprint $table) {
|
||||||
$table->dropColumn('repeats');
|
$table->dropColumn('repeats');
|
||||||
|
|
||||||
|
}
|
||||||
|
);
|
||||||
|
Schema::table(
|
||||||
|
'budget_limits', function (Blueprint $table) {
|
||||||
$table->dropColumn('repeat_freq');
|
$table->dropColumn('repeat_freq');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user