Page MenuHomePhorge

No OneTemporary

diff --git a/resources/sql/autopatches/20190909.herald.01.rebuild.php b/resources/sql/autopatches/20190909.herald.01.rebuild.php
new file mode 100644
index 0000000000..a29b7d2f45
--- /dev/null
+++ b/resources/sql/autopatches/20190909.herald.01.rebuild.php
@@ -0,0 +1,3 @@
+<?php
+
+PhabricatorRebuildIndexesWorker::rebuildObjectsWithQuery('HeraldRuleQuery');
diff --git a/src/applications/herald/engineextension/HeraldRuleIndexEngineExtension.php b/src/applications/herald/engineextension/HeraldRuleIndexEngineExtension.php
index 5df229ccd6..ca28116d4c 100644
--- a/src/applications/herald/engineextension/HeraldRuleIndexEngineExtension.php
+++ b/src/applications/herald/engineextension/HeraldRuleIndexEngineExtension.php
@@ -1,57 +1,71 @@
<?php
final class HeraldRuleIndexEngineExtension
extends PhabricatorEdgeIndexEngineExtension {
const EXTENSIONKEY = 'herald.actions';
public function getExtensionName() {
return pht('Herald Actions');
}
public function shouldIndexObject($object) {
if (!($object instanceof HeraldRule)) {
return false;
}
return true;
}
protected function getIndexEdgeType() {
return HeraldRuleActionAffectsObjectEdgeType::EDGECONST;
}
protected function getIndexDestinationPHIDs($object) {
$rule = $object;
$viewer = $this->getViewer();
$rule = id(new HeraldRuleQuery())
->setViewer($viewer)
->withIDs(array($rule->getID()))
->needConditionsAndActions(true)
->executeOne();
if (!$rule) {
return array();
}
$phids = array();
+ $fields = HeraldField::getAllFields();
+ foreach ($rule->getConditions() as $condition_record) {
+ $field = idx($fields, $condition_record->getFieldName());
+
+ if (!$field) {
+ continue;
+ }
+
+ $affected_phids = $field->getPHIDsAffectedByCondition($condition_record);
+ foreach ($affected_phids as $phid) {
+ $phids[] = $phid;
+ }
+ }
+
$actions = HeraldAction::getAllActions();
foreach ($rule->getActions() as $action_record) {
$action = idx($actions, $action_record->getAction());
if (!$action) {
continue;
}
foreach ($action->getPHIDsAffectedByAction($action_record) as $phid) {
$phids[] = $phid;
}
}
$phids = array_fuse($phids);
return array_keys($phids);
}
}
diff --git a/src/applications/herald/field/HeraldField.php b/src/applications/herald/field/HeraldField.php
index 611ea2cdb3..3df242712e 100644
--- a/src/applications/herald/field/HeraldField.php
+++ b/src/applications/herald/field/HeraldField.php
@@ -1,221 +1,243 @@
<?php
abstract class HeraldField extends Phobject {
private $adapter;
const STANDARD_BOOL = 'standard.bool';
const STANDARD_TEXT = 'standard.text';
const STANDARD_TEXT_LIST = 'standard.text.list';
const STANDARD_TEXT_MAP = 'standard.text.map';
const STANDARD_PHID = 'standard.phid';
const STANDARD_PHID_LIST = 'standard.phid.list';
const STANDARD_PHID_BOOL = 'standard.phid.bool';
const STANDARD_PHID_NULLABLE = 'standard.phid.nullable';
abstract public function getHeraldFieldName();
abstract public function getHeraldFieldValue($object);
public function getFieldGroupKey() {
return null;
}
public function getRequiredAdapterStates() {
return array();
}
protected function getHeraldFieldStandardType() {
throw new PhutilMethodNotImplementedException();
}
protected function getDatasource() {
throw new PhutilMethodNotImplementedException();
}
protected function getDatasourceValueMap() {
return null;
}
public function getHeraldFieldConditions() {
$standard_type = $this->getHeraldFieldStandardType();
switch ($standard_type) {
case self::STANDARD_BOOL:
return array(
HeraldAdapter::CONDITION_IS_TRUE,
HeraldAdapter::CONDITION_IS_FALSE,
);
case self::STANDARD_TEXT:
return array(
HeraldAdapter::CONDITION_CONTAINS,
HeraldAdapter::CONDITION_NOT_CONTAINS,
HeraldAdapter::CONDITION_IS,
HeraldAdapter::CONDITION_IS_NOT,
HeraldAdapter::CONDITION_REGEXP,
HeraldAdapter::CONDITION_NOT_REGEXP,
);
case self::STANDARD_PHID:
return array(
HeraldAdapter::CONDITION_IS_ANY,
HeraldAdapter::CONDITION_IS_NOT_ANY,
);
case self::STANDARD_PHID_LIST:
return array(
HeraldAdapter::CONDITION_INCLUDE_ALL,
HeraldAdapter::CONDITION_INCLUDE_ANY,
HeraldAdapter::CONDITION_INCLUDE_NONE,
HeraldAdapter::CONDITION_EXISTS,
HeraldAdapter::CONDITION_NOT_EXISTS,
);
case self::STANDARD_PHID_BOOL:
return array(
HeraldAdapter::CONDITION_EXISTS,
HeraldAdapter::CONDITION_NOT_EXISTS,
);
case self::STANDARD_PHID_NULLABLE:
return array(
HeraldAdapter::CONDITION_IS_ANY,
HeraldAdapter::CONDITION_IS_NOT_ANY,
HeraldAdapter::CONDITION_EXISTS,
HeraldAdapter::CONDITION_NOT_EXISTS,
);
case self::STANDARD_TEXT_LIST:
return array(
HeraldAdapter::CONDITION_CONTAINS,
HeraldAdapter::CONDITION_NOT_CONTAINS,
HeraldAdapter::CONDITION_REGEXP,
HeraldAdapter::CONDITION_NOT_REGEXP,
HeraldAdapter::CONDITION_EXISTS,
HeraldAdapter::CONDITION_NOT_EXISTS,
);
case self::STANDARD_TEXT_MAP:
return array(
HeraldAdapter::CONDITION_CONTAINS,
HeraldAdapter::CONDITION_NOT_CONTAINS,
HeraldAdapter::CONDITION_REGEXP,
HeraldAdapter::CONDITION_NOT_REGEXP,
HeraldAdapter::CONDITION_REGEXP_PAIR,
);
}
throw new Exception(
pht(
'Herald field "%s" has unknown standard type "%s".',
get_class($this),
$standard_type));
}
public function getHeraldFieldValueType($condition) {
$standard_type = $this->getHeraldFieldStandardType();
switch ($standard_type) {
case self::STANDARD_BOOL:
case self::STANDARD_PHID_BOOL:
return new HeraldEmptyFieldValue();
case self::STANDARD_TEXT:
case self::STANDARD_TEXT_LIST:
case self::STANDARD_TEXT_MAP:
switch ($condition) {
case HeraldAdapter::CONDITION_EXISTS:
case HeraldAdapter::CONDITION_NOT_EXISTS:
return new HeraldEmptyFieldValue();
default:
return new HeraldTextFieldValue();
}
case self::STANDARD_PHID:
case self::STANDARD_PHID_NULLABLE:
case self::STANDARD_PHID_LIST:
switch ($condition) {
case HeraldAdapter::CONDITION_EXISTS:
case HeraldAdapter::CONDITION_NOT_EXISTS:
return new HeraldEmptyFieldValue();
default:
$tokenizer = id(new HeraldTokenizerFieldValue())
->setKey($this->getHeraldFieldName())
->setDatasource($this->getDatasource());
$value_map = $this->getDatasourceValueMap();
if ($value_map !== null) {
$tokenizer->setValueMap($value_map);
}
return $tokenizer;
}
break;
}
throw new Exception(
pht(
'Herald field "%s" has unknown standard type "%s".',
get_class($this),
$standard_type));
}
abstract public function supportsObject($object);
public function getFieldsForObject($object) {
return array($this->getFieldConstant() => $this);
}
public function renderConditionValue(
PhabricatorUser $viewer,
$condition,
$value) {
$value_type = $this->getHeraldFieldValueType($condition);
$value_type->setViewer($viewer);
return $value_type->renderFieldValue($value);
}
public function getEditorValue(
PhabricatorUser $viewer,
$condition,
$value) {
$value_type = $this->getHeraldFieldValueType($condition);
$value_type->setViewer($viewer);
return $value_type->renderEditorValue($value);
}
+ public function getPHIDsAffectedByCondition(HeraldCondition $condition) {
+ $phids = array();
+
+ $standard_type = $this->getHeraldFieldStandardType();
+ switch ($standard_type) {
+ case self::STANDARD_PHID:
+ case self::STANDARD_PHID_NULLABLE:
+ $phid = $condition->getValue();
+ if ($phid) {
+ $phids[] = $phid;
+ }
+ break;
+ case self::STANDARD_PHID_LIST:
+ foreach ($condition->getValue() as $phid) {
+ $phids[] = $phid;
+ }
+ break;
+ }
+
+ return $phids;
+ }
+
final public function setAdapter(HeraldAdapter $adapter) {
$this->adapter = $adapter;
return $this;
}
final public function getAdapter() {
return $this->adapter;
}
final public function getFieldConstant() {
return $this->getPhobjectClassConstant(
'FIELDCONST',
self::getFieldConstantByteLimit());
}
final public static function getFieldConstantByteLimit() {
return 64;
}
final public static function getAllFields() {
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setUniqueMethod('getFieldConstant')
->execute();
}
final protected function hasAppliedTransactionOfType($type) {
$xactions = $this->getAdapter()->getAppliedTransactions();
if (!$xactions) {
return false;
}
foreach ($xactions as $xaction) {
if ($xaction->getTransactionType() === $type) {
return true;
}
}
return false;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Jan 19 2025, 23:08 (6 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1129717
Default Alt Text
(9 KB)

Event Timeline