mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix delete routine and some NULLs
This commit is contained in:
parent
617a5c0606
commit
2c826451d1
@ -58,8 +58,11 @@ class AccountCrud implements AccountCrudInterface
|
||||
// update all transactions:
|
||||
DB::table('transactions')->where('account_id', $account->id)->update(['account_id' => $moveTo->id]);
|
||||
}
|
||||
|
||||
if (!is_null($account)) {
|
||||
Log::debug('Now trigger account delete #' . $account->id);
|
||||
$account->delete();
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -15,8 +15,10 @@ use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Models\PiggyBankRepetition;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class EventServiceProvider
|
||||
@ -107,13 +109,29 @@ class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
Account::deleted(
|
||||
function (Account $account) {
|
||||
|
||||
Log::debug('Now trigger account delete response #' . $account->id);
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($account->transactions()->get() as $transaction) {
|
||||
Log::debug('Now at transaction #' . $transaction->id);
|
||||
$journal = $transaction->transactionJournal()->first();
|
||||
if (!is_null($journal)) {
|
||||
Log::debug('Call for deletion of journal #' . $journal->id);
|
||||
$journal->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
TransactionJournal::deleted(
|
||||
function (TransactionJournal $journal) {
|
||||
Log::debug('Now triggered journal delete response #' . $journal->id);
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($journal->transactions()->get() as $transaction) {
|
||||
Log::debug('Will now delete transaction #' . $transaction->id);
|
||||
$transaction->delete();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
@ -96,11 +96,6 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
*/
|
||||
public function delete(TransactionJournal $journal): bool
|
||||
{
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($journal->transactions()->get() as $transaction) {
|
||||
$transaction->delete();
|
||||
}
|
||||
|
||||
$journal->delete();
|
||||
|
||||
return true;
|
||||
|
@ -440,11 +440,11 @@ class CreateMainTables extends Migration
|
||||
|
||||
$table->string('tag', 1024);
|
||||
$table->string('tagMode', 1024);
|
||||
$table->date('date');
|
||||
$table->text('description');
|
||||
$table->decimal('latitude', 18, 12);
|
||||
$table->decimal('longitude', 18, 12);
|
||||
$table->boolean('zoomLevel');
|
||||
$table->date('date')->nullable();
|
||||
$table->text('description')->nullable();
|
||||
$table->decimal('latitude', 18, 12)->nullable();
|
||||
$table->decimal('longitude', 18, 12)->nullable();
|
||||
$table->boolean('zoomLevel')->nullable();
|
||||
|
||||
// link user id to users table
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
|
Loading…
Reference in New Issue
Block a user