[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

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

   1  <?php
   2  
   3  final class DifferentialSetDiffPropertyConduitAPIMethod
   4    extends DifferentialConduitAPIMethod {
   5  
   6    public function getAPIMethodName() {
   7      return 'differential.setdiffproperty';
   8    }
   9  
  10    public function getMethodDescription() {
  11      return 'Attach properties to Differential diffs.';
  12    }
  13  
  14    public function defineParamTypes() {
  15      return array(
  16        'diff_id' => 'required diff_id',
  17        'name'    => 'required string',
  18        'data'    => 'required string',
  19      );
  20    }
  21  
  22    public function defineReturnType() {
  23      return 'void';
  24    }
  25  
  26    public function defineErrorTypes() {
  27      return array(
  28        'ERR_NOT_FOUND' => 'Diff was not found.',
  29      );
  30    }
  31  
  32    private static function updateLintStatus($diff_id) {
  33  
  34      $diff = id(new DifferentialDiff())->load($diff_id);
  35      if (!$diff) {
  36        throw new ConduitException('ERR_NOT_FOUND');
  37      }
  38  
  39      // Load the postponed linters attached to this diff.
  40      $postponed_linters_property = id(
  41        new DifferentialDiffProperty())->loadOneWhere(
  42          'diffID = %d AND name = %s',
  43          $diff_id,
  44          'arc:lint-postponed');
  45      if ($postponed_linters_property) {
  46        $postponed_linters = $postponed_linters_property->getData();
  47      } else {
  48        $postponed_linters = array();
  49      }
  50  
  51      // Load the lint messages currenty attached to the diff
  52      $messages_property = id(new DifferentialDiffProperty())->loadOneWhere(
  53        'diffID = %d AND name = %s',
  54        $diff_id,
  55        'arc:lint');
  56      if ($messages_property) {
  57        $results = $messages_property->getData();
  58      } else {
  59        $results = array();
  60      }
  61  
  62      $has_error = false;
  63      $has_warning = false;
  64      foreach ($results as $result) {
  65        if ($result['severity'] === ArcanistLintSeverity::SEVERITY_ERROR) {
  66          $has_error = true;
  67          break;
  68        } else if ($result['severity'] ===
  69                   ArcanistLintSeverity::SEVERITY_WARNING) {
  70          $has_warning = true;
  71        }
  72      }
  73  
  74      if ($has_error) {
  75        $diff->setLintStatus(DifferentialLintStatus::LINT_FAIL);
  76      } else if ($has_warning) {
  77        $diff->setLintStatus(DifferentialLintStatus::LINT_WARN);
  78      } else if (!empty($postponed_linters)) {
  79        $diff->setLintStatus(DifferentialLintStatus::LINT_POSTPONED);
  80      } else if ($diff->getLintStatus() != DifferentialLintStatus::LINT_SKIP) {
  81        $diff->setLintStatus(DifferentialLintStatus::LINT_OKAY);
  82      }
  83      $diff->save();
  84    }
  85  
  86    protected function execute(ConduitAPIRequest $request) {
  87      $diff_id = $request->getValue('diff_id');
  88      $name = $request->getValue('name');
  89      $data = json_decode($request->getValue('data'), true);
  90  
  91      self::updateDiffProperty($diff_id, $name, $data);
  92  
  93      if ($name === 'arc:lint' || $name == 'arc:lint-postponed') {
  94        self::updateLintStatus($diff_id);
  95      }
  96  
  97      return;
  98    }
  99  
 100    private static function updateDiffProperty($diff_id, $name, $data) {
 101      $property = id(new DifferentialDiffProperty())->loadOneWhere(
 102        'diffID = %d AND name = %s',
 103        $diff_id,
 104        $name);
 105      if (!$property) {
 106        $property = new DifferentialDiffProperty();
 107        $property->setDiffID($diff_id);
 108        $property->setName($name);
 109      }
 110      $property->setData($data);
 111      $property->save();
 112      return $property;
 113    }
 114  
 115  }


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