Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix https://github.com/firefly-iii/firefly-iii/issues/9714
James Colef38e51052607
diff --git a/app/Transformers/PiggyBankTransformer.php b/app/Transformers/PiggyBankTransformer.phpindex c1cf567fa3..056ec281b6 100644--- a/app/Transformers/PiggyBankTransformer.php+++ b/app/Transformers/PiggyBankTransformer.php@@ -99,10 +99,8 @@ class PiggyBankTransformer extends AbstractTransformer'id' => (string) $piggyBank->id,'created_at' => $piggyBank->created_at->toAtomString(),'updated_at' => $piggyBank->updated_at->toAtomString(),- 'accounts' => $this->renderAccounts($piggyBank),- // 'account_id' => (string)$piggyBank->account_id,- // 'account_name' => $piggyBank->account->name,'name' => $piggyBank->name,+ 'accounts' => $this->renderAccounts($piggyBank),'currency_id' => (string) $currency->id,'currency_code' => $currency->code,'currency_symbol' => $currency->symbol,@@ -137,6 +135,7 @@ class PiggyBankTransformer extends AbstractTransformer'id' => $account->id,'name' => $account->name,'current_amount' => (string) $account->pivot->current_amount,+ 'native_current_amount'=> (string) $account->pivot->native_current_amount,// TODO add balance, add left to save.];}diff --git a/database/migrations/2024_11_30_075826_multi_piggy.php b/database/migrations/2024_11_30_075826_multi_piggy.phpindex a3dc7f9c24..a671759b94 100644--- a/database/migrations/2024_11_30_075826_multi_piggy.php+++ b/database/migrations/2024_11_30_075826_multi_piggy.php@@ -25,10 +25,11 @@ declare(strict_types=1);use Illuminate\Database\Migrations\Migration;use Illuminate\Database\Schema\Blueprint;-use Illuminate\Support\Facades\Schema;use Illuminate\Support\Facades\Log;+use Illuminate\Support\Facades\Schema;return new class () extends Migration {+/*** Run the migrations.*/@@ -37,8 +38,9 @@ return new class () extends Migration {// make account_id nullable and the relation also nullable.try {Schema::table('piggy_banks', static function (Blueprint $table): void {- // 1. drop index- $table->dropForeign('piggy_banks_account_id_foreign');+ if (self::hasForeign('piggy_banks', 'piggy_banks_account_id_foreign')) {+ $table->dropForeign('piggy_banks_account_id_foreign');+ }});} catch (RuntimeException $e) {Log::error('Could not drop foreign key "piggy_banks_account_id_foreign". Probably not an issue.');@@ -105,7 +107,9 @@ return new class () extends Migration {$table->renameColumn('target_date_tz', 'targetdate_tz');// 3. drop currency again + index- $table->dropForeign('unique_currency');+ if (self::hasForeign('piggy_banks', 'unique_currency')) {+ $table->dropForeign('unique_currency');+ }$table->dropColumn('transaction_currency_id');// 2. make column non-nullable.@@ -127,4 +131,15 @@ return new class () extends Migration {Schema::dropIfExists('account_piggy_bank');}++ protected static function hasForeign(string $table, string $column) {++ $foreignKeysDefinitions = Schema::getForeignKeys($table);+ foreach($foreignKeysDefinitions as $foreignKeyDefinition) {+ if($foreignKeyDefinition['name'] === $column) {+ return true;+ }+ }+ return false;+ }};