mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 10:33:30 +00:00
Remove matchesAnything
This commit is contained in:
@@ -30,15 +30,6 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
*/
|
*/
|
||||||
class RuleTrigger extends Model
|
class RuleTrigger extends Model
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Checks whether this trigger will match all transactions
|
|
||||||
* For example: amount > 0 or description starts with ''
|
|
||||||
*/
|
|
||||||
public function matchesAnything()
|
|
||||||
{
|
|
||||||
return TriggerFactory::getTrigger($this, new TransactionJournal)->matchesAnything();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
*/
|
*/
|
||||||
|
@@ -64,18 +64,6 @@ class AmountExactly implements TriggerInterface
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @{inheritdoc}
|
|
||||||
*
|
|
||||||
* @see TriggerInterface::matchesAnything
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function matchesAnything()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
@@ -64,18 +64,6 @@ class AmountLess implements TriggerInterface
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @{inheritdoc}
|
|
||||||
*
|
|
||||||
* @see TriggerInterface::matchesAnything
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function matchesAnything()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
@@ -64,18 +64,6 @@ class AmountMore implements TriggerInterface
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @{inheritdoc}
|
|
||||||
*
|
|
||||||
* @see TriggerInterface::matchesAnything
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function matchesAnything()
|
|
||||||
{
|
|
||||||
return bccomp('0', $this->trigger->trigger_value) === 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
@@ -64,18 +64,6 @@ class DescriptionContains implements TriggerInterface
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @{inheritdoc}
|
|
||||||
*
|
|
||||||
* @see TriggerInterface::matchesAnything
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function matchesAnything()
|
|
||||||
{
|
|
||||||
return $this->trigger->trigger_value === "";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
@@ -63,18 +63,6 @@ class DescriptionEnds implements TriggerInterface
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @{inheritdoc}
|
|
||||||
*
|
|
||||||
* @see TriggerInterface::matchesAnything
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function matchesAnything()
|
|
||||||
{
|
|
||||||
return $this->trigger->trigger_value === "";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
@@ -38,18 +38,6 @@ class DescriptionIs implements TriggerInterface
|
|||||||
$this->journal = $journal;
|
$this->journal = $journal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @{inheritdoc}
|
|
||||||
*
|
|
||||||
* @see TriggerInterface::matchesAnything
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function matchesAnything()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
@@ -38,18 +38,6 @@ class DescriptionStarts implements TriggerInterface
|
|||||||
$this->journal = $journal;
|
$this->journal = $journal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @{inheritdoc}
|
|
||||||
*
|
|
||||||
* @see TriggerInterface::matchesAnything
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function matchesAnything()
|
|
||||||
{
|
|
||||||
return $this->trigger->trigger_value === "";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
@@ -38,18 +38,6 @@ class FromAccountContains implements TriggerInterface
|
|||||||
$this->journal = $journal;
|
$this->journal = $journal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @{inheritdoc}
|
|
||||||
*
|
|
||||||
* @see TriggerInterface::matchesAnything
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function matchesAnything()
|
|
||||||
{
|
|
||||||
return $this->trigger->trigger_value === "";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
@@ -38,18 +38,6 @@ class FromAccountEnds implements TriggerInterface
|
|||||||
$this->journal = $journal;
|
$this->journal = $journal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @{inheritdoc}
|
|
||||||
*
|
|
||||||
* @see TriggerInterface::matchesAnything
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function matchesAnything()
|
|
||||||
{
|
|
||||||
return $this->trigger->trigger_value === "";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
@@ -63,18 +63,6 @@ class FromAccountIs implements TriggerInterface
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @{inheritdoc}
|
|
||||||
*
|
|
||||||
* @see TriggerInterface::matchesAnything
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function matchesAnything()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
@@ -63,18 +63,6 @@ class FromAccountStarts implements TriggerInterface
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @{inheritdoc}
|
|
||||||
*
|
|
||||||
* @see TriggerInterface::matchesAnything
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function matchesAnything()
|
|
||||||
{
|
|
||||||
return $this->trigger->trigger_value === "";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
@@ -38,18 +38,6 @@ class ToAccountContains implements TriggerInterface
|
|||||||
$this->journal = $journal;
|
$this->journal = $journal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @{inheritdoc}
|
|
||||||
*
|
|
||||||
* @see TriggerInterface::matchesAnything
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function matchesAnything()
|
|
||||||
{
|
|
||||||
return $this->trigger->trigger_value === "";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
@@ -38,18 +38,6 @@ class ToAccountEnds implements TriggerInterface
|
|||||||
$this->journal = $journal;
|
$this->journal = $journal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @{inheritdoc}
|
|
||||||
*
|
|
||||||
* @see TriggerInterface::matchesAnything
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function matchesAnything()
|
|
||||||
{
|
|
||||||
return $this->trigger->trigger_value === "";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
@@ -38,18 +38,6 @@ class ToAccountIs implements TriggerInterface
|
|||||||
$this->journal = $journal;
|
$this->journal = $journal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @{inheritdoc}
|
|
||||||
*
|
|
||||||
* @see TriggerInterface::matchesAnything
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function matchesAnything()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
@@ -38,18 +38,6 @@ class ToAccountStarts implements TriggerInterface
|
|||||||
$this->journal = $journal;
|
$this->journal = $journal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @{inheritdoc}
|
|
||||||
*
|
|
||||||
* @see TriggerInterface::matchesAnything
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function matchesAnything()
|
|
||||||
{
|
|
||||||
return $this->trigger->trigger_value === "";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
@@ -38,18 +38,6 @@ class TransactionType implements TriggerInterface
|
|||||||
$this->journal = $journal;
|
$this->journal = $journal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @{inheritdoc}
|
|
||||||
*
|
|
||||||
* @see TriggerInterface::matchesAnything
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function matchesAnything()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
@@ -46,22 +46,6 @@ interface TriggerInterface
|
|||||||
*/
|
*/
|
||||||
public static function willMatchEverything($value = null);
|
public static function willMatchEverything($value = null);
|
||||||
|
|
||||||
/**
|
|
||||||
* A trigger is said to "match anything", or match any given transaction,
|
|
||||||
* when the trigger value is very vague or has no restrictions. Easy examples
|
|
||||||
* are the "AmountMore"-trigger combined with an amount of 0: any given transaction
|
|
||||||
* has an amount of more than zero! Other examples are all the "Description"-triggers
|
|
||||||
* which have hard time handling empty trigger values such as "" or "*" (wild cards).
|
|
||||||
*
|
|
||||||
* If the user tries to create such a trigger, this method MUST return true so Firefly III
|
|
||||||
* can stop the storing / updating the trigger. If the trigger is in any way restrictive
|
|
||||||
* (even if it will still include 99.9% of the users transactions), this method MUST return
|
|
||||||
* false.
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function matchesAnything();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
@@ -60,18 +60,6 @@ class UserAction implements TriggerInterface
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @{inheritdoc}
|
|
||||||
*
|
|
||||||
* @see TriggerInterface::matchesAnything
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function matchesAnything()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This trigger is always triggered, because the rule that it is a part of has been pre-selected on this condition.
|
* This trigger is always triggered, because the rule that it is a part of has been pre-selected on this condition.
|
||||||
*
|
*
|
||||||
|
@@ -14,6 +14,7 @@ use FireflyIII\Models\Budget;
|
|||||||
use FireflyIII\Models\PiggyBank;
|
use FireflyIII\Models\PiggyBank;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
|
use FireflyIII\Rules\Triggers\TriggerInterface;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Contracts\Encryption\DecryptException;
|
use Illuminate\Contracts\Encryption\DecryptException;
|
||||||
use Illuminate\Validation\Validator;
|
use Illuminate\Validation\Validator;
|
||||||
@@ -151,18 +152,34 @@ class FireflyValidator extends Validator
|
|||||||
if (is_array($this->data['rule-trigger'])) {
|
if (is_array($this->data['rule-trigger'])) {
|
||||||
$name = $this->getRuleTriggerName($index);
|
$name = $this->getRuleTriggerName($index);
|
||||||
$value = $this->getRuleTriggerValue($index);
|
$value = $this->getRuleTriggerValue($index);
|
||||||
|
|
||||||
|
// break on some easy checks:
|
||||||
switch ($name) {
|
switch ($name) {
|
||||||
default:
|
|
||||||
return true;
|
|
||||||
case 'amount_less':
|
case 'amount_less':
|
||||||
return is_numeric($value);
|
$result = is_numeric($value);
|
||||||
|
if ($result === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'transaction_type':
|
case 'transaction_type':
|
||||||
$count = TransactionType::where('type', $value)->count();
|
$count = TransactionType::where('type', $value)->count();
|
||||||
|
if (!($count === 1)) {
|
||||||
return $count === 1;
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'invalid':
|
case 'invalid':
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// still a special case where the trigger is
|
||||||
|
// triggered in such a way that it would trigger ANYTHING. We can check for such things
|
||||||
|
// with function willmatcheverything
|
||||||
|
// we know which class it is so dont bother checking that.
|
||||||
|
$classes = Config::get('firefly.rule-triggers');
|
||||||
|
/** @var TriggerInterface $class */
|
||||||
|
$class = $classes[$name];
|
||||||
|
|
||||||
|
return !($class::willMatchEverything($value));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user