From 919aa70251fef086318009e5ab674e5df0226449 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 12 Mar 2016 11:05:26 +0100 Subject: [PATCH] Account controller #185 --- app/Http/Controllers/AccountController.php | 2 +- app/Repositories/Account/AccountRepository.php | 11 ++++++----- .../Account/AccountRepositoryInterface.php | 4 +--- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index b9ed2fd939..11069ba57a 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -87,7 +87,7 @@ class AccountController extends Controller $type = $account->accountType->type; $typeName = Config::get('firefly.shortNamesByFullName.' . $type); $name = $account->name; - $moveTo = Auth::user()->accounts()->find(intval(Input::get('move_account_before_delete'))); + $moveTo = $repository->find(intval(Input::get('move_account_before_delete'))); $repository->destroy($account, $moveTo); diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index 8f2747edd8..64ffdca545 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -66,9 +66,9 @@ class AccountRepository implements AccountRepositoryInterface * * @return bool */ - public function destroy(Account $account, Account $moveTo = null): bool + public function destroy(Account $account, Account $moveTo): bool { - if (!is_null($moveTo)) { + if (!is_null($moveTo->id)) { // update all transactions: DB::table('transactions')->where('account_id', $account->id)->update(['account_id' => $moveTo->id]); } @@ -79,15 +79,16 @@ class AccountRepository implements AccountRepositoryInterface } /** - * @deprecated - * * @param int $accountId * * @return Account */ public function find(int $accountId): Account { - return $this->user->accounts()->findOrNew($accountId); + $entry = $this->user->accounts()->find($accountId); + if (is_null($entry)) { + return new Account; + } } /** diff --git a/app/Repositories/Account/AccountRepositoryInterface.php b/app/Repositories/Account/AccountRepositoryInterface.php index 8bc25e8485..cd2b8520a5 100644 --- a/app/Repositories/Account/AccountRepositoryInterface.php +++ b/app/Repositories/Account/AccountRepositoryInterface.php @@ -32,13 +32,11 @@ interface AccountRepositoryInterface * * @return boolean */ - public function destroy(Account $account, Account $moveTo = null): bool; + public function destroy(Account $account, Account $moveTo): bool; /** * @param int $accountId * - * @deprecated - * * @return Account */ public function find(int $accountId): Account;