[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class DiffusionExternalController extends DiffusionController { 4 5 public function willProcessRequest(array $data) { 6 // Don't build a DiffusionRequest. 7 } 8 9 public function shouldAllowPublic() { 10 return true; 11 } 12 13 public function processRequest() { 14 $request = $this->getRequest(); 15 16 $uri = $request->getStr('uri'); 17 $id = $request->getStr('id'); 18 19 $repositories = id(new PhabricatorRepositoryQuery()) 20 ->setViewer($request->getUser()) 21 ->execute(); 22 23 if ($uri) { 24 $uri_path = id(new PhutilURI($uri))->getPath(); 25 $matches = array(); 26 27 // Try to figure out which tracked repository this external lives in by 28 // comparing repository metadata. We look for an exact match, but accept 29 // a partial match. 30 31 foreach ($repositories as $key => $repository) { 32 $remote_uri = new PhutilURI($repository->getRemoteURI()); 33 if ($remote_uri->getPath() == $uri_path) { 34 $matches[$key] = 1; 35 } 36 if ($repository->getPublicCloneURI() == $uri) { 37 $matches[$key] = 2; 38 } 39 if ($repository->getRemoteURI() == $uri) { 40 $matches[$key] = 3; 41 } 42 } 43 44 arsort($matches); 45 $best_match = head_key($matches); 46 47 if ($best_match) { 48 $repository = $repositories[$best_match]; 49 $redirect = DiffusionRequest::generateDiffusionURI( 50 array( 51 'action' => 'browse', 52 'callsign' => $repository->getCallsign(), 53 'branch' => $repository->getDefaultBranch(), 54 'commit' => $id, 55 )); 56 return id(new AphrontRedirectResponse())->setURI($redirect); 57 } 58 } 59 60 // TODO: This is a rare query but does a table scan, add a key? 61 62 $commits = id(new PhabricatorRepositoryCommit())->loadAllWhere( 63 'commitIdentifier = %s', 64 $id); 65 66 if (empty($commits)) { 67 $desc = null; 68 if ($uri) { 69 $desc = $uri.', at '; 70 } 71 $desc .= $id; 72 73 $content = id(new AphrontErrorView()) 74 ->setTitle(pht('Unknown External')) 75 ->setSeverity(AphrontErrorView::SEVERITY_WARNING) 76 ->appendChild(phutil_tag( 77 'p', 78 array(), 79 pht('This external (%s) does not appear in any tracked '. 80 'repository. It may exist in an untracked repository that '. 81 'Diffusion does not know about.', $desc))); 82 } else if (count($commits) == 1) { 83 $commit = head($commits); 84 $repo = $repositories[$commit->getRepositoryID()]; 85 $redirect = DiffusionRequest::generateDiffusionURI( 86 array( 87 'action' => 'browse', 88 'callsign' => $repo->getCallsign(), 89 'branch' => $repo->getDefaultBranch(), 90 'commit' => $commit->getCommitIdentifier(), 91 )); 92 return id(new AphrontRedirectResponse())->setURI($redirect); 93 } else { 94 95 $rows = array(); 96 foreach ($commits as $commit) { 97 $repo = $repositories[$commit->getRepositoryID()]; 98 $href = DiffusionRequest::generateDiffusionURI( 99 array( 100 'action' => 'browse', 101 'callsign' => $repo->getCallsign(), 102 'branch' => $repo->getDefaultBranch(), 103 'commit' => $commit->getCommitIdentifier(), 104 )); 105 $rows[] = array( 106 phutil_tag( 107 'a', 108 array( 109 'href' => $href, 110 ), 111 'r'.$repo->getCallsign().$commit->getCommitIdentifier()), 112 $commit->loadCommitData()->getSummary(), 113 ); 114 } 115 116 $table = new AphrontTableView($rows); 117 $table->setHeaders( 118 array( 119 pht('Commit'), 120 pht('Description'), 121 )); 122 $table->setColumnClasses( 123 array( 124 'pri', 125 'wide', 126 )); 127 128 $content = new AphrontPanelView(); 129 $content->setHeader(pht('Multiple Matching Commits')); 130 $content->setCaption( 131 pht('This external reference matches multiple known commits.')); 132 $content->appendChild($table); 133 } 134 135 return $this->buildApplicationPage( 136 $content, 137 array( 138 'title' => pht('Unresolvable External'), 139 )); 140 } 141 142 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |