[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/diffusion/controller/ -> DiffusionLintDetailsController.php (source)

   1  <?php
   2  
   3  final class DiffusionLintDetailsController extends DiffusionController {
   4  
   5    public function processRequest() {
   6      $limit = 500;
   7      $offset = $this->getRequest()->getInt('offset', 0);
   8  
   9      $drequest = $this->getDiffusionRequest();
  10      $branch = $drequest->loadBranch();
  11      $messages = $this->loadLintMessages($branch, $limit, $offset);
  12      $is_dir = (substr('/'.$drequest->getPath(), -1) == '/');
  13  
  14      $authors = $this->loadViewerHandles(ipull($messages, 'authorPHID'));
  15  
  16      $rows = array();
  17      foreach ($messages as $message) {
  18        $path = phutil_tag(
  19          'a',
  20          array(
  21            'href' => $drequest->generateURI(array(
  22              'action' => 'lint',
  23              'path' => $message['path'],
  24            )),
  25          ),
  26          substr($message['path'], strlen($drequest->getPath()) + 1));
  27  
  28        $line = phutil_tag(
  29          'a',
  30          array(
  31            'href' => $drequest->generateURI(array(
  32              'action' => 'browse',
  33              'path' => $message['path'],
  34              'line' => $message['line'],
  35              'commit' => $branch->getLintCommit(),
  36            )),
  37          ),
  38          $message['line']);
  39  
  40        $author = $message['authorPHID'];
  41        if ($author && $authors[$author]) {
  42          $author = $authors[$author]->renderLink();
  43        }
  44  
  45        $rows[] = array(
  46          $path,
  47          $line,
  48          $author,
  49          ArcanistLintSeverity::getStringForSeverity($message['severity']),
  50          $message['name'],
  51          $message['description'],
  52        );
  53      }
  54  
  55      $table = id(new AphrontTableView($rows))
  56        ->setHeaders(array(
  57          pht('Path'),
  58          pht('Line'),
  59          pht('Author'),
  60          pht('Severity'),
  61          pht('Name'),
  62          pht('Description'),
  63        ))
  64        ->setColumnClasses(array('', 'n'))
  65        ->setColumnVisibility(array($is_dir));
  66  
  67      $content = array();
  68  
  69      $pager = id(new AphrontPagerView())
  70        ->setPageSize($limit)
  71        ->setOffset($offset)
  72        ->setHasMorePages(count($messages) >= $limit)
  73        ->setURI($this->getRequest()->getRequestURI(), 'offset');
  74  
  75      $content[] = id(new AphrontPanelView())
  76        ->setNoBackground(true)
  77        ->appendChild($table)
  78        ->appendChild($pager);
  79  
  80      $crumbs = $this->buildCrumbs(
  81        array(
  82          'branch' => true,
  83          'path'   => true,
  84          'view'   => 'lint',
  85        ));
  86  
  87      return $this->buildApplicationPage(
  88        array(
  89          $crumbs,
  90          $content,
  91        ),
  92        array(
  93          'title' =>
  94            array(
  95              pht('Lint'),
  96              $drequest->getRepository()->getCallsign(),
  97            ),
  98        ));
  99    }
 100  
 101    private function loadLintMessages(
 102      PhabricatorRepositoryBranch $branch,
 103      $limit,
 104      $offset) {
 105  
 106      $drequest = $this->getDiffusionRequest();
 107      if (!$branch) {
 108        return array();
 109      }
 110  
 111      $conn = $branch->establishConnection('r');
 112  
 113      $where = array(
 114        qsprintf($conn, 'branchID = %d', $branch->getID()),
 115      );
 116  
 117      if ($drequest->getPath() != '') {
 118        $path = '/'.$drequest->getPath();
 119        $is_dir = (substr($path, -1) == '/');
 120        $where[] = ($is_dir
 121          ? qsprintf($conn, 'path LIKE %>', $path)
 122          : qsprintf($conn, 'path = %s', $path));
 123      }
 124  
 125      if ($drequest->getLint() != '') {
 126        $where[] = qsprintf(
 127          $conn,
 128          'code = %s',
 129          $drequest->getLint());
 130      }
 131  
 132      return queryfx_all(
 133        $conn,
 134        'SELECT *
 135          FROM %T
 136          WHERE %Q
 137          ORDER BY path, code, line LIMIT %d OFFSET %d',
 138        PhabricatorRepository::TABLE_LINTMESSAGE,
 139        implode(' AND ', $where),
 140        $limit,
 141        $offset);
 142    }
 143  
 144  }


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