Modularize all remaining Phriction Herald fields

Summary: Ref T8726.

Test Plan:
  - Created a rule using all the fields.
  - Updated documents, saw rule apply, reviewed transcript.
  - Migrated stuff.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: eadler, epriestley

Maniphest Tasks: T8726

Differential Revision: https://secure.phabricator.com/D13514
This commit is contained in:
epriestley
2015-07-06 13:17:50 -07:00
parent 415e4d4cc1
commit 68de3dae9a
11 changed files with 139 additions and 52 deletions

View File

@@ -0,0 +1,24 @@
<?php
final class PhrictionDocumentAuthorHeraldField
extends PhrictionDocumentHeraldField {
const FIELDCONST = 'phriction.document.author';
public function getHeraldFieldName() {
return pht('Author');
}
public function getHeraldFieldValue($object) {
return $object->getContent()->getAuthorPHID();
}
protected function getHeraldFieldStandardConditions() {
return self::STANDARD_PHID;
}
public function getHeraldFieldValueType($condition) {
return HeraldAdapter::VALUE_USER;
}
}

View File

@@ -0,0 +1,24 @@
<?php
final class PhrictionDocumentContentHeraldField
extends PhrictionDocumentHeraldField {
const FIELDCONST = 'phriction.document.content';
public function getHeraldFieldName() {
return pht('Content');
}
public function getHeraldFieldValue($object) {
return $object->getContent()->getContent();
}
protected function getHeraldFieldStandardConditions() {
return self::STANDARD_TEXT;
}
public function getHeraldFieldValueType($condition) {
return HeraldAdapter::VALUE_TEXT;
}
}

View File

@@ -48,17 +48,6 @@ final class PhrictionDocumentHeraldAdapter extends HeraldAdapter {
}
}
public function getFields() {
return array_merge(
array(
self::FIELD_TITLE,
self::FIELD_BODY,
self::FIELD_AUTHOR,
self::FIELD_PATH,
),
parent::getFields());
}
public function getActions($rule_type) {
switch ($rule_type) {
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
@@ -83,38 +72,9 @@ final class PhrictionDocumentHeraldAdapter extends HeraldAdapter {
}
}
public function getPHID() {
return $this->getDocument()->getPHID();
}
public function getHeraldName() {
return pht('Wiki Document %d', $this->getDocument()->getID());
}
public function getHeraldField($field) {
switch ($field) {
case self::FIELD_TITLE:
return $this->getDocument()->getContent()->getTitle();
case self::FIELD_BODY:
return $this->getDocument()->getContent()->getContent();
case self::FIELD_AUTHOR:
return $this->getDocument()->getContent()->getAuthorPHID();
case self::FIELD_PATH:
return $this->getDocument()->getContent()->getSlug();
}
return parent::getHeraldField($field);
}
public function applyHeraldEffects(array $effects) {
assert_instances_of($effects, 'HeraldEffect');
$result = array();
foreach ($effects as $effect) {
$result[] = $this->applyStandardEffect($effect);
}
return $result;
}
}

View File

@@ -0,0 +1,9 @@
<?php
abstract class PhrictionDocumentHeraldField extends HeraldField {
public function supportsObject($object) {
return ($object instanceof PhrictionDocument);
}
}

View File

@@ -0,0 +1,24 @@
<?php
final class PhrictionDocumentPathHeraldField
extends PhrictionDocumentHeraldField {
const FIELDCONST = 'path';
public function getHeraldFieldName() {
return pht('Path');
}
public function getHeraldFieldValue($object) {
return $object->getcontent()->getSlug();
}
protected function getHeraldFieldStandardConditions() {
return self::STANDARD_TEXT;
}
public function getHeraldFieldValueType($condition) {
return HeraldAdapter::VALUE_TEXT;
}
}

View File

@@ -0,0 +1,24 @@
<?php
final class PhrictionDocumentTitleHeraldField
extends PhrictionDocumentHeraldField {
const FIELDCONST = 'phriction.document.title';
public function getHeraldFieldName() {
return pht('Title');
}
public function getHeraldFieldValue($object) {
return $object->getContent()->getTitle();
}
protected function getHeraldFieldStandardConditions() {
return self::STANDARD_TEXT;
}
public function getHeraldFieldValueType($condition) {
return HeraldAdapter::VALUE_TEXT;
}
}