From a3359ba47a89243f053698529fe0fbf9f94b88fc Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 9 Oct 2016 08:20:29 +0200 Subject: [PATCH] Moved destroy() method from CRUD to Account repos. --- app/Crud/Account/AccountCrud.php | 16 --------------- app/Crud/Account/AccountCrudInterface.php | 7 ------- app/Http/Controllers/AccountController.php | 5 +++-- .../Account/AccountRepository.php | 20 +++++++++++++++++++ .../Account/AccountRepositoryInterface.php | 11 ++++++++++ 5 files changed, 34 insertions(+), 25 deletions(-) diff --git a/app/Crud/Account/AccountCrud.php b/app/Crud/Account/AccountCrud.php index 76bcb659e3..8b01d018f8 100644 --- a/app/Crud/Account/AccountCrud.php +++ b/app/Crud/Account/AccountCrud.php @@ -52,23 +52,7 @@ class AccountCrud implements AccountCrudInterface $this->user = $user; } - /** - * @param Account $account - * @param Account $moveTo - * - * @return bool - */ - public function destroy(Account $account, Account $moveTo): bool - { - if (!is_null($moveTo->id)) { - DB::table('transactions')->where('account_id', $account->id)->update(['account_id' => $moveTo->id]); - } - if (!is_null($account)) { - $account->delete(); - } - return true; - } /** * @param $accountId diff --git a/app/Crud/Account/AccountCrudInterface.php b/app/Crud/Account/AccountCrudInterface.php index 772bf6afcb..15dd162de9 100644 --- a/app/Crud/Account/AccountCrudInterface.php +++ b/app/Crud/Account/AccountCrudInterface.php @@ -24,13 +24,6 @@ use Illuminate\Support\Collection; */ interface AccountCrudInterface { - /** - * @param Account $account - * @param Account $moveTo - * - * @return bool - */ - public function destroy(Account $account, Account $moveTo): bool; /** * @param int $accountId diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index c003953b4c..aabab3107d 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -94,19 +94,20 @@ class AccountController extends Controller } /** + * @param ARI $repository * @param AccountCrudInterface $crud * @param Account $account * * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ - public function destroy(AccountCrudInterface $crud, Account $account) + public function destroy(ARI $repository, AccountCrudInterface $crud, Account $account) { $type = $account->accountType->type; $typeName = config('firefly.shortNamesByFullName.' . $type); $name = $account->name; $moveTo = $crud->find(intval(Input::get('move_account_before_delete'))); - $crud->destroy($account, $moveTo); + $repository->destroy($account, $moveTo); Session::flash('success', strval(trans('firefly.' . $typeName . '_deleted', ['name' => $name]))); Preferences::mark(); diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index 8e4348cba0..0dc0072b50 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -64,6 +64,26 @@ class AccountRepository implements AccountRepositoryInterface return $count; } + /** + * Moved here from account CRUD. + * + * @param Account $account + * @param Account $moveTo + * + * @return bool + */ + public function destroy(Account $account, Account $moveTo): bool + { + if (!is_null($moveTo->id)) { + DB::table('transactions')->where('account_id', $account->id)->update(['account_id' => $moveTo->id]); + } + if (!is_null($account)) { + $account->delete(); + } + + return true; + } + /** * This method will call AccountRepositoryInterface::journalsInPeriod and get all withdrawaks made from the given $accounts, * as well as the transfers that move away from those $accounts. This is a slightly sharper selection diff --git a/app/Repositories/Account/AccountRepositoryInterface.php b/app/Repositories/Account/AccountRepositoryInterface.php index 855081fba1..ae253ba416 100644 --- a/app/Repositories/Account/AccountRepositoryInterface.php +++ b/app/Repositories/Account/AccountRepositoryInterface.php @@ -26,6 +26,7 @@ use Illuminate\Support\Collection; */ interface AccountRepositoryInterface { + /** * Moved here from account CRUD. * @@ -35,6 +36,16 @@ interface AccountRepositoryInterface */ public function count(array $types): int; + /** + * Moved here from account CRUD. + * + * @param Account $account + * @param Account $moveTo + * + * @return bool + */ + public function destroy(Account $account, Account $moveTo): bool; + /** * This method will call AccountRepositoryInterface::journalsInPeriod and get all withdrawaks made from the given $accounts, * as well as the transfers that move away from those $accounts. This is a slightly sharper selection