@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Modernize Diffusion lint controllers

Summary: Ref T4245. On their best day these don't work all that well, but I'm pretty sure I didn't make anything worse.

Test Plan:
- Viewed global lint.
- Viewed lint for a repository.
- Viewed lint details for a particular message.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T4245

Differential Revision: https://secure.phabricator.com/D14948

+230 -205
-2
src/__phutil_library_map__.php
··· 621 621 'DiffusionLastModifiedQueryConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionLastModifiedQueryConduitAPIMethod.php', 622 622 'DiffusionLintController' => 'applications/diffusion/controller/DiffusionLintController.php', 623 623 'DiffusionLintCountQuery' => 'applications/diffusion/query/DiffusionLintCountQuery.php', 624 - 'DiffusionLintDetailsController' => 'applications/diffusion/controller/DiffusionLintDetailsController.php', 625 624 'DiffusionLintSaveRunner' => 'applications/diffusion/DiffusionLintSaveRunner.php', 626 625 'DiffusionLookSoonConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionLookSoonConduitAPIMethod.php', 627 626 'DiffusionLowLevelCommitFieldsQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelCommitFieldsQuery.php', ··· 4585 4584 'DiffusionLastModifiedQueryConduitAPIMethod' => 'DiffusionQueryConduitAPIMethod', 4586 4585 'DiffusionLintController' => 'DiffusionController', 4587 4586 'DiffusionLintCountQuery' => 'PhabricatorQuery', 4588 - 'DiffusionLintDetailsController' => 'DiffusionController', 4589 4587 'DiffusionLintSaveRunner' => 'Phobject', 4590 4588 'DiffusionLookSoonConduitAPIMethod' => 'DiffusionConduitAPIMethod', 4591 4589 'DiffusionLowLevelCommitFieldsQuery' => 'DiffusionLowLevelQuery',
+227 -58
src/applications/diffusion/controller/DiffusionLintController.php
··· 6 6 return true; 7 7 } 8 8 9 - protected function processDiffusionRequest(AphrontRequest $request) { 10 - $user = $request->getUser(); 11 - $drequest = $this->diffusionRequest; 9 + public function handleRequest(AphrontRequest $request) { 10 + $viewer = $this->getViewer(); 12 11 13 - if ($request->getStr('lint') !== null) { 14 - $controller = new DiffusionLintDetailsController(); 15 - $controller->setDiffusionRequest($drequest); 16 - $controller->setCurrentApplication($this->getCurrentApplication()); 17 - return $this->delegateToController($controller); 12 + if ($this->getRepositoryIdentifierFromRequest($request)) { 13 + $response = $this->loadDiffusionContext(); 14 + if ($response) { 15 + return $response; 16 + } 17 + 18 + $drequest = $this->getDiffusionRequest(); 19 + } else { 20 + $drequest = null; 21 + } 22 + 23 + $code = $request->getStr('lint'); 24 + if (strlen($code)) { 25 + return $this->buildDetailsResponse(); 18 26 } 19 27 20 28 $owners = array(); 21 29 if (!$drequest) { 22 30 if (!$request->getArr('owner')) { 23 - $owners = array($user->getPHID()); 31 + $owners = array($viewer->getPHID()); 24 32 } else { 25 33 $owners = array(head($request->getArr('owner'))); 26 34 } 27 35 } 28 36 29 - $codes = $this->loadLintCodes($owners); 37 + $codes = $this->loadLintCodes($drequest, $owners); 30 38 31 - if ($codes && !$drequest) { 32 - // TODO: Build some real Query classes for this stuff. 33 - 39 + if ($codes) { 34 40 $branches = id(new PhabricatorRepositoryBranch())->loadAllWhere( 35 41 'id IN (%Ld)', 36 42 array_unique(ipull($codes, 'branchID'))); 43 + $branches = mpull($branches, null, 'getID'); 44 + } else { 45 + $branches = array(); 46 + } 37 47 48 + if ($branches) { 38 49 $repositories = id(new PhabricatorRepositoryQuery()) 39 - ->setViewer($user) 50 + ->setViewer($viewer) 40 51 ->withIDs(mpull($branches, 'getRepositoryID')) 41 52 ->execute(); 42 - 43 - $drequests = array(); 44 - foreach ($branches as $id => $branch) { 45 - if (empty($repositories[$branch->getRepositoryID()])) { 46 - continue; 47 - } 48 - 49 - $drequests[$id] = DiffusionRequest::newFromDictionary(array( 50 - 'user' => $user, 51 - 'repository' => $repositories[$branch->getRepositoryID()], 52 - 'branch' => $branch->getName(), 53 - )); 54 - } 53 + $repositories = mpull($repositories, null, 'getID'); 54 + } else { 55 + $repositories = array(); 55 56 } 57 + 56 58 57 59 $rows = array(); 58 60 $total = 0; 59 61 foreach ($codes as $code) { 60 - if (!$this->diffusionRequest) { 61 - $drequest = idx($drequests, $code['branchID']); 62 + $branch = idx($branches, $code['branchID']); 63 + if (!$branch) { 64 + continue; 62 65 } 63 66 64 - if (!$drequest) { 67 + $repository = idx($repositories, $branch->getRepositoryID()); 68 + if (!$repository) { 65 69 continue; 66 70 } 67 71 68 72 $total += $code['n']; 69 73 70 - $href_lint = $drequest->generateURI(array( 71 - 'action' => 'lint', 72 - 'lint' => $code['code'], 73 - )); 74 - $href_browse = $drequest->generateURI(array( 75 - 'action' => 'browse', 76 - 'lint' => $code['code'], 77 - )); 78 - $href_repo = $drequest->generateURI(array('action' => 'lint')); 74 + if ($drequest) { 75 + $href_lint = $drequest->generateURI( 76 + array( 77 + 'action' => 'lint', 78 + 'lint' => $code['code'], 79 + )); 80 + 81 + $href_browse = $drequest->generateURI( 82 + array( 83 + 'action' => 'browse', 84 + 'lint' => $code['code'], 85 + )); 86 + 87 + $href_repo = $drequest->generateURI( 88 + array( 89 + 'action' => 'lint', 90 + )); 91 + } else { 92 + $href_lint = $repository->generateURI( 93 + array( 94 + 'action' => 'lint', 95 + 'lint' => $code['code'], 96 + )); 97 + 98 + $href_browse = $repository->generateURI( 99 + array( 100 + 'action' => 'browse', 101 + 'lint' => $code['code'], 102 + )); 103 + 104 + $href_repo = $repository->generateURI( 105 + array( 106 + 'action' => 'lint', 107 + )); 108 + } 79 109 80 110 $rows[] = array( 81 111 phutil_tag('a', array('href' => $href_lint), $code['n']), ··· 85 115 array( 86 116 'href' => $href_repo, 87 117 ), 88 - $drequest->getRepository()->getDisplayName()), 118 + $repository->getDisplayName()), 89 119 ArcanistLintSeverity::getStringForSeverity($code['maxSeverity']), 90 120 $code['code'], 91 121 $code['maxName'], ··· 103 133 pht('Name'), 104 134 pht('Example'), 105 135 )) 106 - ->setColumnVisibility(array(true, true, !$this->diffusionRequest)) 136 + ->setColumnVisibility(array(true, true, !$drequest)) 107 137 ->setColumnClasses(array('n', 'n', '', '', 'pri', '', '')); 108 138 109 139 $content = array(); 110 140 111 - if (!$this->diffusionRequest) { 141 + if (!$drequest) { 112 142 $form = id(new AphrontFormView()) 113 - ->setUser($user) 143 + ->setUser($viewer) 114 144 ->setMethod('GET') 115 145 ->appendControl( 116 146 id(new AphrontFormTokenizerControl()) ··· 137 167 'view' => 'lint', 138 168 )); 139 169 140 - if ($this->diffusionRequest) { 170 + if ($drequest) { 141 171 $title[] = $drequest->getRepository()->getDisplayName(); 142 172 } else { 143 173 $crumbs->addTextCrumb(pht('All Lint')); 144 174 } 145 175 146 - if ($this->diffusionRequest) { 176 + if ($drequest) { 147 177 $branch = $drequest->loadBranch(); 148 178 149 179 $header = id(new PHUIHeaderView()) 150 180 ->setHeader($this->renderPathLinks($drequest, 'lint')) 151 - ->setUser($user) 181 + ->setUser($viewer) 152 182 ->setPolicyObject($drequest->getRepository()); 153 183 $actions = $this->buildActionView($drequest); 154 184 $properties = $this->buildPropertyView( ··· 164 194 $object_box = null; 165 195 } 166 196 167 - 168 - return $this->buildApplicationPage( 169 - array( 170 - $crumbs, 171 - $object_box, 172 - $content, 173 - ), 174 - array( 175 - 'title' => $title, 176 - )); 197 + return $this->newPage() 198 + ->setTitle($title) 199 + ->setCrumbs($crumbs) 200 + ->appendChild( 201 + array( 202 + $object_box, 203 + $content, 204 + )); 177 205 } 178 206 179 - private function loadLintCodes(array $owner_phids) { 180 - $drequest = $this->diffusionRequest; 207 + private function loadLintCodes($drequest, array $owner_phids) { 181 208 $conn = id(new PhabricatorRepository())->establishConnection('r'); 182 209 $where = array('1 = 1'); 183 210 ··· 342 369 } 343 370 344 371 372 + private function buildDetailsResponse() { 373 + $request = $this->getRequest(); 374 + 375 + $limit = 500; 376 + 377 + $pager = id(new PHUIPagerView()) 378 + ->readFromRequest($request) 379 + ->setPageSize($limit); 380 + 381 + $offset = $pager->getOffset(); 382 + 383 + $drequest = $this->getDiffusionRequest(); 384 + $branch = $drequest->loadBranch(); 385 + $messages = $this->loadLintMessages($branch, $limit, $offset); 386 + $is_dir = (substr('/'.$drequest->getPath(), -1) == '/'); 387 + 388 + $pager->setHasMorePages(count($messages) >= $limit); 389 + 390 + $authors = $this->loadViewerHandles(ipull($messages, 'authorPHID')); 391 + 392 + $rows = array(); 393 + foreach ($messages as $message) { 394 + $path = phutil_tag( 395 + 'a', 396 + array( 397 + 'href' => $drequest->generateURI(array( 398 + 'action' => 'lint', 399 + 'path' => $message['path'], 400 + )), 401 + ), 402 + substr($message['path'], strlen($drequest->getPath()) + 1)); 403 + 404 + $line = phutil_tag( 405 + 'a', 406 + array( 407 + 'href' => $drequest->generateURI(array( 408 + 'action' => 'browse', 409 + 'path' => $message['path'], 410 + 'line' => $message['line'], 411 + 'commit' => $branch->getLintCommit(), 412 + )), 413 + ), 414 + $message['line']); 415 + 416 + $author = $message['authorPHID']; 417 + if ($author && $authors[$author]) { 418 + $author = $authors[$author]->renderLink(); 419 + } 420 + 421 + $rows[] = array( 422 + $path, 423 + $line, 424 + $author, 425 + ArcanistLintSeverity::getStringForSeverity($message['severity']), 426 + $message['name'], 427 + $message['description'], 428 + ); 429 + } 430 + 431 + $table = id(new AphrontTableView($rows)) 432 + ->setHeaders(array( 433 + pht('Path'), 434 + pht('Line'), 435 + pht('Author'), 436 + pht('Severity'), 437 + pht('Name'), 438 + pht('Description'), 439 + )) 440 + ->setColumnClasses(array('', 'n')) 441 + ->setColumnVisibility(array($is_dir)); 442 + 443 + $content = array(); 444 + 445 + $content[] = id(new PHUIObjectBoxView()) 446 + ->setHeaderText(pht('Lint Details')) 447 + ->setTable($table); 448 + 449 + $crumbs = $this->buildCrumbs( 450 + array( 451 + 'branch' => true, 452 + 'path' => true, 453 + 'view' => 'lint', 454 + )); 455 + 456 + $pager_box = $this->renderTablePagerBox($pager); 457 + 458 + return $this->newPage() 459 + ->setTitle( 460 + array( 461 + pht('Lint'), 462 + $drequest->getRepository()->getDisplayName(), 463 + )) 464 + ->setCrumbs($crumbs) 465 + ->appendChild( 466 + array( 467 + $content, 468 + $pager_box, 469 + )); 470 + } 471 + 472 + private function loadLintMessages( 473 + PhabricatorRepositoryBranch $branch, 474 + $limit, 475 + $offset) { 476 + 477 + $drequest = $this->getDiffusionRequest(); 478 + if (!$branch) { 479 + return array(); 480 + } 481 + 482 + $conn = $branch->establishConnection('r'); 483 + 484 + $where = array( 485 + qsprintf($conn, 'branchID = %d', $branch->getID()), 486 + ); 487 + 488 + if ($drequest->getPath() != '') { 489 + $path = '/'.$drequest->getPath(); 490 + $is_dir = (substr($path, -1) == '/'); 491 + $where[] = ($is_dir 492 + ? qsprintf($conn, 'path LIKE %>', $path) 493 + : qsprintf($conn, 'path = %s', $path)); 494 + } 495 + 496 + if ($drequest->getLint() != '') { 497 + $where[] = qsprintf( 498 + $conn, 499 + 'code = %s', 500 + $drequest->getLint()); 501 + } 502 + 503 + return queryfx_all( 504 + $conn, 505 + 'SELECT * 506 + FROM %T 507 + WHERE %Q 508 + ORDER BY path, code, line LIMIT %d OFFSET %d', 509 + PhabricatorRepository::TABLE_LINTMESSAGE, 510 + implode(' AND ', $where), 511 + $limit, 512 + $offset); 513 + } 345 514 }
-143
src/applications/diffusion/controller/DiffusionLintDetailsController.php
··· 1 - <?php 2 - 3 - final class DiffusionLintDetailsController extends DiffusionController { 4 - 5 - protected function processDiffusionRequest(AphrontRequest $request) { 6 - $limit = 500; 7 - $offset = $request->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 PHUIPagerView()) 70 - ->setPageSize($limit) 71 - ->setOffset($offset) 72 - ->setHasMorePages(count($messages) >= $limit) 73 - ->setURI($request->getRequestURI(), 'offset'); 74 - 75 - $content[] = id(new PHUIObjectBoxView()) 76 - ->setHeaderText(pht('Lint Details')) 77 - ->setTable($table); 78 - 79 - $crumbs = $this->buildCrumbs( 80 - array( 81 - 'branch' => true, 82 - 'path' => true, 83 - 'view' => 'lint', 84 - )); 85 - 86 - return $this->buildApplicationPage( 87 - array( 88 - $crumbs, 89 - $content, 90 - $pager, 91 - ), 92 - array( 93 - 'title' => array( 94 - pht('Lint'), 95 - $drequest->getRepository()->getDisplayName(), 96 - ), 97 - )); 98 - } 99 - 100 - private function loadLintMessages( 101 - PhabricatorRepositoryBranch $branch, 102 - $limit, 103 - $offset) { 104 - 105 - $drequest = $this->getDiffusionRequest(); 106 - if (!$branch) { 107 - return array(); 108 - } 109 - 110 - $conn = $branch->establishConnection('r'); 111 - 112 - $where = array( 113 - qsprintf($conn, 'branchID = %d', $branch->getID()), 114 - ); 115 - 116 - if ($drequest->getPath() != '') { 117 - $path = '/'.$drequest->getPath(); 118 - $is_dir = (substr($path, -1) == '/'); 119 - $where[] = ($is_dir 120 - ? qsprintf($conn, 'path LIKE %>', $path) 121 - : qsprintf($conn, 'path = %s', $path)); 122 - } 123 - 124 - if ($drequest->getLint() != '') { 125 - $where[] = qsprintf( 126 - $conn, 127 - 'code = %s', 128 - $drequest->getLint()); 129 - } 130 - 131 - return queryfx_all( 132 - $conn, 133 - 'SELECT * 134 - FROM %T 135 - WHERE %Q 136 - ORDER BY path, code, line LIMIT %d OFFSET %d', 137 - PhabricatorRepository::TABLE_LINTMESSAGE, 138 - implode(' AND ', $where), 139 - $limit, 140 - $offset); 141 - } 142 - 143 - }
+3 -2
src/applications/diffusion/request/DiffusionRequest.php
··· 244 244 $data = $blob + $data; 245 245 } 246 246 247 - $this->path = idx($data, 'path'); 248 - $this->line = idx($data, 'line'); 247 + $this->path = idx($data, 'path'); 248 + $this->line = idx($data, 'line'); 249 249 $this->initFromConduit = idx($data, 'initFromConduit', true); 250 + $this->lint = idx($data, 'lint'); 250 251 251 252 $this->symbolicCommit = idx($data, 'commit'); 252 253 if ($this->supportsBranches()) {