Remove product literal strings in "pht()", part 6
[phabricator.git] / src / applications / differential / herald / HeraldDifferentialRevisionAdapter.php
blob858a42dbc9178046303c1db5a404d5e46677b003
1 <?php
3 final class HeraldDifferentialRevisionAdapter
4 extends HeraldDifferentialAdapter
5 implements HarbormasterBuildableAdapterInterface {
7 protected $revision;
9 protected $affectedPackages;
10 protected $changesets;
11 private $haveHunks;
13 private $buildRequests = array();
15 public function getAdapterApplicationClass() {
16 return 'PhabricatorDifferentialApplication';
19 protected function newObject() {
20 return new DifferentialRevision();
23 public function isTestAdapterForObject($object) {
24 return ($object instanceof DifferentialRevision);
27 public function getAdapterTestDescription() {
28 return pht(
29 'Test rules which run when a revision is created or updated.');
32 public function newTestAdapter(PhabricatorUser $viewer, $object) {
33 return self::newLegacyAdapter(
34 $object,
35 $object->loadActiveDiff());
38 protected function initializeNewAdapter() {
39 $this->revision = $this->newObject();
42 public function getObject() {
43 return $this->revision;
46 public function getAdapterContentType() {
47 return 'differential';
50 public function getAdapterContentName() {
51 return pht('Differential Revisions');
54 public function getAdapterContentDescription() {
55 return pht(
56 "React to revisions being created or updated.\n".
57 "Revision rules can send email, flag revisions, add reviewers, ".
58 "and run build plans.");
61 public function supportsRuleType($rule_type) {
62 switch ($rule_type) {
63 case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
64 case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
65 return true;
66 case HeraldRuleTypeConfig::RULE_TYPE_OBJECT:
67 default:
68 return false;
72 public static function newLegacyAdapter(
73 DifferentialRevision $revision,
74 DifferentialDiff $diff) {
75 $object = new HeraldDifferentialRevisionAdapter();
77 // Reload the revision to pick up relationship information.
78 $revision = id(new DifferentialRevisionQuery())
79 ->withIDs(array($revision->getID()))
80 ->setViewer(PhabricatorUser::getOmnipotentUser())
81 ->needReviewers(true)
82 ->executeOne();
84 $object->revision = $revision;
85 $object->setDiff($diff);
87 return $object;
90 public function getHeraldName() {
91 return $this->revision->getTitle();
94 protected function loadChangesets() {
95 if ($this->changesets === null) {
96 $this->changesets = $this->getDiff()->loadChangesets();
98 return $this->changesets;
101 protected function loadChangesetsWithHunks() {
102 $changesets = $this->loadChangesets();
104 if ($changesets && !$this->haveHunks) {
105 $this->haveHunks = true;
107 id(new DifferentialHunkQuery())
108 ->setViewer(PhabricatorUser::getOmnipotentUser())
109 ->withChangesets($changesets)
110 ->needAttachToChangesets(true)
111 ->execute();
114 return $changesets;
117 public function loadAffectedPackages() {
118 if ($this->affectedPackages === null) {
119 $this->affectedPackages = array();
121 $repository = $this->loadRepository();
122 if ($repository) {
123 $packages = PhabricatorOwnersPackage::loadAffectedPackagesForChangesets(
124 $repository,
125 $this->getDiff(),
126 $this->loadChangesets());
127 $this->affectedPackages = $packages;
130 return $this->affectedPackages;
133 public function loadReviewers() {
134 return $this->getObject()->getReviewerPHIDs();
138 /* -( HarbormasterBuildableAdapterInterface )------------------------------ */
141 public function getHarbormasterBuildablePHID() {
142 return $this->getDiff()->getPHID();
145 public function getHarbormasterContainerPHID() {
146 return $this->getObject()->getPHID();
149 public function getQueuedHarbormasterBuildRequests() {
150 return $this->buildRequests;
153 public function queueHarbormasterBuildRequest(
154 HarbormasterBuildRequest $request) {
155 $this->buildRequests[] = $request;