Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15422873
D12140.id29182.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D12140.id29182.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -889,6 +889,7 @@
'HeraldCommitAdapter' => 'applications/herald/adapter/HeraldCommitAdapter.php',
'HeraldCondition' => 'applications/herald/storage/HeraldCondition.php',
'HeraldConditionTranscript' => 'applications/herald/storage/transcript/HeraldConditionTranscript.php',
+ 'HeraldConduitAPIMethod' => 'applications/herald/conduit/HeraldConduitAPIMethod.php',
'HeraldController' => 'applications/herald/controller/HeraldController.php',
'HeraldCustomAction' => 'applications/herald/extension/HeraldCustomAction.php',
'HeraldDAO' => 'applications/herald/storage/HeraldDAO.php',
@@ -909,6 +910,7 @@
'HeraldPreCommitAdapter' => 'applications/diffusion/herald/HeraldPreCommitAdapter.php',
'HeraldPreCommitContentAdapter' => 'applications/diffusion/herald/HeraldPreCommitContentAdapter.php',
'HeraldPreCommitRefAdapter' => 'applications/diffusion/herald/HeraldPreCommitRefAdapter.php',
+ 'HeraldQueryRulesConduitAPIMethod' => 'applications/herald/conduit/HeraldQueryRulesConduitAPIMethod.php',
'HeraldRecursiveConditionsException' => 'applications/herald/engine/exception/HeraldRecursiveConditionsException.php',
'HeraldRemarkupRule' => 'applications/herald/remarkup/HeraldRemarkupRule.php',
'HeraldRepetitionPolicyConfig' => 'applications/herald/config/HeraldRepetitionPolicyConfig.php',
@@ -4104,6 +4106,7 @@
'HeraldApplyTranscript' => 'Phobject',
'HeraldCommitAdapter' => 'HeraldAdapter',
'HeraldCondition' => 'HeraldDAO',
+ 'HeraldConduitAPIMethod' => 'ConduitAPIMethod',
'HeraldController' => 'PhabricatorController',
'HeraldDAO' => 'PhabricatorLiskDAO',
'HeraldDifferentialAdapter' => 'HeraldAdapter',
@@ -4120,6 +4123,7 @@
'HeraldPreCommitAdapter' => 'HeraldAdapter',
'HeraldPreCommitContentAdapter' => 'HeraldPreCommitAdapter',
'HeraldPreCommitRefAdapter' => 'HeraldPreCommitAdapter',
+ 'HeraldQueryRulesConduitAPIMethod' => 'HeraldConduitAPIMethod',
'HeraldRecursiveConditionsException' => 'Exception',
'HeraldRemarkupRule' => 'PhabricatorObjectRemarkupRule',
'HeraldRule' => array(
diff --git a/src/applications/herald/conduit/HeraldConduitAPIMethod.php b/src/applications/herald/conduit/HeraldConduitAPIMethod.php
new file mode 100644
--- /dev/null
+++ b/src/applications/herald/conduit/HeraldConduitAPIMethod.php
@@ -0,0 +1,89 @@
+<?php
+
+abstract class HeraldConduitAPIMethod extends ConduitAPIMethod {
+
+ final public function getApplication() {
+ return PhabricatorApplication::getByClass(
+ 'PhabricatorHeraldApplication');
+ }
+
+ public function getMethodStatus() {
+ return self::METHOD_STATUS_UNSTABLE;
+ }
+
+ public function getMethodStatusDescription() {
+ return pht('All Herald APIs are new and subject to change.');
+ }
+
+ protected function buildRuleInfoDictionaries(
+ array $plans, $need_conditions_and_actions = false) {
+ assert_instances_of($plans, 'HeraldRule');
+
+ $result = array();
+
+ foreach ($plans as $plan) {
+ $item = array(
+ 'id' => $plan->getID(),
+ 'phid' => $plan->getPHID(),
+ 'name' => $plan->getName(),
+ 'contentType' => $plan->getContentType(),
+ 'mustMatchAll' => $plan->getMustMatchAll(),
+ 'ruleType' => $plan->getRuleType(),
+ 'dateCreated' => $plan->getDateCreated(),
+ 'dateModified' => $plan->getDateModified(),
+ );
+
+ if ($need_conditions_and_actions) {
+ $conditions = is_array($plan->getConditions())
+ ? $plan->getConditions() : array();
+ $actions = is_array($plan->getActions())
+ ? $plan->getActions() : array();
+ $item['conditions'] =
+ $this->buildConditionsInfoDictionaries($conditions);
+ $item['actions'] =
+ $this->buildActionsInfoDictionaries($actions);
+ }
+
+ $result[$plan->getPHID()] = $item;
+ }
+
+ return $result;
+ }
+
+ protected function buildConditionsInfoDictionaries(array $conditions) {
+ assert_instances_of($conditions, 'HeraldCondition');
+
+ $result = array();
+
+ if (!empty($conditions)) {
+ foreach ($conditions as $cond) {
+ $result[$cond->getID()] = array(
+ 'id' => $cond->getID(),
+ 'fieldName' => $cond->getFieldName(),
+ 'fieldCondition' => $cond->getFieldCondition(),
+ 'value' => $cond->getValue(),
+ );
+ }
+ }
+
+ return $result;
+ }
+
+ protected function buildActionsInfoDictionaries(array $actions) {
+ assert_instances_of($actions, 'HeraldAction');
+
+ $result = array();
+
+ if (!empty($actions)) {
+ foreach ($actions as $action) {
+ $result[$action->getID()] = array(
+ 'id' => $action->getID(),
+ 'action' => $action->getAction(),
+ 'target' => $action->getTarget(),
+ );
+ }
+ }
+
+ return $result;
+ }
+}
diff --git a/src/applications/herald/conduit/HeraldQueryRulesConduitAPIMethod.php b/src/applications/herald/conduit/HeraldQueryRulesConduitAPIMethod.php
new file mode 100644
--- /dev/null
+++ b/src/applications/herald/conduit/HeraldQueryRulesConduitAPIMethod.php
@@ -0,0 +1,96 @@
+<?php
+
+final class HeraldQueryRulesConduitAPIMethod
+ extends HeraldConduitAPIMethod {
+
+ public function getAPIMethodName() {
+ return 'herald.queryrules';
+ }
+
+ public function getMethodDescription() {
+ return pht('Execute searches for Herald rules.');
+ }
+
+ private function getRuleTypes() {
+ return array(
+ HeraldRuleTypeConfig::RULE_TYPE_PERSONAL,
+ HeraldRuleTypeConfig::RULE_TYPE_GLOBAL,
+ HeraldRuleTypeConfig::RULE_TYPE_OBJECT,
+ );
+ }
+
+ public function defineParamTypes() {
+ return array(
+ 'ids' => 'optional list<id>',
+ 'phids' => 'optional list<phid>',
+ 'authorPHIDs' => 'optional list<phid>',
+ 'contentTypes' => 'optional list<string>',
+ 'ruleTypes' => 'optional list<string> ('
+ .implode(', ', $this->getRuleTypes()).')',
+ 'needConditionsAndActions' => 'optional int<0|1> (default = 0)',
+
+ ) + self::getPagerParamTypes();
+ }
+
+ public function defineReturnType() {
+ return 'list<wild>';
+ }
+
+ public function defineErrorTypes() {
+ return array();
+ }
+
+ protected function execute(ConduitAPIRequest $request) {
+ $viewer = $request->getUser();
+
+ $this->requireApplicationCapability(
+ HeraldManageGlobalRulesCapability::CAPABILITY, $viewer);
+
+ $query = id(new HeraldRuleQuery())
+ ->setViewer($viewer);
+
+ $ids = $request->getValue('ids');
+ if ($ids !== null) {
+ $query->withIDs($ids);
+ }
+
+ $phids = $request->getValue('phids');
+ if ($phids !== null) {
+ $query->withPHIDs($phids);
+ }
+
+ $author_phids = $request->getValue('authorPHIDs');
+ if ($author_phids !== null) {
+ $query->withAuthorPHIDs($author_phids);
+ }
+
+ $content_types = $request->getValue('contentTypes');
+ if ($content_types !== null) {
+ $query->withContentTypes($content_types);
+ }
+
+ $rule_types = $request->getValue('ruleTypes');
+ if ($rule_types !== null) {
+ $query->withRuleTypes($rule_types);
+ }
+
+ $need_conditions_and_actions =
+ (bool) $request->getValue('needConditionsAndActions', false);
+ if (true === $need_conditions_and_actions) {
+ $query->needConditionsAndActions(true);
+ }
+
+ $pager = $this->newPager($request);
+
+ $results = $query->executeWithCursorPager($pager);
+
+ $rules = $this->buildRuleInfoDictionaries(
+ $results, $need_conditions_and_actions);
+
+ $result = array(
+ 'data' => $rules,
+ );
+
+ return $this->addPagerResults($result, $pager);
+ }
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mar 23 2025, 11:06 AM (6 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7718380
Default Alt Text
D12140.id29182.diff (7 KB)
Attached To
Mode
D12140: T7651: Created herald.queryrules Conduit API method.
Attached
Detach File
Event Timeline
Log In to Comment