Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14101242
D8186.id18511.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D8186.id18511.diff
View Options
diff --git a/resources/sql/autopatches/20140210.herald.rule-condition-mig.php b/resources/sql/autopatches/20140210.herald.rule-condition-mig.php
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20140210.herald.rule-condition-mig.php
@@ -0,0 +1,31 @@
+<?php
+
+$table = new HeraldCondition();
+$conn_w = $table->establishConnection('w');
+
+echo "Migrating Herald conditions of type Herald rule from IDs to PHIDs...\n";
+foreach (new LiskMigrationIterator($table) as $condition) {
+ if ($condition->getFieldName() != HeraldAdapter::FIELD_RULE) {
+ continue;
+ }
+
+ $value = $condition->getValue();
+ if (!is_numeric($value)) {
+ continue;
+ }
+ $id = $condition->getID();
+ echo "Updating condition {$id}...\n";
+
+ $rule = id(new HeraldRuleQuery())
+ ->setViewer(PhabricatorUser::getOmnipotentUser())
+ ->withIDs(array($value))
+ ->executeOne();
+
+ queryfx(
+ $conn_w,
+ 'UPDATE %T SET value = %s WHERE id = %d',
+ $table->getTableName(),
+ json_encode($rule->getPHID()),
+ $id);
+}
+echo "Done.\n";
diff --git a/src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php b/src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php
--- a/src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php
+++ b/src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php
@@ -44,7 +44,6 @@
self::FIELD_DIFFERENTIAL_REVIEWERS,
self::FIELD_DIFFERENTIAL_CCS,
self::FIELD_IS_MERGE_COMMIT,
- self::FIELD_RULE,
),
parent::getFields());
}
diff --git a/src/applications/diffusion/herald/HeraldPreCommitRefAdapter.php b/src/applications/diffusion/herald/HeraldPreCommitRefAdapter.php
--- a/src/applications/diffusion/herald/HeraldPreCommitRefAdapter.php
+++ b/src/applications/diffusion/herald/HeraldPreCommitRefAdapter.php
@@ -41,7 +41,6 @@
self::FIELD_REPOSITORY_PROJECTS,
self::FIELD_PUSHER,
self::FIELD_PUSHER_PROJECTS,
- self::FIELD_RULE,
),
parent::getFields());
}
diff --git a/src/applications/herald/controller/HeraldRuleController.php b/src/applications/herald/controller/HeraldRuleController.php
--- a/src/applications/herald/controller/HeraldRuleController.php
+++ b/src/applications/herald/controller/HeraldRuleController.php
@@ -414,7 +414,7 @@
}
$all_rules = $this->loadRulesThisRuleMayDependUpon($rule);
- $all_rules = mpull($all_rules, 'getName', 'getID');
+ $all_rules = mpull($all_rules, 'getName', 'getPHID');
asort($all_rules);
$all_fields = $adapter->getFieldNameMap();
@@ -633,6 +633,9 @@
->execute();
}
+ // A rule must be enabled to be useful
+ $all_rules = mfilter($all_rules, 'getIsDisabled', true);
+
// A rule can not depend upon itself.
unset($all_rules[$rule->getID()]);
diff --git a/src/applications/herald/engine/HeraldEngine.php b/src/applications/herald/engine/HeraldEngine.php
--- a/src/applications/herald/engine/HeraldEngine.php
+++ b/src/applications/herald/engine/HeraldEngine.php
@@ -20,8 +20,8 @@
return $this->dryRun;
}
- public function getRule($id) {
- return idx($this->rules, $id);
+ public function getRule($phid) {
+ return idx($this->rules, $phid);
}
public function loadRulesForAdapter(HeraldAdapter $adapter) {
@@ -49,7 +49,7 @@
assert_instances_of($rules, 'HeraldRule');
$t_start = microtime(true);
- $rules = mpull($rules, null, 'getID');
+ $rules = mpull($rules, null, 'getPHID');
$this->transcript = new HeraldTranscript();
$this->transcript->setObjectPHID((string)$object->getPHID());
@@ -59,7 +59,7 @@
$this->object = $object;
$effects = array();
- foreach ($rules as $id => $rule) {
+ foreach ($rules as $phid => $rule) {
$this->stack = array();
try {
if (!$this->getDryRun() &&
@@ -70,7 +70,7 @@
// applied a single time, and it's already been applied...
// That means automatic failure.
$xscript = id(new HeraldRuleTranscript())
- ->setRuleID($id)
+ ->setRuleID($rule->getID())
->setResult(false)
->setRuleName($rule->getName())
->setRuleOwner($rule->getAuthorPHID())
@@ -102,7 +102,7 @@
}
$rule_matches = false;
}
- $this->results[$id] = $rule_matches;
+ $this->results[$phid] = $rule_matches;
if ($rule_matches) {
foreach ($this->getRuleEffects($rule, $object) as $effect) {
@@ -210,25 +210,25 @@
HeraldRule $rule,
HeraldAdapter $object) {
- $id = $rule->getID();
+ $phid = $rule->getPHID();
- if (isset($this->results[$id])) {
+ if (isset($this->results[$phid])) {
// If we've already evaluated this rule because another rule depends
// on it, we don't need to reevaluate it.
- return $this->results[$id];
+ return $this->results[$phid];
}
- if (isset($this->stack[$id])) {
+ if (isset($this->stack[$phid])) {
// We've recursed, fail all of the rules on the stack. This happens when
// there's a dependency cycle with "Rule conditions match for rule ..."
// conditions.
- foreach ($this->stack as $rule_id => $ignored) {
- $this->results[$rule_id] = false;
+ foreach ($this->stack as $rule_phid => $ignored) {
+ $this->results[$rule_phid] = false;
}
throw new HeraldRecursiveConditionsException();
}
- $this->stack[$id] = true;
+ $this->stack[$phid] = true;
$all = $rule->getMustMatchAll();
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 27, 3:54 PM (10 h, 57 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6795239
Default Alt Text
D8186.id18511.diff (5 KB)
Attached To
Mode
D8186: Herald - make herald condition of herald rule display better
Attached
Detach File
Event Timeline
Log In to Comment