Skip to content

Firefly III: a personal finances manager

Added method for triggers to check whether they match all transactions

Robert Horlings7c8c82edd7b2
diff --git a/app/Rules/Triggers/AmountExactly.php b/app/Rules/Triggers/AmountExactly.php
index 02045a42f8..998d851dd5 100644
--- a/app/Rules/Triggers/AmountExactly.php
+++ b/app/Rules/Triggers/AmountExactly.php
@@ -62,4 +62,11 @@ class AmountExactly implements TriggerInterface
return false;
}
+
+ /**
+ * Checks whether this trigger will match all transactions
+ * For example: amount > 0 or description starts with ''
+ * @return bool
+ */
+ public function matchesAnything() { return false; }
}
diff --git a/app/Rules/Triggers/AmountLess.php b/app/Rules/Triggers/AmountLess.php
index cfad91f24b..e90428a233 100644
--- a/app/Rules/Triggers/AmountLess.php
+++ b/app/Rules/Triggers/AmountLess.php
@@ -62,4 +62,11 @@ class AmountLess implements TriggerInterface
return false;
}
+
+ /**
+ * Checks whether this trigger will match all transactions
+ * For example: amount > 0 or description starts with ''
+ * @return bool
+ */
+ public function matchesAnything() { return false; }
}
diff --git a/app/Rules/Triggers/AmountMore.php b/app/Rules/Triggers/AmountMore.php
index a7d6711f1f..4a1376dfe7 100644
--- a/app/Rules/Triggers/AmountMore.php
+++ b/app/Rules/Triggers/AmountMore.php
@@ -62,4 +62,13 @@ class AmountMore implements TriggerInterface
return false;
}
+
+ /**
+ * Checks whether this trigger will match all transactions
+ * This happens when the trigger_value is zero
+ * @return bool
+ */
+ public function matchesAnything() {
+ return bccomp('0', $this->trigger->trigger_value) === 0;
+ }
}
diff --git a/app/Rules/Triggers/DescriptionContains.php b/app/Rules/Triggers/DescriptionContains.php
index 4e5fe8428a..a26d8628d0 100644
--- a/app/Rules/Triggers/DescriptionContains.php
+++ b/app/Rules/Triggers/DescriptionContains.php
@@ -63,4 +63,13 @@ class DescriptionContains implements TriggerInterface
return false;
}
+
+ /**
+ * Checks whether this trigger will match all transactions
+ * This happens when the trigger_value is empty
+ * @return bool
+ */
+ public function matchesAnything() {
+ return $this->trigger->trigger_value === "";
+ }
}
diff --git a/app/Rules/Triggers/DescriptionEnds.php b/app/Rules/Triggers/DescriptionEnds.php
index b71009799a..fde345df80 100644
--- a/app/Rules/Triggers/DescriptionEnds.php
+++ b/app/Rules/Triggers/DescriptionEnds.php
@@ -72,4 +72,14 @@ class DescriptionEnds implements TriggerInterface
return false;
}
+
+ /**
+ * Checks whether this trigger will match all transactions
+ * This happens when the trigger_value is empty
+ * @return bool
+ */
+ public function matchesAnything() {
+ return $this->trigger->trigger_value === "";
+ }
+
}
diff --git a/app/Rules/Triggers/DescriptionIs.php b/app/Rules/Triggers/DescriptionIs.php
index 12bc48b697..2d38bc46f6 100644
--- a/app/Rules/Triggers/DescriptionIs.php
+++ b/app/Rules/Triggers/DescriptionIs.php
@@ -58,4 +58,11 @@ class DescriptionIs implements TriggerInterface
return false;
}
+
+ /**
+ * Checks whether this trigger will match all transactions
+ * @return bool
+ */
+ public function matchesAnything() { return false; }
+
}
diff --git a/app/Rules/Triggers/DescriptionStarts.php b/app/Rules/Triggers/DescriptionStarts.php
index 9b23e1253c..2b41bad3e3 100644
--- a/app/Rules/Triggers/DescriptionStarts.php
+++ b/app/Rules/Triggers/DescriptionStarts.php
@@ -60,4 +60,14 @@ class DescriptionStarts implements TriggerInterface
return false;
}
+
+ /**
+ * Checks whether this trigger will match all transactions
+ * This happens when the trigger_value is empty
+ * @return bool
+ */
+ public function matchesAnything() {
+ return $this->trigger->trigger_value === "";
+ }
+
}
diff --git a/app/Rules/Triggers/FromAccountContains.php b/app/Rules/Triggers/FromAccountContains.php
index 05badb6f7b..9da8cbd290 100644
--- a/app/Rules/Triggers/FromAccountContains.php
+++ b/app/Rules/Triggers/FromAccountContains.php
@@ -62,4 +62,14 @@ class FromAccountContains implements TriggerInterface
return false;
}
+
+ /**
+ * Checks whether this trigger will match all transactions
+ * This happens when the trigger_value is empty
+ * @return bool
+ */
+ public function matchesAnything() {
+ return $this->trigger->trigger_value === "";
+ }
+
}
diff --git a/app/Rules/Triggers/FromAccountEnds.php b/app/Rules/Triggers/FromAccountEnds.php
index e4b144bb87..26927c6370 100644
--- a/app/Rules/Triggers/FromAccountEnds.php
+++ b/app/Rules/Triggers/FromAccountEnds.php
@@ -72,4 +72,15 @@ class FromAccountEnds implements TriggerInterface
return false;
}
+
+
+ /**
+ * Checks whether this trigger will match all transactions
+ * This happens when the trigger_value is empty
+ * @return bool
+ */
+ public function matchesAnything() {
+ return $this->trigger->trigger_value === "";
+ }
+
}
diff --git a/app/Rules/Triggers/FromAccountIs.php b/app/Rules/Triggers/FromAccountIs.php
index 9fb084de93..1cdbc30521 100644
--- a/app/Rules/Triggers/FromAccountIs.php
+++ b/app/Rules/Triggers/FromAccountIs.php
@@ -58,4 +58,11 @@ class FromAccountIs implements TriggerInterface
return false;
}
+
+ /**
+ * Checks whether this trigger will match all transactions
+ * @return bool
+ */
+ public function matchesAnything() { return false; }
+
}
diff --git a/app/Rules/Triggers/FromAccountStarts.php b/app/Rules/Triggers/FromAccountStarts.php
index 6eea3179f4..43e8f915b9 100644
--- a/app/Rules/Triggers/FromAccountStarts.php
+++ b/app/Rules/Triggers/FromAccountStarts.php
@@ -60,4 +60,15 @@ class FromAccountStarts implements TriggerInterface
return false;
}
+
+
+ /**
+ * Checks whether this trigger will match all transactions
+ * This happens when the trigger_value is empty
+ * @return bool
+ */
+ public function matchesAnything() {
+ return $this->trigger->trigger_value === "";
+ }
+
}
diff --git a/app/Rules/Triggers/ToAccountContains.php b/app/Rules/Triggers/ToAccountContains.php
index 06d081bfac..0e291a904a 100644
--- a/app/Rules/Triggers/ToAccountContains.php
+++ b/app/Rules/Triggers/ToAccountContains.php
@@ -62,4 +62,15 @@ class ToAccountContains implements TriggerInterface
return false;
}
+
+
+ /**
+ * Checks whether this trigger will match all transactions
+ * This happens when the trigger_value is empty
+ * @return bool
+ */
+ public function matchesAnything() {
+ return $this->trigger->trigger_value === "";
+ }
+
}
diff --git a/app/Rules/Triggers/ToAccountEnds.php b/app/Rules/Triggers/ToAccountEnds.php
index 5637df0cb6..60784e4b6f 100644
--- a/app/Rules/Triggers/ToAccountEnds.php
+++ b/app/Rules/Triggers/ToAccountEnds.php
@@ -72,4 +72,14 @@ class ToAccountEnds implements TriggerInterface
return false;
}
+
+
+ /**
+ * Checks whether this trigger will match all transactions
+ * This happens when the trigger_value is empty
+ * @return bool
+ */
+ public function matchesAnything() {
+ return $this->trigger->trigger_value === "";
+ }
}
diff --git a/app/Rules/Triggers/ToAccountIs.php b/app/Rules/Triggers/ToAccountIs.php
index 1eb9f5623e..f11fdf272f 100644
--- a/app/Rules/Triggers/ToAccountIs.php
+++ b/app/Rules/Triggers/ToAccountIs.php
@@ -58,4 +58,11 @@ class ToAccountIs implements TriggerInterface
return false;
}
+
+ /**
+ * Checks whether this trigger will match all transactions
+ * @return bool
+ */
+ public function matchesAnything() { return false; }
+
}
diff --git a/app/Rules/Triggers/ToAccountStarts.php b/app/Rules/Triggers/ToAccountStarts.php
index 446a592d29..bf0ca5f5d7 100644
--- a/app/Rules/Triggers/ToAccountStarts.php
+++ b/app/Rules/Triggers/ToAccountStarts.php
@@ -60,4 +60,15 @@ class ToAccountStarts implements TriggerInterface
return false;
}
+
+
+ /**
+ * Checks whether this trigger will match all transactions
+ * This happens when the trigger_value is empty
+ * @return bool
+ */
+ public function matchesAnything() {
+ return $this->trigger->trigger_value === "";
+ }
+
}
diff --git a/app/Rules/Triggers/TransactionType.php b/app/Rules/Triggers/TransactionType.php
index 1a96720fc8..4d46520d50 100644
--- a/app/Rules/Triggers/TransactionType.php
+++ b/app/Rules/Triggers/TransactionType.php
@@ -57,4 +57,11 @@ class TransactionType implements TriggerInterface
return false;
}
+
+ /**
+ * Checks whether this trigger will match all transactions
+ * @return bool
+ */
+ public function matchesAnything() { return false; }
+
}
diff --git a/app/Rules/Triggers/TriggerInterface.php b/app/Rules/Triggers/TriggerInterface.php
index 074cacdd40..5a653a9d9f 100644
--- a/app/Rules/Triggers/TriggerInterface.php
+++ b/app/Rules/Triggers/TriggerInterface.php
@@ -32,4 +32,11 @@ interface TriggerInterface
* @return bool
*/
public function triggered();
+
+ /**
+ * Checks whether this trigger will match all transactions
+ * For example: amount > 0 or description starts with ''
+ * @return bool
+ */
+ public function matchesAnything();
}
diff --git a/app/Rules/Triggers/UserAction.php b/app/Rules/Triggers/UserAction.php
index 917f2d8822..4e576bd573 100644
--- a/app/Rules/Triggers/UserAction.php
+++ b/app/Rules/Triggers/UserAction.php
@@ -53,4 +53,10 @@ class UserAction implements TriggerInterface
return true;
}
+ /**
+ * Checks whether this trigger will match all transactions
+ * @return bool
+ */
+ public function matchesAnything() { return true; }
+
}