/** * @covers FireflyIII\Repositories\Budget\BudgetRepository::cleanupBudgets * @covers FireflyIII\Providers\EventServiceProvider::boot */ public function testCleanupBudgets() { // create some budgets: for ($i = 0; $i < 3; $i++) { $budget = FactoryMuffin::create('FireflyIII\\Models\\Budget'); $limit = FactoryMuffin::create('FireflyIII\\Models\\BudgetLimit'); $limit->budget_id = $budget->id; $limit->amount = 0; $limit->save(); } $this->object->cleanupBudgets(); $this->assertCount(0, BudgetLimit::get()); }
public function moveComponentIdToBudgetId() { BudgetLimit::get()->each(function (BudgetLimit $bl) { Log::debug('Now at budgetLimit #' . $bl->id . ' with component_id: ' . $bl->component_id); $component = Component::find($bl->component_id); if ($component) { Log::debug('Found component with id #' . $component->id . ' and name ' . $component->name); $budget = Budget::whereName($component->name)->whereUserId($component->user_id)->first(); if ($budget) { Log::debug('Found a budget with ID #' . $budget->id . ' and name ' . $budget->name); $bl->budget_id = $budget->id; $bl->save(); Log::debug('Connected budgetLimit #' . $bl->id . ' to budget_id' . $budget->id); } else { Log::debug('Could not find a matching budget with name ' . $component->name); } } else { Log::debug('Could not find a component with id ' . $bl->component_id); } }); }
private function updateComponentInBudgetLimits() { BudgetLimit::get()->each(function (BudgetLimit $bl) { $budgetId = $bl->budget_id; $budget = Budget::find($budgetId); if ($budget) { $component = Component::where('class', 'Budget')->where('user_id', $budget->user_id)->where('name', $budget->name)->first(); if ($component) { $bl->component_id = $component->id; $bl->save(); } } }); }