Changeset View
Changeset View
Standalone View
Standalone View
src/applications/herald/adapter/HeraldAdapter.php
Show All 18 Lines | abstract class HeraldAdapter extends Phobject { | ||||
const FIELD_DIFF_ADDED_CONTENT = 'diff-added-content'; | const FIELD_DIFF_ADDED_CONTENT = 'diff-added-content'; | ||||
const FIELD_DIFF_REMOVED_CONTENT = 'diff-removed-content'; | const FIELD_DIFF_REMOVED_CONTENT = 'diff-removed-content'; | ||||
const FIELD_DIFF_ENORMOUS = 'diff-enormous'; | const FIELD_DIFF_ENORMOUS = 'diff-enormous'; | ||||
const FIELD_REPOSITORY = 'repository'; | const FIELD_REPOSITORY = 'repository'; | ||||
const FIELD_REPOSITORY_PROJECTS = 'repository-projects'; | const FIELD_REPOSITORY_PROJECTS = 'repository-projects'; | ||||
const FIELD_RULE = 'rule'; | const FIELD_RULE = 'rule'; | ||||
const FIELD_AFFECTED_PACKAGE = 'affected-package'; | const FIELD_AFFECTED_PACKAGE = 'affected-package'; | ||||
const FIELD_AFFECTED_PACKAGE_OWNER = 'affected-package-owner'; | const FIELD_AFFECTED_PACKAGE_OWNER = 'affected-package-owner'; | ||||
const FIELD_CONTENT_SOURCE = 'contentsource'; | |||||
const FIELD_ALWAYS = 'always'; | const FIELD_ALWAYS = 'always'; | ||||
const FIELD_AUTHOR_PROJECTS = 'authorprojects'; | const FIELD_AUTHOR_PROJECTS = 'authorprojects'; | ||||
const FIELD_PROJECTS = 'projects'; | const FIELD_PROJECTS = 'projects'; | ||||
const FIELD_PUSHER = 'pusher'; | const FIELD_PUSHER = 'pusher'; | ||||
const FIELD_PUSHER_PROJECTS = 'pusher-projects'; | const FIELD_PUSHER_PROJECTS = 'pusher-projects'; | ||||
const FIELD_DIFFERENTIAL_REVISION = 'differential-revision'; | const FIELD_DIFFERENTIAL_REVISION = 'differential-revision'; | ||||
const FIELD_DIFFERENTIAL_REVIEWERS = 'differential-reviewers'; | const FIELD_DIFFERENTIAL_REVIEWERS = 'differential-reviewers'; | ||||
const FIELD_DIFFERENTIAL_CCS = 'differential-ccs'; | const FIELD_DIFFERENTIAL_CCS = 'differential-ccs'; | ||||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | abstract class HeraldAdapter extends Phobject { | ||||
private $isNewObject; | private $isNewObject; | ||||
private $applicationEmail; | private $applicationEmail; | ||||
private $customFields = false; | private $customFields = false; | ||||
private $customActions = null; | private $customActions = null; | ||||
private $queuedTransactions = array(); | private $queuedTransactions = array(); | ||||
private $emailPHIDs = array(); | private $emailPHIDs = array(); | ||||
private $forcedEmailPHIDs = array(); | private $forcedEmailPHIDs = array(); | ||||
private $unsubscribedPHIDs; | private $unsubscribedPHIDs; | ||||
private $fieldMap; | |||||
public function getEmailPHIDs() { | public function getEmailPHIDs() { | ||||
return array_values($this->emailPHIDs); | return array_values($this->emailPHIDs); | ||||
} | } | ||||
public function getForcedEmailPHIDs() { | public function getForcedEmailPHIDs() { | ||||
return array_values($this->forcedEmailPHIDs); | return array_values($this->forcedEmailPHIDs); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | abstract class HeraldAdapter extends Phobject { | ||||
public function getApplicationEmail() { | public function getApplicationEmail() { | ||||
return $this->applicationEmail; | return $this->applicationEmail; | ||||
} | } | ||||
abstract public function getPHID(); | abstract public function getPHID(); | ||||
abstract public function getHeraldName(); | abstract public function getHeraldName(); | ||||
public function getHeraldField($field_name) { | public function getHeraldField($field_name) { | ||||
$impl = $this->getFieldImplementation($field_name); | |||||
if ($impl) { | |||||
return $impl->getHeraldFieldValue($this->getObject()); | |||||
} | |||||
switch ($field_name) { | switch ($field_name) { | ||||
case self::FIELD_RULE: | case self::FIELD_RULE: | ||||
return null; | return null; | ||||
case self::FIELD_CONTENT_SOURCE: | |||||
return $this->getContentSource()->getSource(); | |||||
case self::FIELD_ALWAYS: | case self::FIELD_ALWAYS: | ||||
return true; | return true; | ||||
case self::FIELD_IS_NEW_OBJECT: | case self::FIELD_IS_NEW_OBJECT: | ||||
return $this->getIsNewObject(); | return $this->getIsNewObject(); | ||||
case self::FIELD_CC: | case self::FIELD_CC: | ||||
$object = $this->getObject(); | $object = $this->getObject(); | ||||
if (!($object instanceof PhabricatorSubscribableInterface)) { | if (!($object instanceof PhabricatorSubscribableInterface)) { | ||||
▲ Show 20 Lines • Show All 143 Lines • ▼ Show 20 Lines | abstract class HeraldAdapter extends Phobject { | ||||
public function getAdapterSortOrder() { | public function getAdapterSortOrder() { | ||||
return 1000; | return 1000; | ||||
} | } | ||||
/* -( Fields )------------------------------------------------------------- */ | /* -( Fields )------------------------------------------------------------- */ | ||||
private function getFieldImplementationMap() { | |||||
if ($this->fieldMap === null) { | |||||
// We can't use PhutilClassMapQuery here because field expansion | |||||
// depends on the adapter and object. | |||||
$object = $this->getObject(); | |||||
$map = array(); | |||||
$all = HeraldField::getAllFields(); | |||||
foreach ($all as $key => $field) { | |||||
if (!$field->supportsObject($object)) { | |||||
continue; | |||||
} | |||||
$subfields = $field->getFieldsForObject($object); | |||||
foreach ($subfields as $subkey => $subfield) { | |||||
if (isset($map[$subkey])) { | |||||
throw new Exception( | |||||
pht( | |||||
'Two HeraldFields (of classes "%s" and "%s") have the same '. | |||||
'field key ("%s") after expansion for an object of class '. | |||||
'"%s" inside adapter "%s". Each field must have a unique '. | |||||
'field key.', | |||||
get_class($subfield), | |||||
get_class($map[$subkey]), | |||||
$subkey, | |||||
get_class($object), | |||||
get_class($this))); | |||||
} | |||||
$subfield = id(clone $subfield)->setAdapter($this); | |||||
$map[$subkey] = $subfield; | |||||
} | |||||
} | |||||
$this->fieldMap = $map; | |||||
} | |||||
return $this->fieldMap; | |||||
} | |||||
private function getFieldImplementation($key) { | |||||
return idx($this->getFieldImplementationMap(), $key); | |||||
} | |||||
public function getFields() { | public function getFields() { | ||||
$fields = array(); | $fields = array_keys($this->getFieldImplementationMap()); | ||||
$fields[] = self::FIELD_ALWAYS; | $fields[] = self::FIELD_ALWAYS; | ||||
$fields[] = self::FIELD_RULE; | $fields[] = self::FIELD_RULE; | ||||
$custom_fields = $this->getCustomFields(); | $custom_fields = $this->getCustomFields(); | ||||
if ($custom_fields) { | if ($custom_fields) { | ||||
foreach ($custom_fields->getFields() as $custom_field) { | foreach ($custom_fields->getFields() as $custom_field) { | ||||
$key = $custom_field->getFieldKey(); | $key = $custom_field->getFieldKey(); | ||||
$fields[] = $this->getHeraldKeyFromCustomKey($key); | $fields[] = $this->getHeraldKeyFromCustomKey($key); | ||||
} | } | ||||
} | } | ||||
return $fields; | return $fields; | ||||
} | } | ||||
public function getFieldNameMap() { | public function getFieldNameMap() { | ||||
return array( | $map = mpull($this->getFieldImplementationMap(), 'getHeraldFieldName'); | ||||
return $map + array( | |||||
self::FIELD_TITLE => pht('Title'), | self::FIELD_TITLE => pht('Title'), | ||||
self::FIELD_BODY => pht('Body'), | self::FIELD_BODY => pht('Body'), | ||||
self::FIELD_AUTHOR => pht('Author'), | self::FIELD_AUTHOR => pht('Author'), | ||||
self::FIELD_ASSIGNEE => pht('Assignee'), | self::FIELD_ASSIGNEE => pht('Assignee'), | ||||
self::FIELD_COMMITTER => pht('Committer'), | self::FIELD_COMMITTER => pht('Committer'), | ||||
self::FIELD_REVIEWER => pht('Reviewer'), | self::FIELD_REVIEWER => pht('Reviewer'), | ||||
self::FIELD_REVIEWERS => pht('Reviewers'), | self::FIELD_REVIEWERS => pht('Reviewers'), | ||||
self::FIELD_CC => pht('CCs'), | self::FIELD_CC => pht('CCs'), | ||||
self::FIELD_TAGS => pht('Tags'), | self::FIELD_TAGS => pht('Tags'), | ||||
self::FIELD_DIFF_FILE => pht('Any changed filename'), | self::FIELD_DIFF_FILE => pht('Any changed filename'), | ||||
self::FIELD_DIFF_CONTENT => pht('Any changed file content'), | self::FIELD_DIFF_CONTENT => pht('Any changed file content'), | ||||
self::FIELD_DIFF_ADDED_CONTENT => pht('Any added file content'), | self::FIELD_DIFF_ADDED_CONTENT => pht('Any added file content'), | ||||
self::FIELD_DIFF_REMOVED_CONTENT => pht('Any removed file content'), | self::FIELD_DIFF_REMOVED_CONTENT => pht('Any removed file content'), | ||||
self::FIELD_DIFF_ENORMOUS => pht('Change is enormous'), | self::FIELD_DIFF_ENORMOUS => pht('Change is enormous'), | ||||
self::FIELD_REPOSITORY => pht('Repository'), | self::FIELD_REPOSITORY => pht('Repository'), | ||||
self::FIELD_REPOSITORY_PROJECTS => pht('Repository\'s projects'), | self::FIELD_REPOSITORY_PROJECTS => pht('Repository\'s projects'), | ||||
self::FIELD_RULE => pht('Another Herald rule'), | self::FIELD_RULE => pht('Another Herald rule'), | ||||
self::FIELD_AFFECTED_PACKAGE => pht('Any affected package'), | self::FIELD_AFFECTED_PACKAGE => pht('Any affected package'), | ||||
self::FIELD_AFFECTED_PACKAGE_OWNER => | self::FIELD_AFFECTED_PACKAGE_OWNER => | ||||
pht("Any affected package's owner"), | pht("Any affected package's owner"), | ||||
self::FIELD_CONTENT_SOURCE => pht('Content Source'), | |||||
self::FIELD_ALWAYS => pht('Always'), | self::FIELD_ALWAYS => pht('Always'), | ||||
self::FIELD_AUTHOR_PROJECTS => pht("Author's projects"), | self::FIELD_AUTHOR_PROJECTS => pht("Author's projects"), | ||||
self::FIELD_PROJECTS => pht('Projects'), | self::FIELD_PROJECTS => pht('Projects'), | ||||
self::FIELD_PUSHER => pht('Pusher'), | self::FIELD_PUSHER => pht('Pusher'), | ||||
self::FIELD_PUSHER_PROJECTS => pht("Pusher's projects"), | self::FIELD_PUSHER_PROJECTS => pht("Pusher's projects"), | ||||
self::FIELD_DIFFERENTIAL_REVISION => pht('Differential revision'), | self::FIELD_DIFFERENTIAL_REVISION => pht('Differential revision'), | ||||
self::FIELD_DIFFERENTIAL_REVIEWERS => pht('Differential reviewers'), | self::FIELD_DIFFERENTIAL_REVIEWERS => pht('Differential reviewers'), | ||||
self::FIELD_DIFFERENTIAL_CCS => pht('Differential CCs'), | self::FIELD_DIFFERENTIAL_CCS => pht('Differential CCs'), | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | return array( | ||||
self::CONDITION_NEVER => '', // don't show anything! | self::CONDITION_NEVER => '', // don't show anything! | ||||
self::CONDITION_REGEXP_PAIR => pht('matches regexp pair'), | self::CONDITION_REGEXP_PAIR => pht('matches regexp pair'), | ||||
self::CONDITION_HAS_BIT => pht('has bit'), | self::CONDITION_HAS_BIT => pht('has bit'), | ||||
self::CONDITION_NOT_BIT => pht('lacks bit'), | self::CONDITION_NOT_BIT => pht('lacks bit'), | ||||
); | ); | ||||
} | } | ||||
public function getConditionsForField($field) { | public function getConditionsForField($field) { | ||||
$impl = $this->getFieldImplementation($field); | |||||
if ($impl) { | |||||
return $impl->getHeraldFieldConditions(); | |||||
} | |||||
switch ($field) { | switch ($field) { | ||||
case self::FIELD_TITLE: | case self::FIELD_TITLE: | ||||
case self::FIELD_BODY: | case self::FIELD_BODY: | ||||
case self::FIELD_COMMITTER_RAW: | case self::FIELD_COMMITTER_RAW: | ||||
case self::FIELD_AUTHOR_RAW: | case self::FIELD_AUTHOR_RAW: | ||||
case self::FIELD_PATH: | case self::FIELD_PATH: | ||||
return array( | return array( | ||||
self::CONDITION_CONTAINS, | self::CONDITION_CONTAINS, | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | switch ($field) { | ||||
self::CONDITION_REGEXP, | self::CONDITION_REGEXP, | ||||
self::CONDITION_REGEXP_PAIR, | self::CONDITION_REGEXP_PAIR, | ||||
); | ); | ||||
case self::FIELD_RULE: | case self::FIELD_RULE: | ||||
return array( | return array( | ||||
self::CONDITION_RULE, | self::CONDITION_RULE, | ||||
self::CONDITION_NOT_RULE, | self::CONDITION_NOT_RULE, | ||||
); | ); | ||||
case self::FIELD_CONTENT_SOURCE: | |||||
return array( | |||||
self::CONDITION_IS, | |||||
self::CONDITION_IS_NOT, | |||||
); | |||||
case self::FIELD_ALWAYS: | case self::FIELD_ALWAYS: | ||||
return array( | return array( | ||||
self::CONDITION_UNCONDITIONALLY, | self::CONDITION_UNCONDITIONALLY, | ||||
); | ); | ||||
case self::FIELD_DIFFERENTIAL_REVIEWERS: | case self::FIELD_DIFFERENTIAL_REVIEWERS: | ||||
return array( | return array( | ||||
self::CONDITION_EXISTS, | self::CONDITION_EXISTS, | ||||
self::CONDITION_NOT_EXISTS, | self::CONDITION_NOT_EXISTS, | ||||
▲ Show 20 Lines • Show All 393 Lines • ▼ Show 20 Lines | /* -( Actions )------------------------------------------------------------ */ | ||||
} | } | ||||
/* -( Values )------------------------------------------------------------- */ | /* -( Values )------------------------------------------------------------- */ | ||||
public function getValueTypeForFieldAndCondition($field, $condition) { | public function getValueTypeForFieldAndCondition($field, $condition) { | ||||
$impl = $this->getFieldImplementation($field); | |||||
if ($impl) { | |||||
return $impl->getHeraldFieldValueType($condition); | |||||
} | |||||
if ($this->isHeraldCustomKey($field)) { | if ($this->isHeraldCustomKey($field)) { | ||||
$value_type = $this->getCustomFieldValueTypeForFieldAndCondition( | $value_type = $this->getCustomFieldValueTypeForFieldAndCondition( | ||||
$field, | $field, | ||||
$condition); | $condition); | ||||
if ($value_type !== null) { | if ($value_type !== null) { | ||||
return $value_type; | return $value_type; | ||||
} | } | ||||
} | } | ||||
switch ($condition) { | switch ($condition) { | ||||
case self::CONDITION_CONTAINS: | case self::CONDITION_CONTAINS: | ||||
case self::CONDITION_NOT_CONTAINS: | case self::CONDITION_NOT_CONTAINS: | ||||
case self::CONDITION_REGEXP: | case self::CONDITION_REGEXP: | ||||
case self::CONDITION_REGEXP_PAIR: | case self::CONDITION_REGEXP_PAIR: | ||||
return self::VALUE_TEXT; | return self::VALUE_TEXT; | ||||
case self::CONDITION_IS: | case self::CONDITION_IS: | ||||
case self::CONDITION_IS_NOT: | case self::CONDITION_IS_NOT: | ||||
switch ($field) { | |||||
case self::FIELD_CONTENT_SOURCE: | |||||
return self::VALUE_CONTENT_SOURCE; | |||||
default: | |||||
return self::VALUE_TEXT; | return self::VALUE_TEXT; | ||||
} | |||||
break; | |||||
case self::CONDITION_IS_ANY: | case self::CONDITION_IS_ANY: | ||||
case self::CONDITION_IS_NOT_ANY: | case self::CONDITION_IS_NOT_ANY: | ||||
switch ($field) { | switch ($field) { | ||||
case self::FIELD_REPOSITORY: | case self::FIELD_REPOSITORY: | ||||
return self::VALUE_REPOSITORY; | return self::VALUE_REPOSITORY; | ||||
case self::FIELD_TASK_PRIORITY: | case self::FIELD_TASK_PRIORITY: | ||||
return self::VALUE_TASK_PRIORITY; | return self::VALUE_TASK_PRIORITY; | ||||
case self::FIELD_TASK_STATUS: | case self::FIELD_TASK_STATUS: | ||||
▲ Show 20 Lines • Show All 824 Lines • Show Last 20 Lines |