1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-03 12:12:43 +01:00
phorge-phorge/src/applications/ponder/herald/HeraldPonderQuestionAdapter.php
epriestley a90b16e83a Define available Herald rule repetition options in terms of "isSingleEventAdapter()"
Summary:
Depends on D18924. Ref T13048. Each adapter defines which repetition options ("every time", "only the first time") users may select for rules.

Currently, this is all explicit and hard-coded. However, every adapter really just implements this rule (except for some bugs, see below):

> You can pick "only the first time" if this adapter fires more than once on the same object.

Since we already have a `isSingleEventAdapter()` method which lets us tell if an adapter fires more than once, just write this rule in the base class and delete all the copy/pasting.

This also fixes two bugs because of the copy/pasting: Pholio Mocks and Phriction Documents did not allow you to write "only the first time" rules. There's no reason for this, they just didn't copy/paste enough methods when they were implemented.

This will make a future diff (which introduces an "if the rule did not match last time" policy) cleaner.

Test Plan:
  - Checked several different types of rules, saw appropriate options in the dropdown (pre-commit: no options; tasks: first or every).
  - Checked mocks and wiki docs, saw that you can now write "only the first time" rules.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13048

Differential Revision: https://secure.phabricator.com/D18925
2018-01-26 11:02:35 -08:00

70 lines
1.5 KiB
PHP

<?php
final class HeraldPonderQuestionAdapter extends HeraldAdapter {
private $question;
protected function newObject() {
return new PonderQuestion();
}
public function getAdapterApplicationClass() {
return 'PhabricatorPonderApplication';
}
public function getAdapterContentDescription() {
return pht('React to questions being created or updated.');
}
protected function initializeNewAdapter() {
$this->question = $this->newObject();
}
public function isTestAdapterForObject($object) {
return ($object instanceof PonderQuestion);
}
public function getAdapterTestDescription() {
return pht(
'Test rules which run when a question is created or updated.');
}
public function setObject($object) {
$this->question = $object;
return $this;
}
public function supportsApplicationEmail() {
return true;
}
public function supportsRuleType($rule_type) {
switch ($rule_type) {
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
return true;
case HeraldRuleTypeConfig::RULE_TYPE_OBJECT:
default:
return false;
}
}
public function setQuestion(PonderQuestion $question) {
$this->question = $question;
return $this;
}
public function getObject() {
return $this->question;
}
public function getAdapterContentName() {
return pht('Ponder Questions');
}
public function getHeraldName() {
return 'Q'.$this->getObject()->getID();
}
}