[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/differential/conduit/ -> DifferentialFinishPostponedLintersConduitAPIMethod.php (source)

   1  <?php
   2  
   3  final class DifferentialFinishPostponedLintersConduitAPIMethod
   4    extends DifferentialConduitAPIMethod {
   5  
   6    public function getAPIMethodName() {
   7      return 'differential.finishpostponedlinters';
   8    }
   9  
  10    public function getMethodDescription() {
  11      return 'Update diff with new lint messages and mark postponed '.
  12             'linters as finished.';
  13    }
  14  
  15    public function defineParamTypes() {
  16      return array(
  17        'diffID'   => 'required diffID',
  18        'linters'  => 'required dict',
  19      );
  20    }
  21  
  22    public function defineReturnType() {
  23      return 'void';
  24    }
  25  
  26    public function defineErrorTypes() {
  27      return array(
  28        'ERR-BAD-DIFF'   => 'Bad diff ID.',
  29        'ERR-BAD-LINTER' => 'No postponed linter by the given name',
  30        'ERR-NO-LINT'    => 'No postponed lint field available in diff',
  31      );
  32    }
  33  
  34    protected function execute(ConduitAPIRequest $request) {
  35  
  36      $diff_id = $request->getValue('diffID');
  37      $linter_map = $request->getValue('linters');
  38  
  39      $diff = id(new DifferentialDiffQuery())
  40        ->setViewer($request->getUser())
  41        ->withIDs(array($diff_id))
  42        ->executeOne();
  43      if (!$diff) {
  44        throw new ConduitException('ERR-BAD-DIFF');
  45      }
  46  
  47      // Extract the finished linters and messages from the linter map.
  48      $finished_linters = array_keys($linter_map);
  49      $new_messages = array();
  50      foreach ($linter_map as $linter => $messages) {
  51        $new_messages = array_merge($new_messages, $messages);
  52      }
  53  
  54      // Load the postponed linters attached to this diff.
  55      $postponed_linters_property = id(
  56        new DifferentialDiffProperty())->loadOneWhere(
  57          'diffID = %d AND name = %s',
  58          $diff_id,
  59          'arc:lint-postponed');
  60      if ($postponed_linters_property) {
  61        $postponed_linters = $postponed_linters_property->getData();
  62      } else {
  63        $postponed_linters = array();
  64      }
  65  
  66      foreach ($finished_linters as $linter) {
  67        if (!in_array($linter, $postponed_linters)) {
  68          throw new ConduitException('ERR-BAD-LINTER');
  69        }
  70      }
  71  
  72      foreach ($postponed_linters as $idx => $linter) {
  73        if (in_array($linter, $finished_linters)) {
  74          unset($postponed_linters[$idx]);
  75        }
  76      }
  77  
  78      // Load the lint messages currenty attached to the diff. If this
  79      // diff property doesn't exist, create it.
  80      $messages_property = id(new DifferentialDiffProperty())->loadOneWhere(
  81        'diffID = %d AND name = %s',
  82        $diff_id,
  83        'arc:lint');
  84      if ($messages_property) {
  85        $messages = $messages_property->getData();
  86      } else {
  87        $messages = array();
  88      }
  89  
  90      // Add new lint messages, removing duplicates.
  91      foreach ($new_messages as $new_message) {
  92        if (!in_array($new_message, $messages)) {
  93          $messages[] = $new_message;
  94        }
  95      }
  96  
  97      // Use setdiffproperty to update the postponed linters and messages,
  98      // as these will also update the lint status correctly.
  99      $call = new ConduitCall(
 100        'differential.setdiffproperty',
 101        array(
 102          'diff_id' => $diff_id,
 103          'name' => 'arc:lint',
 104          'data' => json_encode($messages),
 105        ));
 106      $call->setForceLocal(true);
 107      $call->setUser($request->getUser());
 108      $call->execute();
 109      $call = new ConduitCall(
 110        'differential.setdiffproperty',
 111        array(
 112          'diff_id' => $diff_id,
 113          'name' => 'arc:lint-postponed',
 114          'data' => json_encode($postponed_linters),
 115        ));
 116      $call->setForceLocal(true);
 117      $call->setUser($request->getUser());
 118      $call->execute();
 119  
 120    }
 121  
 122  }


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