[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class DiffusionPathChangeQuery { 4 5 private $request; 6 private $limit; 7 8 public function setLimit($limit) { 9 $this->limit = $limit; 10 return $this; 11 } 12 13 public function getLimit() { 14 return $this->limit; 15 } 16 17 final private function __construct() { 18 // <private> 19 } 20 21 final public static function newFromDiffusionRequest( 22 DiffusionRequest $request) { 23 $query = new DiffusionPathChangeQuery(); 24 $query->request = $request; 25 26 return $query; 27 } 28 29 final protected function getRequest() { 30 return $this->request; 31 } 32 33 final public function loadChanges() { 34 return $this->executeQuery(); 35 } 36 37 protected function executeQuery() { 38 39 $drequest = $this->getRequest(); 40 $repository = $drequest->getRepository(); 41 42 $commit = $drequest->loadCommit(); 43 44 $conn_r = $repository->establishConnection('r'); 45 46 $limit = ''; 47 if ($this->limit) { 48 $limit = qsprintf( 49 $conn_r, 50 'LIMIT %d', 51 $this->limit + 1); 52 } 53 54 $raw_changes = queryfx_all( 55 $conn_r, 56 'SELECT c.*, p.path pathName, t.path targetPathName, 57 i.commitIdentifier targetCommitIdentifier 58 FROM %T c 59 LEFT JOIN %T p ON c.pathID = p.id 60 LEFT JOIN %T t ON c.targetPathID = t.id 61 LEFT JOIN %T i ON c.targetCommitID = i.id 62 WHERE c.commitID = %d AND isDirect = 1 %Q', 63 PhabricatorRepository::TABLE_PATHCHANGE, 64 PhabricatorRepository::TABLE_PATH, 65 PhabricatorRepository::TABLE_PATH, 66 $commit->getTableName(), 67 $commit->getID(), 68 $limit); 69 70 $limited = $this->limit && (count($raw_changes) > $this->limit); 71 if ($limited) { 72 $raw_changes = array_slice($raw_changes, 0, $this->limit); 73 } 74 75 $changes = array(); 76 77 $raw_changes = isort($raw_changes, 'pathName'); 78 foreach ($raw_changes as $raw_change) { 79 $type = $raw_change['changeType']; 80 if ($type == DifferentialChangeType::TYPE_CHILD) { 81 continue; 82 } 83 84 $change = new DiffusionPathChange(); 85 $change->setPath(ltrim($raw_change['pathName'], '/')); 86 $change->setChangeType($raw_change['changeType']); 87 $change->setFileType($raw_change['fileType']); 88 $change->setCommitIdentifier($commit->getCommitIdentifier()); 89 90 $change->setTargetPath(ltrim($raw_change['targetPathName'], '/')); 91 $change->setTargetCommitIdentifier($raw_change['targetCommitIdentifier']); 92 93 $id = $raw_change['pathID']; 94 $changes[$id] = $change; 95 } 96 97 // Deduce the away paths by examining all the changes, if we loaded them 98 // all. 99 100 if (!$limited) { 101 $away = array(); 102 foreach ($changes as $change) { 103 if ($change->getTargetPath()) { 104 $away[$change->getTargetPath()][] = $change->getPath(); 105 } 106 } 107 foreach ($changes as $change) { 108 if (isset($away[$change->getPath()])) { 109 $change->setAwayPaths($away[$change->getPath()]); 110 } 111 } 112 } 113 114 return $changes; 115 } 116 }
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 |