[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

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

   1  <?php
   2  
   3  final class DifferentialCreateDiffConduitAPIMethod
   4    extends DifferentialConduitAPIMethod {
   5  
   6    public function getAPIMethodName() {
   7      return 'differential.creatediff';
   8    }
   9  
  10    public function getMethodDescription() {
  11      return 'Create a new Differential diff.';
  12    }
  13  
  14    public function defineParamTypes() {
  15  
  16      $vcs_const = $this->formatStringConstants(
  17        array(
  18          'svn',
  19          'git',
  20          'hg',
  21        ));
  22  
  23      $status_const = $this->formatStringConstants(
  24        array(
  25          'none',
  26          'skip',
  27          'okay',
  28          'warn',
  29          'fail',
  30          'postponed',
  31        ));
  32  
  33      return array(
  34        'changes'                   => 'required list<dict>',
  35        'sourceMachine'             => 'required string',
  36        'sourcePath'                => 'required string',
  37        'branch'                    => 'required string',
  38        'bookmark'                  => 'optional string',
  39        'sourceControlSystem'       => 'required '.$vcs_const,
  40        'sourceControlPath'         => 'required string',
  41        'sourceControlBaseRevision' => 'required string',
  42        'creationMethod'            => 'optional string',
  43        'arcanistProject'           => 'optional string',
  44        'lintStatus'                => 'required '.$status_const,
  45        'unitStatus'                => 'required '.$status_const,
  46        'repositoryPHID'            => 'optional phid',
  47  
  48        'parentRevisionID'          => 'deprecated',
  49        'authorPHID'                => 'deprecated',
  50        'repositoryUUID'            => 'deprecated',
  51      );
  52    }
  53  
  54    public function defineReturnType() {
  55      return 'nonempty dict';
  56    }
  57  
  58    public function defineErrorTypes() {
  59      return array(
  60      );
  61    }
  62  
  63    protected function execute(ConduitAPIRequest $request) {
  64      $viewer = $request->getUser();
  65      $change_data = $request->getValue('changes');
  66  
  67      $changes = array();
  68      foreach ($change_data as $dict) {
  69        $changes[] = ArcanistDiffChange::newFromDictionary($dict);
  70      }
  71  
  72      $diff = DifferentialDiff::newFromRawChanges($viewer, $changes);
  73  
  74      // TODO: Remove repository UUID eventually; for now continue writing
  75      // the UUID. Note that we'll overwrite it below if we identify a
  76      // repository, and `arc` no longer sends it. This stuff is retained for
  77      // backward compatibility.
  78  
  79      $repository_uuid = $request->getValue('repositoryUUID');
  80      $repository_phid = $request->getValue('repositoryPHID');
  81      if ($repository_phid) {
  82        $repository = id(new PhabricatorRepositoryQuery())
  83          ->setViewer($viewer)
  84          ->withPHIDs(array($repository_phid))
  85          ->executeOne();
  86        if ($repository) {
  87          $repository_phid = $repository->getPHID();
  88          $repository_uuid = $repository->getUUID();
  89        }
  90      }
  91  
  92      $project_name = $request->getValue('arcanistProject');
  93      $project_phid = null;
  94      if ($project_name) {
  95        $arcanist_project = id(new PhabricatorRepositoryArcanistProject())
  96          ->loadOneWhere(
  97            'name = %s',
  98            $project_name);
  99        if (!$arcanist_project) {
 100          $arcanist_project = new PhabricatorRepositoryArcanistProject();
 101          $arcanist_project->setName($project_name);
 102          $arcanist_project->save();
 103        }
 104        $project_phid = $arcanist_project->getPHID();
 105      }
 106  
 107      switch ($request->getValue('lintStatus')) {
 108        case 'skip':
 109          $lint_status = DifferentialLintStatus::LINT_SKIP;
 110          break;
 111        case 'okay':
 112          $lint_status = DifferentialLintStatus::LINT_OKAY;
 113          break;
 114        case 'warn':
 115          $lint_status = DifferentialLintStatus::LINT_WARN;
 116          break;
 117        case 'fail':
 118          $lint_status = DifferentialLintStatus::LINT_FAIL;
 119          break;
 120        case 'postponed':
 121          $lint_status = DifferentialLintStatus::LINT_POSTPONED;
 122          break;
 123        case 'none':
 124        default:
 125          $lint_status = DifferentialLintStatus::LINT_NONE;
 126          break;
 127      }
 128  
 129      switch ($request->getValue('unitStatus')) {
 130        case 'skip':
 131          $unit_status = DifferentialUnitStatus::UNIT_SKIP;
 132          break;
 133        case 'okay':
 134          $unit_status = DifferentialUnitStatus::UNIT_OKAY;
 135          break;
 136        case 'warn':
 137          $unit_status = DifferentialUnitStatus::UNIT_WARN;
 138          break;
 139        case 'fail':
 140          $unit_status = DifferentialUnitStatus::UNIT_FAIL;
 141          break;
 142        case 'postponed':
 143          $unit_status = DifferentialUnitStatus::UNIT_POSTPONED;
 144          break;
 145        case 'none':
 146        default:
 147          $unit_status = DifferentialUnitStatus::UNIT_NONE;
 148          break;
 149      }
 150  
 151      $diff_data_dict = array(
 152        'sourcePath' => $request->getValue('sourcePath'),
 153        'sourceMachine' => $request->getValue('sourceMachine'),
 154        'branch' => $request->getValue('branch'),
 155        'creationMethod' => $request->getValue('creationMethod'),
 156        'authorPHID' => $viewer->getPHID(),
 157        'bookmark' => $request->getValue('bookmark'),
 158        'repositoryUUID' => $repository_uuid,
 159        'repositoryPHID' => $repository_phid,
 160        'sourceControlSystem' => $request->getValue('sourceControlSystem'),
 161        'sourceControlPath' => $request->getValue('sourceControlPath'),
 162        'sourceControlBaseRevision' =>
 163          $request->getValue('sourceControlBaseRevision'),
 164        'arcanistProjectPHID' => $project_phid,
 165        'lintStatus' => $lint_status,
 166        'unitStatus' => $unit_status,);
 167  
 168      $xactions = array(id(new DifferentialTransaction())
 169        ->setTransactionType(DifferentialDiffTransaction::TYPE_DIFF_CREATE)
 170        ->setNewValue($diff_data_dict),);
 171  
 172      id(new DifferentialDiffEditor())
 173        ->setActor($viewer)
 174        ->setContentSourceFromConduitRequest($request)
 175        ->applyTransactions($diff, $xactions);
 176  
 177      $path = '/differential/diff/'.$diff->getID().'/';
 178      $uri = PhabricatorEnv::getURI($path);
 179  
 180      return array(
 181        'diffid' => $diff->getID(),
 182        'uri'    => $uri,
 183      );
 184    }
 185  
 186  }


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