[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/releeph/editor/ -> ReleephRequestTransactionalEditor.php (source)

   1  <?php
   2  
   3  final class ReleephRequestTransactionalEditor
   4    extends PhabricatorApplicationTransactionEditor {
   5  
   6    public function getEditorApplicationClass() {
   7      return 'PhabricatorReleephApplication';
   8    }
   9  
  10    public function getEditorObjectsDescription() {
  11      return pht('Releeph Requests');
  12    }
  13  
  14    public function getTransactionTypes() {
  15      $types = parent::getTransactionTypes();
  16  
  17      $types[] = PhabricatorTransactions::TYPE_COMMENT;
  18      $types[] = ReleephRequestTransaction::TYPE_COMMIT;
  19      $types[] = ReleephRequestTransaction::TYPE_DISCOVERY;
  20      $types[] = ReleephRequestTransaction::TYPE_EDIT_FIELD;
  21      $types[] = ReleephRequestTransaction::TYPE_MANUAL_IN_BRANCH;
  22      $types[] = ReleephRequestTransaction::TYPE_PICK_STATUS;
  23      $types[] = ReleephRequestTransaction::TYPE_REQUEST;
  24      $types[] = ReleephRequestTransaction::TYPE_USER_INTENT;
  25  
  26      return $types;
  27    }
  28  
  29    public function getCustomTransactionOldValue(
  30      PhabricatorLiskDAO $object,
  31      PhabricatorApplicationTransaction $xaction) {
  32  
  33      switch ($xaction->getTransactionType()) {
  34        case ReleephRequestTransaction::TYPE_REQUEST:
  35          return $object->getRequestCommitPHID();
  36  
  37        case ReleephRequestTransaction::TYPE_EDIT_FIELD:
  38          $field = newv($xaction->getMetadataValue('fieldClass'), array());
  39          $value = $field->setReleephRequest($object)->getValue();
  40          return $value;
  41  
  42        case ReleephRequestTransaction::TYPE_USER_INTENT:
  43          $user_phid = $xaction->getAuthorPHID();
  44          return idx($object->getUserIntents(), $user_phid);
  45  
  46        case ReleephRequestTransaction::TYPE_PICK_STATUS:
  47          return (int)$object->getPickStatus();
  48          break;
  49  
  50        case ReleephRequestTransaction::TYPE_COMMIT:
  51          return $object->getCommitIdentifier();
  52  
  53        case ReleephRequestTransaction::TYPE_DISCOVERY:
  54          return $object->getCommitPHID();
  55  
  56        case ReleephRequestTransaction::TYPE_MANUAL_IN_BRANCH:
  57          return $object->getInBranch();
  58      }
  59    }
  60  
  61    public function getCustomTransactionNewValue(
  62      PhabricatorLiskDAO $object,
  63      PhabricatorApplicationTransaction $xaction) {
  64  
  65      switch ($xaction->getTransactionType()) {
  66        case ReleephRequestTransaction::TYPE_REQUEST:
  67        case ReleephRequestTransaction::TYPE_USER_INTENT:
  68        case ReleephRequestTransaction::TYPE_EDIT_FIELD:
  69        case ReleephRequestTransaction::TYPE_PICK_STATUS:
  70        case ReleephRequestTransaction::TYPE_COMMIT:
  71        case ReleephRequestTransaction::TYPE_DISCOVERY:
  72        case ReleephRequestTransaction::TYPE_MANUAL_IN_BRANCH:
  73          return $xaction->getNewValue();
  74      }
  75    }
  76  
  77    public function applyCustomInternalTransaction(
  78      PhabricatorLiskDAO $object,
  79      PhabricatorApplicationTransaction $xaction) {
  80  
  81      $new = $xaction->getNewValue();
  82  
  83      switch ($xaction->getTransactionType()) {
  84        case ReleephRequestTransaction::TYPE_REQUEST:
  85          $object->setRequestCommitPHID($new);
  86          break;
  87  
  88        case ReleephRequestTransaction::TYPE_USER_INTENT:
  89          $user_phid = $xaction->getAuthorPHID();
  90          $intents = $object->getUserIntents();
  91          $intents[$user_phid] = $new;
  92          $object->setUserIntents($intents);
  93          break;
  94  
  95        case ReleephRequestTransaction::TYPE_EDIT_FIELD:
  96          $field = newv($xaction->getMetadataValue('fieldClass'), array());
  97          $field
  98            ->setReleephRequest($object)
  99            ->setValue($new);
 100          break;
 101  
 102        case ReleephRequestTransaction::TYPE_PICK_STATUS:
 103          $object->setPickStatus($new);
 104          break;
 105  
 106        case ReleephRequestTransaction::TYPE_COMMIT:
 107          $this->setInBranchFromAction($object, $xaction);
 108          $object->setCommitIdentifier($new);
 109          break;
 110  
 111        case ReleephRequestTransaction::TYPE_DISCOVERY:
 112          $this->setInBranchFromAction($object, $xaction);
 113          $object->setCommitPHID($new);
 114          break;
 115  
 116        case ReleephRequestTransaction::TYPE_MANUAL_IN_BRANCH:
 117          $object->setInBranch((int) $new);
 118          break;
 119      }
 120    }
 121  
 122    protected function applyCustomExternalTransaction(
 123      PhabricatorLiskDAO $object,
 124      PhabricatorApplicationTransaction $xaction) {
 125  
 126      return;
 127    }
 128  
 129    protected function filterTransactions(
 130      PhabricatorLiskDAO $object,
 131      array $xactions) {
 132  
 133      // Remove TYPE_DISCOVERY xactions that are the result of a reparse.
 134      $previously_discovered_commits = array();
 135      $discovery_xactions = idx(
 136        mgroup($xactions, 'getTransactionType'),
 137        ReleephRequestTransaction::TYPE_DISCOVERY);
 138      if ($discovery_xactions) {
 139        $previous_xactions = id(new ReleephRequestTransactionQuery())
 140          ->setViewer(PhabricatorUser::getOmnipotentUser())
 141          ->withObjectPHIDs(array($object->getPHID()))
 142          ->execute();
 143  
 144        foreach ($previous_xactions as $xaction) {
 145          if ($xaction->getTransactionType() ===
 146            ReleephRequestTransaction::TYPE_DISCOVERY) {
 147  
 148            $commit_phid = $xaction->getNewValue();
 149            $previously_discovered_commits[$commit_phid] = true;
 150          }
 151        }
 152      }
 153  
 154      foreach ($xactions as $key => $xaction) {
 155        if ($xaction->getTransactionType() ===
 156          ReleephRequestTransaction::TYPE_DISCOVERY &&
 157          idx($previously_discovered_commits, $xaction->getNewValue())) {
 158  
 159          unset($xactions[$key]);
 160        }
 161      }
 162  
 163      return parent::filterTransactions($object, $xactions);
 164    }
 165  
 166    protected function shouldSendMail(
 167      PhabricatorLiskDAO $object,
 168      array $xactions) {
 169      return true;
 170    }
 171  
 172    protected function sendMail(
 173      PhabricatorLiskDAO $object,
 174      array $xactions) {
 175  
 176      // Avoid sending emails that only talk about commit discovery.
 177      $types = array_unique(mpull($xactions, 'getTransactionType'));
 178      if ($types === array(ReleephRequestTransaction::TYPE_DISCOVERY)) {
 179        return null;
 180      }
 181  
 182      // Don't email people when we discover that something picks or reverts OK.
 183      if ($types === array(ReleephRequestTransaction::TYPE_PICK_STATUS)) {
 184        if (!mfilter($xactions, 'isBoringPickStatus', true /* negate */)) {
 185          // If we effectively call "isInterestingPickStatus" and get nothing...
 186          return null;
 187        }
 188      }
 189  
 190      return parent::sendMail($object, $xactions);
 191    }
 192  
 193    protected function buildReplyHandler(PhabricatorLiskDAO $object) {
 194      return id(new ReleephRequestReplyHandler())
 195        ->setActor($this->getActor())
 196        ->setMailReceiver($object);
 197    }
 198  
 199    protected function getMailSubjectPrefix() {
 200      return '[Releeph]';
 201    }
 202  
 203    protected function buildMailTemplate(PhabricatorLiskDAO $object) {
 204      $id = $object->getID();
 205      $phid = $object->getPHID();
 206      $title = $object->getSummaryForDisplay();
 207      return id(new PhabricatorMetaMTAMail())
 208        ->setSubject("RQ{$id}: {$title}")
 209        ->addHeader('Thread-Topic', "RQ{$id}: {$phid}");
 210    }
 211  
 212    protected function getMailTo(PhabricatorLiskDAO $object) {
 213      $to_phids = array();
 214  
 215      $product = $object->getBranch()->getProduct();
 216      foreach ($product->getPushers() as $phid) {
 217        $to_phids[] = $phid;
 218      }
 219  
 220      foreach ($object->getUserIntents() as $phid => $intent) {
 221        $to_phids[] = $phid;
 222      }
 223  
 224      return $to_phids;
 225    }
 226  
 227    protected function getMailCC(PhabricatorLiskDAO $object) {
 228      return array();
 229    }
 230  
 231    protected function buildMailBody(
 232      PhabricatorLiskDAO $object,
 233      array $xactions) {
 234  
 235      $body = parent::buildMailBody($object, $xactions);
 236  
 237      $rq = $object;
 238      $releeph_branch = $rq->getBranch();
 239      $releeph_project = $releeph_branch->getProduct();
 240  
 241      /**
 242       * If any of the events we are emailing about were about a pick failure
 243       * (and/or a revert failure?), include pick failure instructions.
 244       */
 245      $has_pick_failure = false;
 246      foreach ($xactions as $xaction) {
 247        if ($xaction->getTransactionType() ===
 248          ReleephRequestTransaction::TYPE_PICK_STATUS &&
 249          $xaction->getNewValue() === ReleephRequest::PICK_FAILED) {
 250  
 251          $has_pick_failure = true;
 252          break;
 253        }
 254      }
 255      if ($has_pick_failure) {
 256        $instructions = $releeph_project->getDetail('pick_failure_instructions');
 257        if ($instructions) {
 258          $body->addTextSection(
 259            pht('PICK FAILURE INSTRUCTIONS'),
 260            $instructions);
 261        }
 262      }
 263  
 264      $name = sprintf('RQ%s: %s', $rq->getID(), $rq->getSummaryForDisplay());
 265      $body->addTextSection(
 266        pht('RELEEPH REQUEST'),
 267        $name."\n".
 268        PhabricatorEnv::getProductionURI('/RQ'.$rq->getID()));
 269  
 270      $project_and_branch = sprintf(
 271        '%s - %s',
 272        $releeph_project->getName(),
 273        $releeph_branch->getDisplayNameWithDetail());
 274  
 275      $body->addTextSection(
 276        pht('RELEEPH BRANCH'),
 277        $project_and_branch."\n".
 278        PhabricatorEnv::getProductionURI($releeph_branch->getURI()));
 279  
 280      return $body;
 281    }
 282  
 283    private function setInBranchFromAction(
 284      ReleephRequest $rq,
 285      ReleephRequestTransaction $xaction) {
 286  
 287      $action = $xaction->getMetadataValue('action');
 288      switch ($action) {
 289        case 'pick':
 290          $rq->setInBranch(1);
 291          break;
 292  
 293        case 'revert':
 294          $rq->setInBranch(0);
 295          break;
 296  
 297        default:
 298          $id = $rq->getID();
 299          $type = $xaction->getTransactionType();
 300          $new = $xaction->getNewValue();
 301          phlog(
 302            "Unknown discovery action '{$action}' ".
 303            "for xaction of type {$type} ".
 304            "with new value {$new} ".
 305            "mentioning RQ{$id}!");
 306          break;
 307      }
 308    }
 309  
 310  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1