Fix delete routine and some NULLs

This commit is contained in:
James Cole 2016-06-23 12:07:31 +02:00
parent 617a5c0606
commit 2c826451d1
5 changed files with 30 additions and 14 deletions

View File

@ -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();
}
$account->delete();
return true;
}

View File

@ -103,7 +103,7 @@ class AccountController extends Controller
$typeName = config('firefly.shortNamesByFullName.' . $type);
$name = $account->name;
$moveTo = $crud->find(intval(Input::get('move_account_before_delete')));
$crud->destroy($account, $moveTo);
Session::flash('success', strval(trans('firefly.' . $typeName . '_deleted', ['name' => $name])));

View File

@ -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,11 +109,27 @@ 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();
$journal->delete();
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();
}
}
);

View File

@ -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;

View File

@ -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');