[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class DiffusionLastModifiedController extends DiffusionController { 4 5 public function shouldAllowPublic() { 6 return true; 7 } 8 9 public function processRequest() { 10 $drequest = $this->getDiffusionRequest(); 11 $request = $this->getRequest(); 12 $viewer = $request->getUser(); 13 14 $paths = $request->getStr('paths'); 15 $paths = json_decode($paths, true); 16 if (!is_array($paths)) { 17 return new Aphront400Response(); 18 } 19 20 $modified_map = $this->callConduitWithDiffusionRequest( 21 'diffusion.lastmodifiedquery', 22 array( 23 'paths' => array_fill_keys($paths, $drequest->getCommit()), 24 )); 25 26 if ($modified_map) { 27 $commit_map = id(new DiffusionCommitQuery()) 28 ->setViewer($viewer) 29 ->withRepository($drequest->getRepository()) 30 ->withIdentifiers(array_values($modified_map)) 31 ->needCommitData(true) 32 ->execute(); 33 $commit_map = mpull($commit_map, null, 'getCommitIdentifier'); 34 } else { 35 $commit_map = array(); 36 } 37 38 $commits = array(); 39 foreach ($paths as $path) { 40 $modified_at = idx($modified_map, $path); 41 if ($modified_at) { 42 $commit = idx($commit_map, $modified_at); 43 if ($commit) { 44 $commits[$path] = $commit; 45 } 46 } 47 } 48 49 $phids = array(); 50 foreach ($commits as $commit) { 51 $data = $commit->getCommitData(); 52 $phids[] = $data->getCommitDetail('authorPHID'); 53 $phids[] = $data->getCommitDetail('committerPHID'); 54 } 55 $phids = array_filter($phids); 56 $handles = $this->loadViewerHandles($phids); 57 58 $branch = $drequest->loadBranch(); 59 if ($branch && $commits) { 60 $lint_query = id(new DiffusionLintCountQuery()) 61 ->withBranchIDs(array($branch->getID())) 62 ->withPaths(array_keys($commits)); 63 64 if ($drequest->getLint()) { 65 $lint_query->withCodes(array($drequest->getLint())); 66 } 67 68 $lint = $lint_query->execute(); 69 } else { 70 $lint = array(); 71 } 72 73 $output = array(); 74 foreach ($commits as $path => $commit) { 75 $prequest = clone $drequest; 76 $prequest->setPath($path); 77 78 $output[$path] = $this->renderColumns( 79 $prequest, 80 $handles, 81 $commit, 82 idx($lint, $path)); 83 } 84 85 return id(new AphrontAjaxResponse())->setContent($output); 86 } 87 88 private function renderColumns( 89 DiffusionRequest $drequest, 90 array $handles, 91 PhabricatorRepositoryCommit $commit = null, 92 $lint = null) { 93 assert_instances_of($handles, 'PhabricatorObjectHandle'); 94 $viewer = $this->getRequest()->getUser(); 95 96 if ($commit) { 97 $epoch = $commit->getEpoch(); 98 $modified = DiffusionView::linkCommit( 99 $drequest->getRepository(), 100 $commit->getCommitIdentifier()); 101 $date = phabricator_date($epoch, $viewer); 102 $time = phabricator_time($epoch, $viewer); 103 } else { 104 $modified = ''; 105 $date = ''; 106 $time = ''; 107 } 108 109 $data = $commit->getCommitData(); 110 if ($data) { 111 $author_phid = $data->getCommitDetail('authorPHID'); 112 if ($author_phid && isset($handles[$author_phid])) { 113 $author = $handles[$author_phid]->renderLink(); 114 } else { 115 $author = DiffusionView::renderName($data->getAuthorName()); 116 } 117 118 $committer = $data->getCommitDetail('committer'); 119 if ($committer) { 120 $committer_phid = $data->getCommitDetail('committerPHID'); 121 if ($committer_phid && isset($handles[$committer_phid])) { 122 $committer = $handles[$committer_phid]->renderLink(); 123 } else { 124 $committer = DiffusionView::renderName($committer); 125 } 126 if ($author != $committer) { 127 $author = hsprintf('%s/%s', $author, $committer); 128 } 129 } 130 131 $details = AphrontTableView::renderSingleDisplayLine($data->getSummary()); 132 } else { 133 $author = ''; 134 $details = ''; 135 } 136 137 $return = array( 138 'commit' => $modified, 139 'date' => $date, 140 'time' => $time, 141 'author' => $author, 142 'details' => $details, 143 ); 144 145 if ($lint !== null) { 146 $return['lint'] = phutil_tag( 147 'a', 148 array( 149 'href' => $drequest->generateURI(array( 150 'action' => 'lint', 151 'lint' => null, 152 )), 153 ), 154 number_format($lint)); 155 } 156 157 return $return; 158 } 159 160 }
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 |