@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Modularize more Herald fields

Summary: Ref T8726. Continue making Herald fields more modular than they currently are.

Test Plan:
- Created a rule using all the affected fields.
- Ran the rule.
- Saw reasonable object field values.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: eadler, joshuaspence, epriestley

Maniphest Tasks: T8726

Differential Revision: https://secure.phabricator.com/D13495

+287 -93
+1 -1
resources/sql/autopatches/20140210.herald.rule-condition-mig.php
··· 6 6 echo pht( 7 7 "Migrating Herald conditions of type Herald rule from IDs to PHIDs...\n"); 8 8 foreach (new LiskMigrationIterator($table) as $condition) { 9 - if ($condition->getFieldName() != HeraldAdapter::FIELD_RULE) { 9 + if ($condition->getFieldName() != HeraldAnotherRuleField::FIELDCONST) { 10 10 continue; 11 11 } 12 12
+12
src/__phutil_library_map__.php
··· 930 930 'HarbormasterWorker' => 'applications/harbormaster/worker/HarbormasterWorker.php', 931 931 'HeraldAction' => 'applications/herald/storage/HeraldAction.php', 932 932 'HeraldAdapter' => 'applications/herald/adapter/HeraldAdapter.php', 933 + 'HeraldAlwaysField' => 'applications/herald/field/HeraldAlwaysField.php', 934 + 'HeraldAnotherRuleField' => 'applications/herald/field/HeraldAnotherRuleField.php', 933 935 'HeraldApplyTranscript' => 'applications/herald/storage/transcript/HeraldApplyTranscript.php', 934 936 'HeraldCommitAdapter' => 'applications/herald/adapter/HeraldCommitAdapter.php', 935 937 'HeraldCondition' => 'applications/herald/storage/HeraldCondition.php', ··· 950 952 'HeraldManageGlobalRulesCapability' => 'applications/herald/capability/HeraldManageGlobalRulesCapability.php', 951 953 'HeraldManiphestTaskAdapter' => 'applications/herald/adapter/HeraldManiphestTaskAdapter.php', 952 954 'HeraldNewController' => 'applications/herald/controller/HeraldNewController.php', 955 + 'HeraldNewObjectField' => 'applications/herald/field/HeraldNewObjectField.php', 953 956 'HeraldObjectTranscript' => 'applications/herald/storage/transcript/HeraldObjectTranscript.php', 954 957 'HeraldPholioMockAdapter' => 'applications/herald/adapter/HeraldPholioMockAdapter.php', 955 958 'HeraldPreCommitAdapter' => 'applications/diffusion/herald/HeraldPreCommitAdapter.php', 956 959 'HeraldPreCommitContentAdapter' => 'applications/diffusion/herald/HeraldPreCommitContentAdapter.php', 957 960 'HeraldPreCommitRefAdapter' => 'applications/diffusion/herald/HeraldPreCommitRefAdapter.php', 961 + 'HeraldProjectsField' => 'applications/project/herald/HeraldProjectsField.php', 958 962 'HeraldRecursiveConditionsException' => 'applications/herald/engine/exception/HeraldRecursiveConditionsException.php', 959 963 'HeraldRemarkupRule' => 'applications/herald/remarkup/HeraldRemarkupRule.php', 960 964 'HeraldRepetitionPolicyConfig' => 'applications/herald/config/HeraldRepetitionPolicyConfig.php', ··· 972 976 'HeraldRuleTypeConfig' => 'applications/herald/config/HeraldRuleTypeConfig.php', 973 977 'HeraldRuleViewController' => 'applications/herald/controller/HeraldRuleViewController.php', 974 978 'HeraldSchemaSpec' => 'applications/herald/storage/HeraldSchemaSpec.php', 979 + 'HeraldSpaceField' => 'applications/spaces/herald/HeraldSpaceField.php', 980 + 'HeraldSubscribersField' => 'applications/subscriptions/herald/HeraldSubscribersField.php', 975 981 'HeraldTestConsoleController' => 'applications/herald/controller/HeraldTestConsoleController.php', 976 982 'HeraldTransactionQuery' => 'applications/herald/query/HeraldTransactionQuery.php', 977 983 'HeraldTranscript' => 'applications/herald/storage/transcript/HeraldTranscript.php', ··· 4427 4433 'HarbormasterWorker' => 'PhabricatorWorker', 4428 4434 'HeraldAction' => 'HeraldDAO', 4429 4435 'HeraldAdapter' => 'Phobject', 4436 + 'HeraldAlwaysField' => 'HeraldField', 4437 + 'HeraldAnotherRuleField' => 'HeraldField', 4430 4438 'HeraldApplyTranscript' => 'Phobject', 4431 4439 'HeraldCommitAdapter' => 'HeraldAdapter', 4432 4440 'HeraldCondition' => 'HeraldDAO', ··· 4447 4455 'HeraldManageGlobalRulesCapability' => 'PhabricatorPolicyCapability', 4448 4456 'HeraldManiphestTaskAdapter' => 'HeraldAdapter', 4449 4457 'HeraldNewController' => 'HeraldController', 4458 + 'HeraldNewObjectField' => 'HeraldField', 4450 4459 'HeraldObjectTranscript' => 'Phobject', 4451 4460 'HeraldPholioMockAdapter' => 'HeraldAdapter', 4452 4461 'HeraldPreCommitAdapter' => 'HeraldAdapter', 4453 4462 'HeraldPreCommitContentAdapter' => 'HeraldPreCommitAdapter', 4454 4463 'HeraldPreCommitRefAdapter' => 'HeraldPreCommitAdapter', 4464 + 'HeraldProjectsField' => 'HeraldField', 4455 4465 'HeraldRecursiveConditionsException' => 'Exception', 4456 4466 'HeraldRemarkupRule' => 'PhabricatorObjectRemarkupRule', 4457 4467 'HeraldRepetitionPolicyConfig' => 'Phobject', ··· 4475 4485 'HeraldRuleTypeConfig' => 'Phobject', 4476 4486 'HeraldRuleViewController' => 'HeraldController', 4477 4487 'HeraldSchemaSpec' => 'PhabricatorConfigSchemaSpec', 4488 + 'HeraldSpaceField' => 'HeraldField', 4489 + 'HeraldSubscribersField' => 'HeraldField', 4478 4490 'HeraldTestConsoleController' => 'HeraldController', 4479 4491 'HeraldTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 4480 4492 'HeraldTranscript' => array(
+8
src/applications/diffusion/herald/HeraldPreCommitAdapter.php
··· 23 23 return 'PhabricatorDiffusionApplication'; 24 24 } 25 25 26 + protected function initializeNewAdapter() { 27 + $this->log = new PhabricatorRepositoryPushLog(); 28 + } 29 + 30 + public function isSingleEventAdapter() { 31 + return true; 32 + } 33 + 26 34 public function getObject() { 27 35 return $this->log; 28 36 }
+18 -69
src/applications/herald/adapter/HeraldAdapter.php
··· 12 12 const FIELD_REVIEWER = 'reviewer'; 13 13 const FIELD_REVIEWERS = 'reviewers'; 14 14 const FIELD_COMMITTER = 'committer'; 15 - const FIELD_CC = 'cc'; 16 15 const FIELD_TAGS = 'tags'; 17 16 const FIELD_DIFF_FILE = 'diff-file'; 18 17 const FIELD_DIFF_CONTENT = 'diff-content'; ··· 21 20 const FIELD_DIFF_ENORMOUS = 'diff-enormous'; 22 21 const FIELD_REPOSITORY = 'repository'; 23 22 const FIELD_REPOSITORY_PROJECTS = 'repository-projects'; 24 - const FIELD_RULE = 'rule'; 25 23 const FIELD_AFFECTED_PACKAGE = 'affected-package'; 26 24 const FIELD_AFFECTED_PACKAGE_OWNER = 'affected-package-owner'; 27 - const FIELD_ALWAYS = 'always'; 28 25 const FIELD_AUTHOR_PROJECTS = 'authorprojects'; 29 - const FIELD_PROJECTS = 'projects'; 30 26 const FIELD_PUSHER = 'pusher'; 31 27 const FIELD_PUSHER_PROJECTS = 'pusher-projects'; 32 28 const FIELD_DIFFERENTIAL_REVISION = 'differential-revision'; ··· 37 33 const FIELD_BRANCHES = 'branches'; 38 34 const FIELD_AUTHOR_RAW = 'author-raw'; 39 35 const FIELD_COMMITTER_RAW = 'committer-raw'; 40 - const FIELD_IS_NEW_OBJECT = 'new-object'; 41 36 const FIELD_APPLICATION_EMAIL = 'applicaton-email'; 42 37 const FIELD_TASK_PRIORITY = 'taskpriority'; 43 38 const FIELD_TASK_STATUS = 'taskstatus'; 44 39 const FIELD_PUSHER_IS_COMMITTER = 'pusher-is-committer'; 45 40 const FIELD_PATH = 'path'; 46 - const FIELD_SPACE = 'space'; 47 41 48 42 const CONDITION_CONTAINS = 'contains'; 49 43 const CONDITION_NOT_CONTAINS = '!contains'; ··· 196 190 } 197 191 198 192 switch ($field_name) { 199 - case self::FIELD_RULE: 200 - return null; 201 - case self::FIELD_ALWAYS: 202 - return true; 203 - case self::FIELD_IS_NEW_OBJECT: 204 - return $this->getIsNewObject(); 205 - case self::FIELD_CC: 206 - $object = $this->getObject(); 207 - 208 - if (!($object instanceof PhabricatorSubscribableInterface)) { 209 - throw new Exception( 210 - pht( 211 - 'Adapter object (of class "%s") does not implement interface '. 212 - '"%s", so the subscribers field value can not be determined.', 213 - get_class($object), 214 - 'PhabricatorSubscribableInterface')); 215 - } 216 - 217 - $phid = $object->getPHID(); 218 - return PhabricatorSubscribersQuery::loadSubscribersForPHID($phid); 219 193 case self::FIELD_APPLICATION_EMAIL: 220 194 $value = array(); 221 195 // while there is only one match by implementation, we do set ··· 224 198 $value[] = $this->getApplicationEmail()->getPHID(); 225 199 } 226 200 return $value; 227 - case self::FIELD_SPACE: 228 - $object = $this->getObject(); 229 - 230 - if (!($object instanceof PhabricatorSpacesInterface)) { 231 - throw new Exception( 232 - pht( 233 - 'Adapter object (of class "%s") does not implement interface '. 234 - '"%s", so the Space field value can not be determined.', 235 - get_class($object), 236 - 'PhabricatorSpacesInterface')); 237 - } 238 - 239 - return PhabricatorSpacesNamespaceQuery::getObjectSpacePHID($object); 240 201 default: 241 202 if ($this->isHeraldCustomKey($field_name)) { 242 203 return $this->getCustomFieldValue($field_name); ··· 367 328 $map = array(); 368 329 $all = HeraldField::getAllFields(); 369 330 foreach ($all as $key => $field) { 331 + $field = id(clone $field)->setAdapter($this); 332 + 370 333 if (!$field->supportsObject($object)) { 371 334 continue; 372 335 } ··· 403 366 404 367 public function getFields() { 405 368 $fields = array_keys($this->getFieldImplementationMap()); 406 - 407 - $fields[] = self::FIELD_ALWAYS; 408 - $fields[] = self::FIELD_RULE; 409 369 410 370 $custom_fields = $this->getCustomFields(); 411 371 if ($custom_fields) { ··· 429 389 self::FIELD_COMMITTER => pht('Committer'), 430 390 self::FIELD_REVIEWER => pht('Reviewer'), 431 391 self::FIELD_REVIEWERS => pht('Reviewers'), 432 - self::FIELD_CC => pht('CCs'), 433 392 self::FIELD_TAGS => pht('Tags'), 434 393 self::FIELD_DIFF_FILE => pht('Any changed filename'), 435 394 self::FIELD_DIFF_CONTENT => pht('Any changed file content'), ··· 438 397 self::FIELD_DIFF_ENORMOUS => pht('Change is enormous'), 439 398 self::FIELD_REPOSITORY => pht('Repository'), 440 399 self::FIELD_REPOSITORY_PROJECTS => pht('Repository\'s projects'), 441 - self::FIELD_RULE => pht('Another Herald rule'), 442 400 self::FIELD_AFFECTED_PACKAGE => pht('Any affected package'), 443 401 self::FIELD_AFFECTED_PACKAGE_OWNER => 444 402 pht("Any affected package's owner"), 445 - self::FIELD_ALWAYS => pht('Always'), 446 403 self::FIELD_AUTHOR_PROJECTS => pht("Author's projects"), 447 - self::FIELD_PROJECTS => pht('Projects'), 448 404 self::FIELD_PUSHER => pht('Pusher'), 449 405 self::FIELD_PUSHER_PROJECTS => pht("Pusher's projects"), 450 406 self::FIELD_DIFFERENTIAL_REVISION => pht('Differential revision'), ··· 456 412 self::FIELD_BRANCHES => pht('Commit\'s branches'), 457 413 self::FIELD_AUTHOR_RAW => pht('Raw author name'), 458 414 self::FIELD_COMMITTER_RAW => pht('Raw committer name'), 459 - self::FIELD_IS_NEW_OBJECT => pht('Is newly created?'), 460 415 self::FIELD_APPLICATION_EMAIL => pht('Receiving email address'), 461 416 self::FIELD_TASK_PRIORITY => pht('Task priority'), 462 417 self::FIELD_TASK_STATUS => pht('Task status'), 463 418 self::FIELD_PUSHER_IS_COMMITTER => pht('Pusher same as committer'), 464 419 self::FIELD_PATH => pht('Path'), 465 - self::FIELD_SPACE => pht('Space'), 466 420 ) + $this->getCustomFieldNameMap(); 467 421 } 468 422 ··· 521 475 case self::FIELD_PUSHER: 522 476 case self::FIELD_TASK_PRIORITY: 523 477 case self::FIELD_TASK_STATUS: 524 - case self::FIELD_SPACE: 525 478 return array( 526 479 self::CONDITION_IS_ANY, 527 480 self::CONDITION_IS_NOT_ANY, ··· 538 491 ); 539 492 case self::FIELD_TAGS: 540 493 case self::FIELD_REVIEWERS: 541 - case self::FIELD_CC: 542 494 case self::FIELD_AUTHOR_PROJECTS: 543 - case self::FIELD_PROJECTS: 544 495 case self::FIELD_AFFECTED_PACKAGE: 545 496 case self::FIELD_AFFECTED_PACKAGE_OWNER: 546 497 case self::FIELD_PUSHER_PROJECTS: ··· 573 524 self::CONDITION_REGEXP, 574 525 self::CONDITION_REGEXP_PAIR, 575 526 ); 576 - case self::FIELD_RULE: 577 - return array( 578 - self::CONDITION_RULE, 579 - self::CONDITION_NOT_RULE, 580 - ); 581 - case self::FIELD_ALWAYS: 582 - return array( 583 - self::CONDITION_UNCONDITIONALLY, 584 - ); 585 527 case self::FIELD_DIFFERENTIAL_REVIEWERS: 586 528 return array( 587 529 self::CONDITION_EXISTS, ··· 604 546 ); 605 547 case self::FIELD_IS_MERGE_COMMIT: 606 548 case self::FIELD_DIFF_ENORMOUS: 607 - case self::FIELD_IS_NEW_OBJECT: 608 549 case self::FIELD_PUSHER_IS_COMMITTER: 609 550 return array( 610 551 self::CONDITION_IS_TRUE, ··· 1019 960 return self::VALUE_TASK_PRIORITY; 1020 961 case self::FIELD_TASK_STATUS: 1021 962 return self::VALUE_TASK_STATUS; 1022 - case self::FIELD_SPACE: 1023 - return self::VALUE_SPACE; 1024 963 default: 1025 964 return self::VALUE_USER; 1026 965 } ··· 1031 970 switch ($field) { 1032 971 case self::FIELD_REPOSITORY: 1033 972 return self::VALUE_REPOSITORY; 1034 - case self::FIELD_CC: 1035 - return self::VALUE_EMAIL; 1036 973 case self::FIELD_TAGS: 1037 974 return self::VALUE_TAG; 1038 975 case self::FIELD_AFFECTED_PACKAGE: 1039 976 return self::VALUE_OWNERS_PACKAGE; 1040 977 case self::FIELD_AUTHOR_PROJECTS: 1041 978 case self::FIELD_PUSHER_PROJECTS: 1042 - case self::FIELD_PROJECTS: 1043 979 case self::FIELD_REPOSITORY_PROJECTS: 1044 980 return self::VALUE_PROJECT; 1045 981 case self::FIELD_REVIEWERS: ··· 1059 995 case self::CONDITION_IS_TRUE: 1060 996 case self::CONDITION_IS_FALSE: 1061 997 return self::VALUE_NONE; 1062 - case self::CONDITION_RULE: 1063 - case self::CONDITION_NOT_RULE: 1064 - return self::VALUE_RULE; 1065 998 default: 1066 999 throw new Exception(pht("Unknown condition '%s'.", $condition)); 1067 1000 } ··· 1133 1066 ); 1134 1067 } 1135 1068 1069 + abstract protected function initializeNewAdapter(); 1070 + 1071 + /** 1072 + * Does this adapter's event fire only once? 1073 + * 1074 + * Single use adapters (like pre-commit and diff adapters) only fire once, 1075 + * so fields like "Is new object" don't make sense to apply to their content. 1076 + * 1077 + * @return bool 1078 + */ 1079 + public function isSingleEventAdapter() { 1080 + return false; 1081 + } 1082 + 1136 1083 public static function getAllAdapters() { 1137 1084 static $adapters; 1138 1085 if (!$adapters) { ··· 1149 1096 1150 1097 foreach ($adapters as $adapter) { 1151 1098 if ($adapter->getAdapterContentType() == $content_type) { 1099 + $adapter = id(clone $adapter); 1100 + $adapter->initializeNewAdapter(); 1152 1101 return $adapter; 1153 1102 } 1154 1103 }
+4
src/applications/herald/adapter/HeraldCommitAdapter.php
··· 29 29 return new PhabricatorRepositoryCommit(); 30 30 } 31 31 32 + protected function initializeNewAdapter() { 33 + $this->commit = $this->newObject(); 34 + } 35 + 32 36 public function getObject() { 33 37 return $this->commit; 34 38 }
+8
src/applications/herald/adapter/HeraldDifferentialDiffAdapter.php
··· 6 6 return 'PhabricatorDifferentialApplication'; 7 7 } 8 8 9 + protected function initializeNewAdapter() { 10 + $this->setDiff(new DifferentialDiff()); 11 + } 12 + 13 + public function isSingleEventAdapter() { 14 + return true; 15 + } 16 + 9 17 protected function loadChangesets() { 10 18 return $this->loadChangesetsWithHunks(); 11 19 }
+4 -2
src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php
··· 24 24 return new DifferentialRevision(); 25 25 } 26 26 27 + protected function initializeNewAdapter() { 28 + $this->revision = $this->newObject(); 29 + } 30 + 27 31 public function getObject() { 28 32 return $this->revision; 29 33 } ··· 66 70 self::FIELD_AUTHOR, 67 71 self::FIELD_AUTHOR_PROJECTS, 68 72 self::FIELD_REVIEWERS, 69 - self::FIELD_CC, 70 73 self::FIELD_REPOSITORY, 71 74 self::FIELD_REPOSITORY_PROJECTS, 72 75 self::FIELD_DIFF_FILE, ··· 75 78 self::FIELD_DIFF_REMOVED_CONTENT, 76 79 self::FIELD_AFFECTED_PACKAGE, 77 80 self::FIELD_AFFECTED_PACKAGE_OWNER, 78 - self::FIELD_IS_NEW_OBJECT, 79 81 ), 80 82 parent::getFields()); 81 83 }
+4 -8
src/applications/herald/adapter/HeraldManiphestTaskAdapter.php
··· 17 17 return pht('React to tasks being created or updated.'); 18 18 } 19 19 20 + protected function initializeNewAdapter() { 21 + $this->task = $this->newObject(); 22 + } 23 + 20 24 public function getRepetitionOptions() { 21 25 return array( 22 26 HeraldRepetitionPolicyConfig::EVERY, ··· 66 70 self::FIELD_BODY, 67 71 self::FIELD_AUTHOR, 68 72 self::FIELD_ASSIGNEE, 69 - self::FIELD_CC, 70 - self::FIELD_PROJECTS, 71 73 self::FIELD_TASK_PRIORITY, 72 74 self::FIELD_TASK_STATUS, 73 - self::FIELD_IS_NEW_OBJECT, 74 75 self::FIELD_APPLICATION_EMAIL, 75 - self::FIELD_SPACE, 76 76 ), 77 77 parent::getFields()); 78 78 } ··· 121 121 return $this->getTask()->getAuthorPHID(); 122 122 case self::FIELD_ASSIGNEE: 123 123 return $this->getTask()->getOwnerPHID(); 124 - case self::FIELD_PROJECTS: 125 - return PhabricatorEdgeQuery::loadDestinationPHIDs( 126 - $this->getTask()->getPHID(), 127 - PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); 128 124 case self::FIELD_TASK_PRIORITY: 129 125 return $this->getTask()->getPriority(); 130 126 case self::FIELD_TASK_STATUS:
+4 -8
src/applications/herald/adapter/HeraldPholioMockAdapter.php
··· 12 12 return pht('React to mocks being created or updated.'); 13 13 } 14 14 15 + protected function initializeNewAdapter() { 16 + $this->mock = $this->newObject(); 17 + } 18 + 15 19 protected function newObject() { 16 20 return new PholioMock(); 17 21 } ··· 49 53 self::FIELD_TITLE, 50 54 self::FIELD_BODY, 51 55 self::FIELD_AUTHOR, 52 - self::FIELD_CC, 53 - self::FIELD_PROJECTS, 54 - self::FIELD_IS_NEW_OBJECT, 55 - self::FIELD_SPACE, 56 56 ), 57 57 parent::getFields()); 58 58 } ··· 95 95 return $this->getMock()->getDescription(); 96 96 case self::FIELD_AUTHOR: 97 97 return $this->getMock()->getAuthorPHID(); 98 - case self::FIELD_PROJECTS: 99 - return PhabricatorEdgeQuery::loadDestinationPHIDs( 100 - $this->getMock()->getPHID(), 101 - PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); 102 98 } 103 99 104 100 return parent::getHeraldField($field);
+2 -2
src/applications/herald/controller/HeraldTranscriptController.php
··· 117 117 118 118 protected function renderConditionTestValue($condition, $handles) { 119 119 switch ($condition->getFieldName()) { 120 - case HeraldAdapter::FIELD_RULE: 120 + case HeraldAnotherRuleField::FIELDCONST: 121 121 $value = array($condition->getTestValue()); 122 122 break; 123 123 default: ··· 204 204 } 205 205 foreach ($condition_xscripts as $condition_xscript) { 206 206 switch ($condition_xscript->getFieldName()) { 207 - case HeraldAdapter::FIELD_RULE: 207 + case HeraldAnotherRuleField::FIELDCONST: 208 208 $phids[] = $condition_xscript->getTestValue(); 209 209 break; 210 210 default:
+29
src/applications/herald/field/HeraldAlwaysField.php
··· 1 + <?php 2 + 3 + final class HeraldAlwaysField extends HeraldField { 4 + 5 + const FIELDCONST = 'always'; 6 + 7 + public function getHeraldFieldName() { 8 + return pht('Always'); 9 + } 10 + 11 + public function getHeraldFieldValue($object) { 12 + return true; 13 + } 14 + 15 + public function getHeraldFieldConditions() { 16 + return array( 17 + HeraldAdapter::CONDITION_UNCONDITIONALLY, 18 + ); 19 + } 20 + 21 + public function getHeraldFieldValueType($condition) { 22 + return HeraldAdapter::VALUE_NONE; 23 + } 24 + 25 + public function supportsObject($object) { 26 + return true; 27 + } 28 + 29 + }
+31
src/applications/herald/field/HeraldAnotherRuleField.php
··· 1 + <?php 2 + 3 + final class HeraldAnotherRuleField extends HeraldField { 4 + 5 + const FIELDCONST = 'rule'; 6 + 7 + public function getHeraldFieldName() { 8 + return pht('Another Herald rule'); 9 + } 10 + 11 + public function supportsObject($object) { 12 + return true; 13 + } 14 + 15 + public function getHeraldFieldValue($object) { 16 + return null; 17 + } 18 + 19 + public function getHeraldFieldConditions() { 20 + return array( 21 + HeraldAdapter::CONDITION_RULE, 22 + HeraldAdapter::CONDITION_NOT_RULE, 23 + ); 24 + } 25 + 26 + public function getHeraldFieldValueType($condition) { 27 + return HeraldAdapter::VALUE_RULE; 28 + } 29 + 30 + 31 + }
+35 -1
src/applications/herald/field/HeraldField.php
··· 4 4 5 5 private $adapter; 6 6 7 + const STANDARD_LIST = 'standard.list'; 8 + const STANDARD_BOOL = 'standard.bool'; 9 + const STANDARD_PHID = 'standard.phid'; 10 + 7 11 abstract public function getHeraldFieldName(); 8 12 abstract public function getHeraldFieldValue($object); 9 - abstract public function getHeraldFieldConditions(); 13 + 14 + public function getHeraldFieldConditions() { 15 + switch ($this->getHeraldFieldStandardConditions()) { 16 + case self::STANDARD_LIST: 17 + return array( 18 + HeraldAdapter::CONDITION_INCLUDE_ALL, 19 + HeraldAdapter::CONDITION_INCLUDE_ANY, 20 + HeraldAdapter::CONDITION_INCLUDE_NONE, 21 + HeraldAdapter::CONDITION_EXISTS, 22 + HeraldAdapter::CONDITION_NOT_EXISTS, 23 + ); 24 + case self::STANDARD_BOOL: 25 + return array( 26 + HeraldAdapter::CONDITION_IS_TRUE, 27 + HeraldAdapter::CONDITION_IS_FALSE, 28 + ); 29 + case self::STANDARD_PHID: 30 + return array( 31 + HeraldAdapter::CONDITION_IS_ANY, 32 + HeraldAdapter::CONDITION_IS_NOT_ANY, 33 + ); 34 + 35 + } 36 + 37 + throw new Exception(pht('Unknown standard condition set.')); 38 + } 39 + 40 + protected function getHeraldFieldStandardConditions() { 41 + throw new PhutilMethodNotImplementedException(); 42 + } 43 + 10 44 abstract public function getHeraldFieldValueType($condition); 11 45 12 46 abstract public function supportsObject($object);
+27
src/applications/herald/field/HeraldNewObjectField.php
··· 1 + <?php 2 + 3 + final class HeraldNewObjectField extends HeraldField { 4 + 5 + const FIELDCONST = 'new-object'; 6 + 7 + public function getHeraldFieldName() { 8 + return pht('Is newly created'); 9 + } 10 + 11 + public function supportsObject($object) { 12 + return !$this->getAdapter()->isSingleEventAdapter(); 13 + } 14 + 15 + public function getHeraldFieldValue($object) { 16 + return $this->getAdapter()->getIsNewObject(); 17 + } 18 + 19 + protected function getHeraldFieldStandardConditions() { 20 + return self::STANDARD_BOOL; 21 + } 22 + 23 + public function getHeraldFieldValueType($condition) { 24 + return HeraldAdapter::VALUE_NONE; 25 + } 26 + 27 + }
+4 -2
src/applications/phriction/herald/PhrictionDocumentHeraldAdapter.php
··· 12 12 return pht('React to wiki documents being created or updated.'); 13 13 } 14 14 15 + protected function initializeNewAdapter() { 16 + $this->document = $this->newObject(); 17 + } 18 + 15 19 protected function newObject() { 16 20 return new PhrictionDocument(); 17 21 } ··· 50 54 self::FIELD_TITLE, 51 55 self::FIELD_BODY, 52 56 self::FIELD_AUTHOR, 53 - self::FIELD_IS_NEW_OBJECT, 54 - self::FIELD_CC, 55 57 self::FIELD_PATH, 56 58 ), 57 59 parent::getFields());
+35
src/applications/project/herald/HeraldProjectsField.php
··· 1 + <?php 2 + 3 + final class HeraldProjectsField extends HeraldField { 4 + 5 + const FIELDCONST = 'projects'; 6 + 7 + public function getHeraldFieldName() { 8 + return pht('Projects'); 9 + } 10 + 11 + public function supportsObject($object) { 12 + return ($object instanceof PhabricatorProjectInterface); 13 + } 14 + 15 + public function getHeraldFieldValue($object) { 16 + return PhabricatorEdgeQuery::loadDestinationPHIDs( 17 + $object->getPHID(), 18 + PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); 19 + } 20 + 21 + protected function getHeraldFieldStandardConditions() { 22 + return self::STANDARD_LIST; 23 + } 24 + 25 + public function getHeraldFieldValueType($condition) { 26 + switch ($condition) { 27 + case HeraldAdapter::CONDITION_EXISTS: 28 + case HeraldAdapter::CONDITION_NOT_EXISTS: 29 + return HeraldAdapter::VALUE_NONE; 30 + default: 31 + return HeraldAdapter::VALUE_PROJECT; 32 + } 33 + } 34 + 35 + }
+27
src/applications/spaces/herald/HeraldSpaceField.php
··· 1 + <?php 2 + 3 + final class HeraldSpaceField extends HeraldField { 4 + 5 + const FIELDCONST = 'space'; 6 + 7 + public function getHeraldFieldName() { 8 + return pht('Space'); 9 + } 10 + 11 + public function supportsObject($object) { 12 + return ($object instanceof PhabricatorSpacesInterface); 13 + } 14 + 15 + public function getHeraldFieldValue($object) { 16 + return PhabricatorSpacesNamespaceQuery::getObjectSpacePHID($object); 17 + } 18 + 19 + protected function getHeraldFieldStandardConditions() { 20 + return self::STANDARD_PHID; 21 + } 22 + 23 + public function getHeraldFieldValueType($condition) { 24 + return HeraldAdapter::VALUE_SPACE; 25 + } 26 + 27 + }
+34
src/applications/subscriptions/herald/HeraldSubscribersField.php
··· 1 + <?php 2 + 3 + final class HeraldSubscribersField extends HeraldField { 4 + 5 + const FIELDCONST = 'cc'; 6 + 7 + public function getHeraldFieldName() { 8 + return pht('Subscribers'); 9 + } 10 + 11 + public function supportsObject($object) { 12 + return ($object instanceof PhabricatorSubscribableInterface); 13 + } 14 + 15 + public function getHeraldFieldValue($object) { 16 + $phid = $object->getPHID(); 17 + return PhabricatorSubscribersQuery::loadSubscribersForPHID($phid); 18 + } 19 + 20 + protected function getHeraldFieldStandardConditions() { 21 + return self::STANDARD_LIST; 22 + } 23 + 24 + public function getHeraldFieldValueType($condition) { 25 + switch ($condition) { 26 + case HeraldAdapter::CONDITION_EXISTS: 27 + case HeraldAdapter::CONDITION_NOT_EXISTS: 28 + return HeraldAdapter::VALUE_NONE; 29 + default: 30 + return HeraldAdapter::VALUE_PROJECT; 31 + } 32 + } 33 + 34 + }