From 094922bcb930006333ecbed480d38bb7612769c5 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 11 Feb 2014 07:45:26 -0800 Subject: [PATCH] Support "only the first time" in Maniphest Summary: Ref T4403. Implements "only the first time" for Maniphest rules, and fixes the trigger itself. The trigger would never fire and block rules because it was comparing a string (like "first") to an int (like 0). The "only" vs "every" stuff is contributed and I should have pushed back harder on this toInt / toString stuff. Maybe I'll just get rid of it; it purely causes confusion and problems. Test Plan: Wrote an "only the first time" rule, ran it twice, it applied once. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T4403 Differential Revision: https://secure.phabricator.com/D8193 --- .../herald/adapter/HeraldManiphestTaskAdapter.php | 7 +++++++ src/applications/herald/engine/HeraldEngine.php | 8 ++++++-- src/applications/herald/storage/HeraldRule.php | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php b/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php index aea6f10530..d4cbfcab2f 100644 --- a/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php +++ b/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php @@ -19,6 +19,13 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter { 'React to tasks being created or updated.'); } + public function getRepetitionOptions() { + return array( + HeraldRepetitionPolicyConfig::EVERY, + HeraldRepetitionPolicyConfig::FIRST, + ); + } + public function supportsRuleType($rule_type) { switch ($rule_type) { case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL: diff --git a/src/applications/herald/engine/HeraldEngine.php b/src/applications/herald/engine/HeraldEngine.php index acc9556c97..5e62a8e19d 100644 --- a/src/applications/herald/engine/HeraldEngine.php +++ b/src/applications/herald/engine/HeraldEngine.php @@ -61,10 +61,14 @@ final class HeraldEngine { $effects = array(); foreach ($rules as $phid => $rule) { $this->stack = array(); + + $policy_first = HeraldRepetitionPolicyConfig::FIRST; + $policy_first_int = HeraldRepetitionPolicyConfig::toInt($policy_first); + $is_first_only = ($rule->getRepetitionPolicy() == $policy_first_int); + try { if (!$this->getDryRun() && - ($rule->getRepetitionPolicy() == - HeraldRepetitionPolicyConfig::FIRST) && + $is_first_only && $rule->getRuleApplied($object->getPHID())) { // This is not a dry run, and this rule is only supposed to be // applied a single time, and it's already been applied... diff --git a/src/applications/herald/storage/HeraldRule.php b/src/applications/herald/storage/HeraldRule.php index 81aa6125ba..7610935460 100644 --- a/src/applications/herald/storage/HeraldRule.php +++ b/src/applications/herald/storage/HeraldRule.php @@ -17,7 +17,7 @@ final class HeraldRule extends HeraldDAO protected $isDisabled = 0; protected $triggerObjectPHID; - protected $configVersion = 30; + protected $configVersion = 31; // phids for which this rule has been applied private $ruleApplied = self::ATTACHABLE; -- 2.51.2