diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php index cf9ea778c8..4c03129599 100644 --- a/app/controllers/AccountController.php +++ b/app/controllers/AccountController.php @@ -60,55 +60,19 @@ class AccountController extends BaseController { $type = $account->accountType->type; + $name = $account->name; /** @var \FireflyIII\Database\Account $acct */ $acct = App::make('FireflyIII\Database\Account'); - /** @var \FireflyIII\Database\TransactionJournal $jrnls */ - $jrnls = App::make('FireflyIII\Database\TransactionJournal'); - - /* - * Find the "initial balance account", should it exist: - */ - $initialBalance = $acct->findInitialBalanceAccount($account); - - /* - * Get all the transaction journals that are part of this/these account(s): - */ - $journals = []; - if ($initialBalance) { - $transactions = $initialBalance->transactions()->get(); - /** @var \Transaction $transaction */ - foreach ($transactions as $transaction) { - $journals[] = $transaction->transaction_journal_id; - } - } - /** @var \Transaction $transaction */ - foreach ($account->transactions() as $transaction) { - $journals[] = $transaction->transaction_journal_id; - } - - $journals = array_unique($journals); - - /* - * Delete the journals. Should get rid of the transactions as well. - */ - foreach ($journals as $id) { - $journal = $jrnls->find($id); - $jrnls->destroy($journal); - } - - /* - * Delete the initial balance as well. - */ - if ($initialBalance) { - $acct->destroy($initialBalance); - } - $name = $account->name; + // find the initial balance account (the only other account that should be deleted) + // find all journals for both accounts (or just the one) and delete them. + // the rest will take care of itself. + // in the least amount of queries possible. + // and it can be done in ONE query! or maybe two. $acct->destroy($account); - $return = 'asset'; switch ($type) { case 'Expense account': @@ -123,8 +87,6 @@ class AccountController extends BaseController Session::flash('success', 'The ' . $return . ' account "' . e($name) . '" was deleted.'); return Redirect::route('accounts.index', $return); - - } /** diff --git a/app/controllers/TransactionController.php b/app/controllers/TransactionController.php index e0088de107..01066c79ee 100644 --- a/app/controllers/TransactionController.php +++ b/app/controllers/TransactionController.php @@ -548,10 +548,10 @@ class TransactionController extends BaseController return Redirect::route('transactions.index', $data['what']); } } else { - Session::flash('error', 'Could not update transaction: ' . $journal->errors()->first()); + Session::flash('error', 'Could not update transaction: ' . $journal->getErrors()->first()); return Redirect::route('transactions.edit', $journal->id)->withInput()->withErrors( - $journal->errors() + $journal->getErrors() ); } diff --git a/app/lib/FireflyIII/Database/Account.php b/app/lib/FireflyIII/Database/Account.php index d03777b6f9..6dcd5ae0b3 100644 --- a/app/lib/FireflyIII/Database/Account.php +++ b/app/lib/FireflyIII/Database/Account.php @@ -9,7 +9,6 @@ use FireflyIII\Database\Ifaces\CUD; use FireflyIII\Exception\NotImplementedException; use Illuminate\Support\Collection; use Illuminate\Support\MessageBag; -use LaravelBook\Ardent\Ardent; /** * Class Account @@ -224,17 +223,58 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface } /** - * @param Ardent $model + * @param \Eloquent $model * * @return bool */ - public function destroy(Ardent $model) + public function destroy(\Eloquent $model) { + + // delete journals: + $journals = \TransactionJournal::whereIn( + 'id', function ($query) use ($model) { + $query->select('transaction_journal_id') + ->from('transactions')->whereIn( + 'account_id', function ($query) use ($model) { + $query + ->select('id') + ->from('accounts') + ->where( + function ($q) use ($model) { + $q->where('id', $model->id); + $q->orWhere( + function ($q) use ($model) { + $q->where('accounts.name', 'LIKE', '%' . $model->name . '%'); + // TODO magic number! + $q->where('accounts.account_type_id', 3); + $q->where('accounts.active', 0); + } + ); + } + )->where('accounts.user_id', $this->getUser()->id); + } + )->get(); + } + )->delete(); + /* * Trigger deletion: */ \Event::fire('account.destroy', [$model]); - $model->delete(); + + // delete accounts: + \Account::where( + function ($q) use ($model) { + $q->where('id', $model->id); + $q->orWhere( + function ($q) use ($model) { + $q->where('accounts.name', 'LIKE', '%' . $model->name . '%'); + // TODO magic number! + $q->where('accounts.account_type_id', 3); + $q->where('accounts.active', 0); + } + ); + })->delete(); return true; @@ -243,7 +283,7 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface /** * @param array $data * - * @return Ardent + * @return \Eloquent */ public function store(array $data) { @@ -263,8 +303,8 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface $data = array_except($data, ['_token', 'what']); $account = new \Account($data); - if (!$account->validate()) { - var_dump($account->errors()->all()); + if (!$account->isValid()) { + var_dump($account->getErrors()->all()); exit; } $account->save(); @@ -290,12 +330,12 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface } /** - * @param Ardent $model + * @param \Eloquent $model * @param array $data * * @return bool */ - public function update(Ardent $model, array $data) + public function update(\Eloquent $model, array $data) { $model->name = $data['name']; $model->active = isset($data['active']) ? intval($data['active']) : 0; @@ -415,7 +455,7 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface * * @param int $id * - * @return Ardent + * @return \Eloquent */ public function find($id) { diff --git a/app/lib/FireflyIII/Database/AccountType.php b/app/lib/FireflyIII/Database/AccountType.php index 9d945faffa..68b3911b8f 100644 --- a/app/lib/FireflyIII/Database/AccountType.php +++ b/app/lib/FireflyIII/Database/AccountType.php @@ -2,13 +2,12 @@ namespace FireflyIII\Database; -use Firefly\Exception\FireflyException; +use FireflyIII\Exception\FireflyException; use FireflyIII\Database\Ifaces\AccountTypeInterface; use FireflyIII\Database\Ifaces\CommonDatabaseCalls; use FireflyIII\Database\Ifaces\CUD; use FireflyIII\Exception\NotImplementedException; use Illuminate\Support\Collection; -use LaravelBook\Ardent\Ardent; /** * Class AccountType @@ -19,11 +18,11 @@ class AccountType implements CUD, CommonDatabaseCalls { /** - * @param Ardent $model + * @param \Eloquent $model * * @return bool */ - public function destroy(Ardent $model) + public function destroy(\Eloquent $model) { // TODO: Implement destroy() method. throw new NotImplementedException; @@ -32,7 +31,7 @@ class AccountType implements CUD, CommonDatabaseCalls /** * @param array $data * - * @return Ardent + * @return \Eloquent */ public function store(array $data) { @@ -41,12 +40,12 @@ class AccountType implements CUD, CommonDatabaseCalls } /** - * @param Ardent $model + * @param \Eloquent $model * @param array $data * * @return bool */ - public function update(Ardent $model, array $data) + public function update(\Eloquent $model, array $data) { // TODO: Implement update() method. throw new NotImplementedException; @@ -71,7 +70,7 @@ class AccountType implements CUD, CommonDatabaseCalls * * @param int $id * - * @return Ardent + * @return \Eloquent */ public function find($id) { diff --git a/app/lib/FireflyIII/Database/Budget.php b/app/lib/FireflyIII/Database/Budget.php index a265ac0a27..f9563d8066 100644 --- a/app/lib/FireflyIII/Database/Budget.php +++ b/app/lib/FireflyIII/Database/Budget.php @@ -8,7 +8,6 @@ use FireflyIII\Database\Ifaces\CUD; use FireflyIII\Exception\NotImplementedException; use Illuminate\Support\Collection; use Illuminate\Support\MessageBag; -use LaravelBook\Ardent\Ardent; /** * Class Budget @@ -28,11 +27,11 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface } /** - * @param Ardent $model + * @param \Eloquent $model * * @return bool */ - public function destroy(Ardent $model) + public function destroy(\Eloquent $model) { $model->delete(); @@ -42,7 +41,7 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface /** * @param array $data * - * @return Ardent + * @return \Eloquent */ public function store(array $data) { @@ -51,8 +50,8 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface $budget = new \Budget($data); $budget->class = 'Budget'; - if (!$budget->validate()) { - var_dump($budget->errors()->all()); + if (!$budget->isValid()) { + var_dump($budget->getErrors()->all()); exit; } $budget->save(); @@ -61,16 +60,16 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface } /** - * @param Ardent $model + * @param \Eloquent $model * @param array $data * * @return bool */ - public function update(Ardent $model, array $data) + public function update(\Eloquent $model, array $data) { $model->name = $data['name']; - if (!$model->validate()) { - var_dump($model->errors()->all()); + if (!$model->isValid()) { + var_dump($model->getErrors()->all()); exit; } @@ -124,7 +123,7 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface * * @param int $id * - * @return Ardent + * @return \Eloquent */ public function find($id) { diff --git a/app/lib/FireflyIII/Database/Category.php b/app/lib/FireflyIII/Database/Category.php index c04d4aa6b7..649dfc47ea 100644 --- a/app/lib/FireflyIII/Database/Category.php +++ b/app/lib/FireflyIII/Database/Category.php @@ -8,7 +8,7 @@ use FireflyIII\Database\Ifaces\CUD; use FireflyIII\Exception\NotImplementedException; use Illuminate\Support\Collection; use Illuminate\Support\MessageBag; -use LaravelBook\Ardent\Ardent; + /** * Class Category @@ -28,11 +28,11 @@ class Category implements CUD, CommonDatabaseCalls } /** - * @param Ardent $model + * @param \Eloquent $model * * @return bool */ - public function destroy(Ardent $model) + public function destroy(\Eloquent $model) { $model->delete(); @@ -42,7 +42,7 @@ class Category implements CUD, CommonDatabaseCalls /** * @param array $data * - * @return Ardent + * @return \Eloquent */ public function store(array $data) { @@ -50,8 +50,8 @@ class Category implements CUD, CommonDatabaseCalls $category->name = $data['name']; $category->class = 'Category'; $category->user()->associate($this->getUser()); - if (!$category->validate()) { - var_dump($category->errors()); + if (!$category->isValid()) { + var_dump($category->getErrors()); exit(); } $category->save(); @@ -60,16 +60,16 @@ class Category implements CUD, CommonDatabaseCalls } /** - * @param Ardent $model + * @param \Eloquent $model * @param array $data * * @return bool */ - public function update(Ardent $model, array $data) + public function update(\Eloquent $model, array $data) { $model->name = $data['name']; - if (!$model->validate()) { - var_dump($model->errors()->all()); + if (!$model->isValid()) { + var_dump($model->getErrors()->all()); exit; } @@ -107,7 +107,7 @@ class Category implements CUD, CommonDatabaseCalls $validator = \Validator::make($model, \Component::$rules); if ($validator->invalid()) { - $errors->merge($validator->errors()); + $errors->merge($validator->getErrors()); } @@ -123,7 +123,7 @@ class Category implements CUD, CommonDatabaseCalls * * @param int $id * - * @return Ardent + * @return \Eloquent */ public function find($id) { diff --git a/app/lib/FireflyIII/Database/Ifaces/CUD.php b/app/lib/FireflyIII/Database/Ifaces/CUD.php index fd4b4ab47d..b80882d465 100644 --- a/app/lib/FireflyIII/Database/Ifaces/CUD.php +++ b/app/lib/FireflyIII/Database/Ifaces/CUD.php @@ -2,7 +2,7 @@ namespace FireflyIII\Database\Ifaces; -use LaravelBook\Ardent\Ardent; + /** * Interface CUD @@ -13,26 +13,26 @@ interface CUD { /** - * @param Ardent $model + * @param \Eloquent $model * * @return bool */ - public function destroy(Ardent $model); + public function destroy(\Eloquent $model); /** * @param array $data * - * @return Ardent + * @return \Eloquent */ public function store(array $data); /** - * @param Ardent $model + * @param \Eloquent $model * @param array $data * * @return bool */ - public function update(Ardent $model, array $data); + public function update(\Eloquent $model, array $data); /** * Validates an array. Returns an array containing MessageBags diff --git a/app/lib/FireflyIII/Database/Ifaces/CommonDatabaseCalls.php b/app/lib/FireflyIII/Database/Ifaces/CommonDatabaseCalls.php index 977e151c82..2c47a6023c 100644 --- a/app/lib/FireflyIII/Database/Ifaces/CommonDatabaseCalls.php +++ b/app/lib/FireflyIII/Database/Ifaces/CommonDatabaseCalls.php @@ -3,7 +3,7 @@ namespace FireflyIII\Database\Ifaces; use Illuminate\Support\Collection; -use LaravelBook\Ardent\Ardent; + /** @@ -18,7 +18,7 @@ interface CommonDatabaseCalls * * @param int $id * - * @return Ardent + * @return \Eloquent */ public function find($id); diff --git a/app/lib/FireflyIII/Database/Piggybank.php b/app/lib/FireflyIII/Database/Piggybank.php index d07c870d06..f416900a4c 100644 --- a/app/lib/FireflyIII/Database/Piggybank.php +++ b/app/lib/FireflyIII/Database/Piggybank.php @@ -2,14 +2,14 @@ namespace FireflyIII\Database; use Carbon\Carbon; -use Firefly\Exception\FireflyException; +use FireflyIII\Exception\FireflyException; use FireflyIII\Database\Ifaces\CommonDatabaseCalls; use FireflyIII\Database\Ifaces\CUD; use FireflyIII\Database\Ifaces\PiggybankInterface; use FireflyIII\Exception\NotImplementedException; use Illuminate\Support\Collection; use Illuminate\Support\MessageBag; -use LaravelBook\Ardent\Ardent; + /** * Class Piggybank @@ -29,11 +29,11 @@ class Piggybank implements CUD, CommonDatabaseCalls, PiggybankInterface } /** - * @param Ardent $model + * @param \Eloquent $model * * @return bool */ - public function destroy(Ardent $model) + public function destroy(\Eloquent $model) { $model->delete(); } @@ -41,7 +41,7 @@ class Piggybank implements CUD, CommonDatabaseCalls, PiggybankInterface /** * @param array $data * - * @return Ardent + * @return \Eloquent */ public function store(array $data) { @@ -58,8 +58,8 @@ class Piggybank implements CUD, CommonDatabaseCalls, PiggybankInterface $piggybank = new \Piggybank($data); - if (!$piggybank->validate()) { - var_dump($piggybank->errors()->all()); + if (!$piggybank->isValid()) { + var_dump($piggybank->getErrors()->all()); exit; } $piggybank->save(); @@ -68,12 +68,12 @@ class Piggybank implements CUD, CommonDatabaseCalls, PiggybankInterface } /** - * @param Ardent $model + * @param \Eloquent $model * @param array $data * * @return bool */ - public function update(Ardent $model, array $data) + public function update(\Eloquent $model, array $data) { /** @var \Piggybank $model */ $model->name = $data['name']; @@ -90,8 +90,8 @@ class Piggybank implements CUD, CommonDatabaseCalls, PiggybankInterface $model->reminder = null; } - if (!$model->validate()) { - var_dump($model->errors()); + if (!$model->isValid()) { + var_dump($model->getErrors()); exit(); } @@ -188,7 +188,7 @@ class Piggybank implements CUD, CommonDatabaseCalls, PiggybankInterface * * @param int $id * - * @return Ardent + * @return \Eloquent */ public function find($id) { diff --git a/app/lib/FireflyIII/Database/Recurring.php b/app/lib/FireflyIII/Database/Recurring.php index b781b4e611..d87a7f2b33 100644 --- a/app/lib/FireflyIII/Database/Recurring.php +++ b/app/lib/FireflyIII/Database/Recurring.php @@ -10,7 +10,7 @@ use FireflyIII\Database\Ifaces\RecurringInterface; use FireflyIII\Exception\NotImplementedException; use Illuminate\Support\Collection; use Illuminate\Support\MessageBag; -use LaravelBook\Ardent\Ardent; + use stdObject; /** @@ -31,11 +31,11 @@ class Recurring implements CUD, CommonDatabaseCalls, RecurringInterface } /** - * @param Ardent $model + * @param \Eloquent $model * * @return bool */ - public function destroy(Ardent $model) + public function destroy(\Eloquent $model) { $model->delete(); @@ -45,7 +45,7 @@ class Recurring implements CUD, CommonDatabaseCalls, RecurringInterface /** * @param array $data * - * @return Ardent + * @return \Eloquent */ public function store(array $data) { @@ -71,8 +71,8 @@ class Recurring implements CUD, CommonDatabaseCalls, RecurringInterface $recurring->date = $date; $recurring->skip = intval($data['skip']); - if (!$recurring->validate()) { - var_dump($recurring->errors()); + if (!$recurring->isValid()) { + var_dump($recurring->getErrors()); exit(); } @@ -82,12 +82,12 @@ class Recurring implements CUD, CommonDatabaseCalls, RecurringInterface } /** - * @param Ardent $model + * @param \Eloquent $model * @param array $data * * @return bool */ - public function update(Ardent $model, array $data) + public function update(\Eloquent $model, array $data) { var_dump($data); @@ -104,8 +104,8 @@ class Recurring implements CUD, CommonDatabaseCalls, RecurringInterface $model->repeat_freq = $data['repeat_freq']; $model->skip = intval($data['skip']); - if (!$model->validate()) { - var_dump($model->errors()); + if (!$model->isValid()) { + var_dump($model->getErrors()); exit(); } @@ -182,7 +182,7 @@ class Recurring implements CUD, CommonDatabaseCalls, RecurringInterface * * @param int $id * - * @return Ardent + * @return \Eloquent */ public function find($id) { diff --git a/app/lib/FireflyIII/Database/RepeatedExpense.php b/app/lib/FireflyIII/Database/RepeatedExpense.php index e09463b023..e0294558ce 100644 --- a/app/lib/FireflyIII/Database/RepeatedExpense.php +++ b/app/lib/FireflyIII/Database/RepeatedExpense.php @@ -11,7 +11,7 @@ use FireflyIII\Database\Ifaces\PiggybankInterface; use FireflyIII\Exception\NotImplementedException; use Illuminate\Support\Collection; use Illuminate\Support\MessageBag; -use LaravelBook\Ardent\Ardent; + class RepeatedExpense implements CUD, CommonDatabaseCalls, PiggybankInterface { @@ -272,11 +272,11 @@ class RepeatedExpense implements CUD, CommonDatabaseCalls, PiggybankInterface } /** - * @param Ardent $model + * @param \Eloquent $model * * @return bool */ - public function destroy(Ardent $model) + public function destroy(\Eloquent $model) { // TODO: Implement destroy() method. throw new NotImplementedException; @@ -285,7 +285,7 @@ class RepeatedExpense implements CUD, CommonDatabaseCalls, PiggybankInterface /** * @param array $data * - * @return Ardent + * @return \Eloquent */ public function store(array $data) { @@ -305,8 +305,8 @@ class RepeatedExpense implements CUD, CommonDatabaseCalls, PiggybankInterface $repeated = new \Piggybank($data); - if (!$repeated->validate()) { - var_dump($repeated->errors()->all()); + if (!$repeated->isValid()) { + var_dump($repeated->getErrors()->all()); exit; } $repeated->save(); @@ -315,12 +315,12 @@ class RepeatedExpense implements CUD, CommonDatabaseCalls, PiggybankInterface } /** - * @param Ardent $model + * @param \Eloquent $model * @param array $data * * @return bool */ - public function update(Ardent $model, array $data) + public function update(\Eloquent $model, array $data) { // TODO: Implement update() method. throw new NotImplementedException; @@ -425,7 +425,7 @@ class RepeatedExpense implements CUD, CommonDatabaseCalls, PiggybankInterface * * @param int $id * - * @return Ardent + * @return \Eloquent */ public function find($id) { diff --git a/app/lib/FireflyIII/Database/Transaction.php b/app/lib/FireflyIII/Database/Transaction.php index 3ab54aea75..514ea66217 100644 --- a/app/lib/FireflyIII/Database/Transaction.php +++ b/app/lib/FireflyIII/Database/Transaction.php @@ -2,14 +2,14 @@ namespace FireflyIII\Database; -use Firefly\Exception\FireflyException; +use FireflyIII\Exception\FireflyException; use FireflyIII\Database\Ifaces\CommonDatabaseCalls; use FireflyIII\Database\Ifaces\CUD; use FireflyIII\Database\Ifaces\TransactionInterface; use FireflyIII\Exception\NotImplementedException; use Illuminate\Support\Collection; use Illuminate\Support\MessageBag; -use LaravelBook\Ardent\Ardent; + /** * Class Transaction @@ -21,11 +21,11 @@ class Transaction implements CUD, CommonDatabaseCalls use SwitchUser; /** - * @param Ardent $model + * @param \Eloquent $model * * @return bool */ - public function destroy(Ardent $model) + public function destroy(\Eloquent $model) { // TODO: Implement destroy() method. throw new NotImplementedException; @@ -34,7 +34,7 @@ class Transaction implements CUD, CommonDatabaseCalls /** * @param array $data * - * @return Ardent + * @return \Eloquent */ public function store(array $data) { @@ -48,22 +48,22 @@ class Transaction implements CUD, CommonDatabaseCalls if (isset($data['description'])) { $transaction->description = $data['description']; } - if ($transaction->validate()) { + if ($transaction->isValid()) { $transaction->save(); } else { - throw new FireflyException($transaction->errors()->first()); + throw new FireflyException($transaction->getErrors()->first()); } return $transaction; } /** - * @param Ardent $model + * @param \Eloquent $model * @param array $data * * @return bool */ - public function update(Ardent $model, array $data) + public function update(\Eloquent $model, array $data) { // TODO: Implement update() method. throw new NotImplementedException; @@ -140,7 +140,7 @@ class Transaction implements CUD, CommonDatabaseCalls * * @param int $id * - * @return Ardent + * @return \Eloquent */ public function find($id) { diff --git a/app/lib/FireflyIII/Database/TransactionJournal.php b/app/lib/FireflyIII/Database/TransactionJournal.php index e74ca8163d..e0f8184fc0 100644 --- a/app/lib/FireflyIII/Database/TransactionJournal.php +++ b/app/lib/FireflyIII/Database/TransactionJournal.php @@ -4,14 +4,13 @@ namespace FireflyIII\Database; use Carbon\Carbon; -use Firefly\Exception\FireflyException; use FireflyIII\Database\Ifaces\CommonDatabaseCalls; use FireflyIII\Database\Ifaces\CUD; use FireflyIII\Database\Ifaces\TransactionJournalInterface; +use FireflyIII\Exception\FireflyException; use FireflyIII\Exception\NotImplementedException; use Illuminate\Support\Collection; use Illuminate\Support\MessageBag; -use LaravelBook\Ardent\Ardent; /** * Class TransactionJournal @@ -31,11 +30,11 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData } /** - * @param Ardent $model + * @param \Eloquent $model * * @return bool */ - public function destroy(Ardent $model) + public function destroy(\Eloquent $model) { /* * Trigger deletion. @@ -58,7 +57,7 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData /** * @param array $data * - * @return Ardent + * @return \Eloquent */ public function store(array $data) { @@ -88,8 +87,8 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData /* * This must be enough to store the journal: */ - if (!$journal->validate()) { - \Log::error($journal->errors()->all()); + if (!$journal->isValid()) { + \Log::error($journal->getErrors()->all()); throw new FireflyException('store() transaction journal failed, but it should not!'); } $journal->save(); @@ -171,12 +170,12 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData } /** - * @param Ardent $model + * @param \Eloquent $model * @param array $data * * @return bool */ - public function update(Ardent $model, array $data) + public function update(\Eloquent $model, array $data) { /** @var \FireflyIII\Database\TransactionType $typeRepository */ $typeRepository = \App::make('FireflyIII\Database\TransactionType'); @@ -202,8 +201,8 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData /* * This must be enough to store the journal: */ - if (!$model->validate()) { - \Log::error($model->errors()->all()); + if (!$model->isValid()) { + \Log::error($model->getErrors()->all()); throw new FireflyException('store() transaction journal failed, but it should not!'); } $model->save(); @@ -269,7 +268,7 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData $transaction->account()->associate($data['from']); $transaction->amount = $amount * -1; } - if (!$transaction->validate()) { + if (!$transaction->isValid()) { throw new FireflyException('Could not validate transaction while saving.'); } $transaction->save(); @@ -446,7 +445,7 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData * * @param int $id * - * @return Ardent + * @return \Eloquent */ public function find($id) { diff --git a/app/lib/FireflyIII/Database/TransactionType.php b/app/lib/FireflyIII/Database/TransactionType.php index a0c215783d..6414f7e835 100644 --- a/app/lib/FireflyIII/Database/TransactionType.php +++ b/app/lib/FireflyIII/Database/TransactionType.php @@ -9,7 +9,7 @@ use FireflyIII\Database\Ifaces\TransactionTypeInterface; use FireflyIII\Exception\FireflyException; use FireflyIII\Exception\NotImplementedException; use Illuminate\Support\Collection; -use LaravelBook\Ardent\Ardent; + /** * Class TransactionType @@ -20,11 +20,11 @@ class TransactionType implements CUD, CommonDatabaseCalls { /** - * @param Ardent $model + * @param \Eloquent $model * * @return bool */ - public function destroy(Ardent $model) + public function destroy(\Eloquent $model) { // TODO: Implement destroy() method. throw new NotImplementedException; @@ -33,7 +33,7 @@ class TransactionType implements CUD, CommonDatabaseCalls /** * @param array $data * - * @return Ardent + * @return \Eloquent */ public function store(array $data) { @@ -42,12 +42,12 @@ class TransactionType implements CUD, CommonDatabaseCalls } /** - * @param Ardent $model + * @param \Eloquent $model * @param array $data * * @return bool */ - public function update(Ardent $model, array $data) + public function update(\Eloquent $model, array $data) { // TODO: Implement update() method. throw new NotImplementedException; @@ -72,7 +72,7 @@ class TransactionType implements CUD, CommonDatabaseCalls * * @param int $id * - * @return Ardent + * @return \Eloquent */ public function find($id) { diff --git a/app/lib/FireflyIII/Database/User.php b/app/lib/FireflyIII/Database/User.php index 4cb416e42a..e33ef42f4c 100644 --- a/app/lib/FireflyIII/Database/User.php +++ b/app/lib/FireflyIII/Database/User.php @@ -46,7 +46,7 @@ class User if (!$user->save()) { \Log::error('Invalid user with data: ' . isset($data['email']) ? $data['email'] : '(no email!)'); - \Session::flash('error', 'Input invalid, please try again: ' . $user->errors()->first()); + \Session::flash('error', 'Input invalid, please try again: ' . $user->getErrors()->first()); return false; } diff --git a/app/lib/FireflyIII/Event/Event.php b/app/lib/FireflyIII/Event/Event.php new file mode 100644 index 0000000000..1f670ccb20 --- /dev/null +++ b/app/lib/FireflyIII/Event/Event.php @@ -0,0 +1,35 @@ +piggybanks()->get(); + + // get reminders for each + /** @var \Piggybank $piggyBank */ + foreach ($piggies as $piggyBank) { + $reminders = $piggyBank->reminders()->get(); + /** @var \Reminder $reminder */ + foreach ($reminders as $reminder) { + $reminder->delete(); + } + } + } + + + /** + * @param Dispatcher $events + */ + public function subscribe(Dispatcher $events) + { + // triggers when others are updated. + $events->listen('account.destroy', 'FireflyIII\Event\Event@deleteAccount'); + } +} \ No newline at end of file diff --git a/app/lib/FireflyIII/Event/Piggybank.php b/app/lib/FireflyIII/Event/Piggybank.php index aa1aab289f..05657efafb 100644 --- a/app/lib/FireflyIII/Event/Piggybank.php +++ b/app/lib/FireflyIII/Event/Piggybank.php @@ -20,8 +20,8 @@ class Piggybank $event->piggybank()->associate($piggybank); $event->amount = floatval($amount); $event->date = new Carbon; - if (!$event->validate()) { - var_dump($event->errors()); + if (!$event->isValid()) { + var_dump($event->getErrors()); exit(); } $event->save(); @@ -60,8 +60,8 @@ class Piggybank $event->piggybank()->associate($piggyBank); $event->amount = floatval($relevantTransaction->amount * -1); $event->date = new Carbon; - if (!$event->validate()) { - var_dump($event->errors()); + if (!$event->isValid()) { + var_dump($event->getErrors()); exit(); } $event->save(); @@ -80,8 +80,8 @@ class Piggybank $event->piggybank()->associate($piggybank); $event->amount = floatval($amount); $event->date = new Carbon; - if (!$event->validate()) { - var_dump($event->errors()); + if (!$event->isValid()) { + var_dump($event->getErrors()); exit(); } $event->save(); @@ -165,8 +165,8 @@ class Piggybank $event->transactionjournal()->associate($journal); $event->amount = floatval($relevantTransaction->amount); $event->date = new Carbon; - if (!$event->validate()) { - var_dump($event->errors()); + if (!$event->isValid()) { + var_dump($event->getErrors()); exit(); } $event->save(); @@ -300,8 +300,8 @@ class Piggybank $event->transactionJournal()->associate($journal); $event->amount = $diff; $event->date = new Carbon; - if (!$event->validate()) { - var_dump($event->errors()); + if (!$event->isValid()) { + var_dump($event->getErrors()); exit(); } $event->save(); diff --git a/app/lib/FireflyIII/Exception/FireflyException.php b/app/lib/FireflyIII/Exception/FireflyException.php index 566a0cb437..69890ddfc4 100644 --- a/app/lib/FireflyIII/Exception/FireflyException.php +++ b/app/lib/FireflyIII/Exception/FireflyException.php @@ -6,7 +6,7 @@ namespace FireflyIII\Exception; /** * Class FireflyException * - * @package Firefly\Exception + * @package FireflyIII\Exception */ class FireflyException extends \Exception { diff --git a/app/lib/FireflyIII/Exception/ValidationException.php b/app/lib/FireflyIII/Exception/ValidationException.php index 56116a870d..b33a078b1c 100644 --- a/app/lib/FireflyIII/Exception/ValidationException.php +++ b/app/lib/FireflyIII/Exception/ValidationException.php @@ -4,7 +4,7 @@ namespace FireflyIII\Exception; /** * Class ValidationException * - * @package Firefly\Exception + * @package FireflyIII\Exception */ class ValidationException extends \Exception { diff --git a/app/lib/FireflyIII/Shared/Preferences/Preferences.php b/app/lib/FireflyIII/Shared/Preferences/Preferences.php index 0fa5bfda7a..0770b2be1d 100644 --- a/app/lib/FireflyIII/Shared/Preferences/Preferences.php +++ b/app/lib/FireflyIII/Shared/Preferences/Preferences.php @@ -3,7 +3,7 @@ namespace FireflyIII\Shared\Preferences; /** * Class PreferencesHelper * - * @package Firefly\Helper\Preferences + * @package FireflyIII\Shared\Preferences */ class Preferences implements PreferencesInterface { diff --git a/app/lib/FireflyIII/Shared/Preferences/PreferencesInterface.php b/app/lib/FireflyIII/Shared/Preferences/PreferencesInterface.php index 27f18a7ac5..1a3cb217eb 100644 --- a/app/lib/FireflyIII/Shared/Preferences/PreferencesInterface.php +++ b/app/lib/FireflyIII/Shared/Preferences/PreferencesInterface.php @@ -4,7 +4,7 @@ namespace FireflyIII\Shared\Preferences; /** * Interface PreferencesHelperInterface * - * @package Firefly\Helper\Preferences + * @package FireflyIII\Shared\Preferences */ interface PreferencesInterface { diff --git a/app/lib/FireflyIII/Shared/SingleTableInheritanceEntity.php b/app/lib/FireflyIII/Shared/SingleTableInheritanceEntity.php index 664813d406..eb43e60b6a 100644 --- a/app/lib/FireflyIII/Shared/SingleTableInheritanceEntity.php +++ b/app/lib/FireflyIII/Shared/SingleTableInheritanceEntity.php @@ -1,14 +1,12 @@ ['required', 'between:1,100'], 'user_id' => 'required|exists:users,id', 'account_type_id' => 'required|exists:account_types,id', 'active' => 'required|boolean' ]; - + protected $dates = ['deleted_at', 'created_at', 'updated_at']; /** * Fillable fields. * @@ -134,7 +110,7 @@ class Account extends Ardent } $meta = new AccountMeta; $meta->account()->associate($this); - $meta->name = $fieldName; + $meta->name = $fieldName; $meta->data = $fieldValue; $meta->save(); diff --git a/app/models/AccountMeta.php b/app/models/AccountMeta.php index 8202709aff..78dbc159dd 100644 --- a/app/models/AccountMeta.php +++ b/app/models/AccountMeta.php @@ -1,26 +1,9 @@ ['required', 'between:1,50', 'alphabasic'], diff --git a/app/models/Budget.php b/app/models/Budget.php index 2101250670..ba7ca58652 100644 --- a/app/models/Budget.php +++ b/app/models/Budget.php @@ -1,32 +1,12 @@ hasManyThrough('LimitRepetition', 'Limit','component_id'); + return $this->hasManyThrough('LimitRepetition', 'Limit', 'component_id'); } /** diff --git a/app/models/Category.php b/app/models/Category.php index c8258373d5..50dda8a466 100644 --- a/app/models/Category.php +++ b/app/models/Category.php @@ -1,26 +1,5 @@ 'required|between:1,100|alphabasic', 'class' => 'required', ]; + protected $dates = ['deleted_at', 'created_at', 'updated_at']; protected $fillable = ['name', 'user_id']; protected $subclassField = 'class'; protected $table = 'components'; + use SoftDeletingTrait, ValidatingTrait; /** * TODO remove this method in favour of something in the FireflyIII libraries. diff --git a/app/models/Limit.php b/app/models/Limit.php index 6f7b0ec9d2..a215c98623 100644 --- a/app/models/Limit.php +++ b/app/models/Limit.php @@ -2,35 +2,12 @@ use Carbon\Carbon; use Illuminate\Database\QueryException; -use LaravelBook\Ardent\Ardent as Ardent; +use Watson\Validating\ValidatingTrait; - -/** - * Limit - * - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property integer $component_id - * @property \Carbon\Carbon $startdate - * @property float $amount - * @property boolean $repeats - * @property string $repeat_freq - * @property-read \Budget $budget - * @property-read \Component $component - * @property-read \Illuminate\Database\Eloquent\Collection|\LimitRepetition[] $limitrepetitions - * @method static \Illuminate\Database\Query\Builder|\Limit whereId($value) - * @method static \Illuminate\Database\Query\Builder|\Limit whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Limit whereUpdatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Limit whereComponentId($value) - * @method static \Illuminate\Database\Query\Builder|\Limit whereStartdate($value) - * @method static \Illuminate\Database\Query\Builder|\Limit whereAmount($value) - * @method static \Illuminate\Database\Query\Builder|\Limit whereRepeats($value) - * @method static \Illuminate\Database\Query\Builder|\Limit whereRepeatFreq($value) - */ -class Limit extends Ardent +class Limit extends Eloquent { + use ValidatingTrait; public static $rules = [ 'component_id' => 'required|exists:components,id', diff --git a/app/models/LimitRepetition.php b/app/models/LimitRepetition.php index 750191030a..07e9da433b 100644 --- a/app/models/LimitRepetition.php +++ b/app/models/LimitRepetition.php @@ -1,30 +1,11 @@ 'required|exists:limits,id', @@ -41,6 +22,14 @@ class LimitRepetition extends Ardent return ['created_at', 'updated_at', 'startdate', 'enddate']; } + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function limit() + { + return $this->belongsTo('Limit'); + } + /** * TODO see if this scope is still used. * @@ -72,15 +61,6 @@ class LimitRepetition extends Ardent return floatval($sum); } - /** - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo - */ - public function limit() - { - return $this->belongsTo('Limit'); - } - - /** * TODO remove this method in favour of something in the FireflyIII libraries. * diff --git a/app/models/Piggybank.php b/app/models/Piggybank.php index 291e96577f..a35f60e67d 100644 --- a/app/models/Piggybank.php +++ b/app/models/Piggybank.php @@ -1,51 +1,10 @@ 'required|exists:accounts,id', // link to Account 'name' => 'required|between:1,255', // name @@ -126,11 +85,12 @@ class Piggybank extends Ardent return $this->currentRep; } if ($this->repeats == 0) { - $rep = $this->piggybankrepetitions()->first(['piggybank_repetitions.*']); + $rep = $this->piggybankrepetitions()->first(['piggybank_repetitions.*']); $this->currentRep = $rep; + return $rep; } else { - $query = $this->piggybankrepetitions()->where( + $query = $this->piggybankrepetitions()->where( function ($q) { $q->where( @@ -160,8 +120,8 @@ class Piggybank extends Ardent } ) - ->orderBy('startdate', 'ASC'); - $result = $query->first(['piggybank_repetitions.*']); + ->orderBy('startdate', 'ASC'); + $result = $query->first(['piggybank_repetitions.*']); $this->currentRep = $result; \Log::debug('Found relevant rep in currentRelevantRep(): ' . $result->id); diff --git a/app/models/PiggybankEvent.php b/app/models/PiggybankEvent.php index bd2f2d55f3..ecb85a8654 100644 --- a/app/models/PiggybankEvent.php +++ b/app/models/PiggybankEvent.php @@ -1,31 +1,10 @@ 'required|exists:piggybanks,id', diff --git a/app/models/PiggybankRepetition.php b/app/models/PiggybankRepetition.php index 750a9d9829..a7cfe38bb5 100644 --- a/app/models/PiggybankRepetition.php +++ b/app/models/PiggybankRepetition.php @@ -1,31 +1,11 @@ 'required|exists:piggybanks,id', @@ -66,11 +46,14 @@ class PiggybankRepetition extends Ardent return $this->belongsTo('Piggybank'); } - public function scopeStarts(Builder $query, Carbon $date) { - $query->where('startdate',$date->format('Y-m-d')); + public function scopeStarts(Builder $query, Carbon $date) + { + $query->where('startdate', $date->format('Y-m-d')); } - public function scopeTargets(Builder $query, Carbon $date) { - $query->where('targetdate',$date->format('Y-m-d')); + + public function scopeTargets(Builder $query, Carbon $date) + { + $query->where('targetdate', $date->format('Y-m-d')); } diff --git a/app/models/Preference.php b/app/models/Preference.php index 2638708714..0f3c9700cf 100644 --- a/app/models/Preference.php +++ b/app/models/Preference.php @@ -1,27 +1,9 @@ 'required|exists:users,id', 'name' => 'required|between:1,255', 'data' => 'required']; diff --git a/app/models/RecurringTransaction.php b/app/models/RecurringTransaction.php index 7c54f69e1c..b3f5c4e9ae 100644 --- a/app/models/RecurringTransaction.php +++ b/app/models/RecurringTransaction.php @@ -1,43 +1,11 @@ 'required|exists:users,id', @@ -63,6 +31,7 @@ class RecurringTransaction extends Ardent /** * TODO remove this method in favour of something in the FireflyIII libraries. + * * @return null */ public function lastFoundMatch() diff --git a/app/models/Reminder.php b/app/models/Reminder.php index 10b4de7a24..8b61d63db2 100644 --- a/app/models/Reminder.php +++ b/app/models/Reminder.php @@ -1,42 +1,18 @@ morphTo(); } + public function scopeDateIs($query, Carbon $start, Carbon $end) + { + return $query->where('startdate', $start->format('Y-m-d'))->where('enddate', $end->format('Y-m-d')); + } + + /** + * @param $value + */ + public function setDataAttribute($value) + { + $this->attributes['data'] = json_encode($value); + } + /** * User * @@ -67,23 +56,4 @@ class Reminder extends Ardent } - public function scopeDateIs($query, Carbon $start, Carbon $end) - { - return $query->where('startdate', $start->format('Y-m-d'))->where('enddate', $end->format('Y-m-d')); - } - - public function getDataAttribute($value) - { - return json_decode($value); - } - - /** - * @param $value - */ - public function setDataAttribute($value) - { - $this->attributes['data'] = json_encode($value); - } - - } \ No newline at end of file diff --git a/app/models/Transaction.php b/app/models/Transaction.php index 8f21da2f14..6e549cee8b 100644 --- a/app/models/Transaction.php +++ b/app/models/Transaction.php @@ -1,44 +1,13 @@ 'numeric|required|exists:accounts,id', 'piggybank_id' => 'numeric|exists:piggybanks,id', diff --git a/app/models/TransactionCurrency.php b/app/models/TransactionCurrency.php index 0d7dd981aa..9fded03565 100644 --- a/app/models/TransactionCurrency.php +++ b/app/models/TransactionCurrency.php @@ -1,24 +1,13 @@ 'required|in:balance' - ]; + public static $rules + = [ + 'relation' => 'required|in:balance' + ]; /** * @return array diff --git a/app/models/TransactionJournal.php b/app/models/TransactionJournal.php index f6965946a7..61dd4424c9 100644 --- a/app/models/TransactionJournal.php +++ b/app/models/TransactionJournal.php @@ -1,77 +1,13 @@ 'required|exists:transaction_types,id', @@ -268,6 +204,11 @@ class TransactionJournal extends Ardent return $this->belongsTo('TransactionType'); } + public function transactiongroups() + { + return $this->belongsToMany('TransactionGroup'); + } + /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */ @@ -286,9 +227,4 @@ class TransactionJournal extends Ardent return $this->belongsTo('User'); } - public function transactiongroups() - { - return $this->belongsToMany('TransactionGroup'); - } - } \ No newline at end of file diff --git a/app/models/TransactionRelation.php b/app/models/TransactionRelation.php index ed4fb6550c..93109b2490 100644 --- a/app/models/TransactionRelation.php +++ b/app/models/TransactionRelation.php @@ -1,11 +1,6 @@