[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/releeph/conduit/ -> ReleephProjectInfoConduitAPIMethod.php (source)

   1  <?php
   2  
   3  final class ReleephProjectInfoConduitAPIMethod extends ReleephConduitAPIMethod {
   4  
   5    public function getAPIMethodName() {
   6      return 'releeph.projectinfo';
   7    }
   8  
   9    public function getMethodDescription() {
  10      return
  11        'Fetch information about all Releeph projects '.
  12        'for a given Arcanist project.';
  13    }
  14  
  15    public function defineParamTypes() {
  16      return array(
  17        'arcProjectName' => 'optional string',
  18      );
  19    }
  20  
  21    public function defineReturnType() {
  22      return 'dict<string, wild>';
  23    }
  24  
  25    public function defineErrorTypes() {
  26      return array(
  27        'ERR_UNKNOWN_ARC' =>
  28          "The given Arcanist project name doesn't exist in the ".
  29          "installation of Phabricator you are accessing.",
  30      );
  31    }
  32  
  33    protected function execute(ConduitAPIRequest $request) {
  34      $arc_project_name = $request->getValue('arcProjectName');
  35      if ($arc_project_name) {
  36        $arc_project = id(new PhabricatorRepositoryArcanistProject())
  37          ->loadOneWhere('name = %s', $arc_project_name);
  38        if (!$arc_project) {
  39          throw id(new ConduitException('ERR_UNKNOWN_ARC'))
  40            ->setErrorDescription(
  41              "Unknown Arcanist project '{$arc_project_name}': ".
  42              "are you using the correct Conduit URI?");
  43        }
  44  
  45        $releeph_projects = id(new ReleephProject())
  46          ->loadAllWhere('arcanistProjectID = %d', $arc_project->getID());
  47      } else {
  48        $releeph_projects = id(new ReleephProject())->loadAll();
  49      }
  50  
  51      $releeph_projects = mfilter($releeph_projects, 'getIsActive');
  52  
  53      $result = array();
  54      foreach ($releeph_projects as $releeph_project) {
  55        $selector = $releeph_project->getReleephFieldSelector();
  56        $fields = $selector->getFieldSpecifications();
  57  
  58        $fields_info = array();
  59        foreach ($fields as $field) {
  60          $field->setReleephProject($releeph_project);
  61          if ($field->isEditable()) {
  62            $key = $field->getKeyForConduit();
  63            $fields_info[$key] = array(
  64              'class'   => get_class($field),
  65              'name'    => $field->getName(),
  66              'key'     => $key,
  67              'arcHelp' => $field->renderHelpForArcanist(),
  68            );
  69          }
  70        }
  71  
  72        $releeph_branches = mfilter(
  73          id(new ReleephBranch())
  74            ->loadAllWhere('releephProjectID = %d', $releeph_project->getID()),
  75          'getIsActive');
  76  
  77        $releeph_branches_struct = array();
  78        foreach ($releeph_branches as $branch) {
  79          $releeph_branches_struct[] = array(
  80            'branchName'  => $branch->getName(),
  81            'projectName' => $releeph_project->getName(),
  82            'projectPHID' => $releeph_project->getPHID(),
  83            'branchPHID'  => $branch->getPHID(),
  84          );
  85        }
  86  
  87        $result[] = array(
  88          'projectName' => $releeph_project->getName(),
  89          'projectPHID' => $releeph_project->getPHID(),
  90          'branches'    => $releeph_branches_struct,
  91          'fields'      => $fields_info,
  92        );
  93      }
  94  
  95      return $result;
  96    }
  97  
  98  }


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