[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/diffusion/conduit/ -> DiffusionUpdateCoverageConduitAPIMethod.php (source)

   1  <?php
   2  
   3  final class DiffusionUpdateCoverageConduitAPIMethod
   4    extends DiffusionConduitAPIMethod {
   5  
   6    public function getAPIMethodName() {
   7      return 'diffusion.updatecoverage';
   8    }
   9  
  10    public function getMethodStatus() {
  11      return self::METHOD_STATUS_UNSTABLE;
  12    }
  13  
  14    public function getMethodDescription() {
  15      return pht('Publish coverage information for a repository.');
  16    }
  17  
  18    public function defineReturnType() {
  19      return 'void';
  20    }
  21  
  22    public function defineParamTypes() {
  23      return array(
  24        'repositoryPHID' => 'required phid',
  25        'branch' => 'required string',
  26        'commit' => 'required string',
  27        'coverage' => 'required map<string, string>',
  28      );
  29    }
  30  
  31    public function defineErrorTypes() {
  32      return array();
  33    }
  34  
  35    protected function execute(ConduitAPIRequest $request) {
  36      $viewer = $request->getUser();
  37  
  38      $repository_phid = $request->getValue('repositoryPHID');
  39      $repository = id(new PhabricatorRepositoryQuery())
  40        ->setViewer($viewer)
  41        ->withPHIDs(array($repository_phid))
  42        ->executeOne();
  43  
  44      if (!$repository) {
  45        throw new Exception(
  46          pht('No repository exists with PHID "%s".', $repository_phid));
  47      }
  48  
  49      $commit_name = $request->getValue('commit');
  50      $commit = id(new DiffusionCommitQuery())
  51        ->setViewer($viewer)
  52        ->withRepository($repository)
  53        ->withIdentifiers(array($commit_name))
  54        ->executeOne();
  55      if (!$commit) {
  56        throw new Exception(
  57          pht('No commit exists with identifier "%s".', $commit_name));
  58      }
  59  
  60      $branch = PhabricatorRepositoryBranch::loadOrCreateBranch(
  61        $repository->getID(),
  62        $request->getValue('branch'));
  63  
  64      $coverage = $request->getValue('coverage');
  65      $path_map = id(new DiffusionPathIDQuery(array_keys($coverage)))
  66        ->loadPathIDs();
  67  
  68      $conn = $repository->establishConnection('w');
  69  
  70      $sql = array();
  71      foreach ($coverage as $path => $coverage_info) {
  72        $sql[] = qsprintf(
  73          $conn,
  74          '(%d, %d, %d, %s)',
  75          $branch->getID(),
  76          $path_map[$path],
  77          $commit->getID(),
  78          $coverage_info);
  79      }
  80  
  81      $table_name = 'repository_coverage';
  82  
  83      $conn->openTransaction();
  84        queryfx(
  85          $conn,
  86          'DELETE FROM %T WHERE branchID = %d',
  87          $table_name,
  88          $branch->getID());
  89  
  90        foreach (PhabricatorLiskDAO::chunkSQL($sql) as $chunk) {
  91          queryfx(
  92            $conn,
  93            'INSERT INTO %T (branchID, pathID, commitID, coverage) VALUES %Q',
  94            $table_name,
  95            $chunk);
  96        }
  97      $conn->saveTransaction();
  98    }
  99  
 100  }


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