Gave all rule actions some logging. #322

This commit is contained in:
James Cole 2016-09-21 20:12:04 +02:00
parent dc9fe58536
commit d221ea68d0
10 changed files with 42 additions and 2 deletions

View File

@ -15,6 +15,7 @@ namespace FireflyIII\Rules\Actions;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class AddTag
@ -44,14 +45,20 @@ class AddTag implements ActionInterface
*/
public function act(TransactionJournal $journal): bool
{
// journal has this tag maybe?
$tag = Tag::firstOrCreateEncrypted(['tag' => $this->action->action_value, 'user_id' => $journal->user->id]);
$count = $journal->tags()->where('tag_id', $tag->id)->count();
if ($count == 0) {
if ($count === 0) {
$journal->tags()->save($tag);
Log::debug(sprintf('RuleAction AddTag. Added tag #%d ("%s") to journal %d.', $tag->id, $tag->tag, $journal->id));
return true;
}
Log::debug(sprintf('RuleAction AddTag fired but tag %d ("%s") was already added to journal %d.', $tag->id, $tag->tag, $journal->id));
return true;
}
}

View File

@ -13,6 +13,7 @@ namespace FireflyIII\Rules\Actions;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class AppendDescription
@ -42,6 +43,7 @@ class AppendDescription implements ActionInterface
*/
public function act(TransactionJournal $journal): bool
{
Log::debug(sprintf('RuleAction AppendDescription appended "%s" to "%s".', $this->action->action_value, $journal->description));
$journal->description = $journal->description . $this->action->action_value;
$journal->save();

View File

@ -11,9 +11,9 @@ declare(strict_types = 1);
namespace FireflyIII\Rules\Actions;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class ClearBudget
@ -44,6 +44,7 @@ class ClearBudget implements ActionInterface
public function act(TransactionJournal $journal): bool
{
$journal->budgets()->detach();
Log::debug(sprintf('RuleAction ClearBudget removed all budgets from journal %d.', $journal->id));
return true;
}

View File

@ -44,6 +44,7 @@ class ClearCategory implements ActionInterface
public function act(TransactionJournal $journal): bool
{
$journal->categories()->detach();
Log::debug(sprintf('RuleAction ClearCategory removed all categories from journal %d.', $journal->id));
return true;
}

View File

@ -13,6 +13,7 @@ namespace FireflyIII\Rules\Actions;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class AppendDescription
@ -42,9 +43,11 @@ class PrependDescription implements ActionInterface
*/
public function act(TransactionJournal $journal): bool
{
Log::debug(sprintf('RuleAction PrependDescription prepended "%s" to "%s".', $this->action->action_value, $journal->description));
$journal->description = $this->action->action_value . $journal->description;
$journal->save();
return true;
}
}

View File

@ -14,6 +14,7 @@ namespace FireflyIII\Rules\Actions;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class RemoveAllTags
@ -42,6 +43,7 @@ class RemoveAllTags implements ActionInterface
*/
public function act(TransactionJournal $journal): bool
{
Log::debug(sprintf('RuleAction ClearCategory removed all tags from journal %d.', $journal->id));
$journal->tags()->detach();
return true;

View File

@ -15,6 +15,7 @@ namespace FireflyIII\Rules\Actions;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class RemoveTag
@ -54,8 +55,12 @@ class RemoveTag implements ActionInterface
)->first();
if (!is_null($tag)) {
Log::debug(sprintf('RuleAction RemoveTag removed tag #%d ("%s") from journal #%d.', $tag->id, $tag->tag, $journal->id));
$journal->tags()->detach([$tag->id]);
return true;
}
Log::debug(sprintf('RuleAction RemoveTag tried to remove tag "%s" from journal #%d but no such tag exists.', $name, $journal->id));
return true;
}

View File

@ -16,6 +16,7 @@ use FireflyIII\Models\Budget;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use Log;
/**
* Class SetBudget
@ -55,9 +56,13 @@ class SetBudget implements ActionInterface
}
)->first();
if (!is_null($budget)) {
Log::debug(sprintf('RuleAction SetBudget set the budget of journal #%d to budget #%d ("%s").', $journal->id, $budget->id, $budget->name));
$journal->budgets()->sync([$budget->id]);
}
Log::debug(sprintf('RuleAction SetBudget could not set budget of journal #%d to "%s" because no such budget exists.', $journal->id, $search));
return true;
}
}

View File

@ -15,6 +15,7 @@ namespace FireflyIII\Rules\Actions;
use FireflyIII\Models\Category;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class SetCategory
@ -48,6 +49,8 @@ class SetCategory implements ActionInterface
$category = Category::firstOrCreateEncrypted(['name' => $name, 'user_id' => $journal->user->id]);
$journal->categories()->sync([$category->id]);
Log::debug(sprintf('RuleAction SetCategory set the category of journal #%d to budget #%d ("%s").', $journal->id, $category->id, $category->name));
return true;
}
}

View File

@ -13,6 +13,7 @@ namespace FireflyIII\Rules\Actions;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class SetDescription
@ -42,9 +43,19 @@ class SetDescription implements ActionInterface
*/
public function act(TransactionJournal $journal): bool
{
$oldDescription = $journal->description;
$journal->description = $this->action->action_value;
$journal->save();
Log::debug(
sprintf(
'RuleAction SetDescription changed the description of journal #%d from "%s" to "%s".', $journal->id,
$oldDescription,
$this->action->action_value
)
);
return true;
}
}