[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 abstract class DiffusionQuery extends PhabricatorQuery { 4 5 private $request; 6 7 final protected function __construct() { 8 // <protected> 9 } 10 11 protected static function newQueryObject( 12 $base_class, 13 DiffusionRequest $request) { 14 15 $repository = $request->getRepository(); 16 17 $obj = self::initQueryObject($base_class, $repository); 18 $obj->request = $request; 19 20 return $obj; 21 } 22 23 final protected static function initQueryObject( 24 $base_class, 25 PhabricatorRepository $repository) { 26 27 $map = array( 28 PhabricatorRepositoryType::REPOSITORY_TYPE_GIT => 'Git', 29 PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL => 'Mercurial', 30 PhabricatorRepositoryType::REPOSITORY_TYPE_SVN => 'Svn', 31 ); 32 33 $name = idx($map, $repository->getVersionControlSystem()); 34 if (!$name) { 35 throw new Exception('Unsupported VCS!'); 36 } 37 38 $class = str_replace('Diffusion', 'Diffusion'.$name, $base_class); 39 $obj = new $class(); 40 return $obj; 41 } 42 43 final protected function getRequest() { 44 return $this->request; 45 } 46 47 final public static function callConduitWithDiffusionRequest( 48 PhabricatorUser $user, 49 DiffusionRequest $drequest, 50 $method, 51 array $params = array()) { 52 53 $repository = $drequest->getRepository(); 54 55 $core_params = array( 56 'callsign' => $repository->getCallsign(), 57 ); 58 59 if ($drequest->getBranch() !== null) { 60 $core_params['branch'] = $drequest->getBranch(); 61 } 62 63 $params = $params + $core_params; 64 65 return id(new ConduitCall( 66 $method, 67 $params 68 )) 69 ->setUser($user) 70 ->execute(); 71 } 72 73 public function execute() { 74 return $this->executeQuery(); 75 } 76 77 abstract protected function executeQuery(); 78 79 80 /* -( Query Utilities )---------------------------------------------------- */ 81 82 83 final public static function loadCommitsByIdentifiers( 84 array $identifiers, 85 DiffusionRequest $drequest) { 86 if (!$identifiers) { 87 return array(); 88 } 89 90 $commits = array(); 91 $commit_data = array(); 92 93 $repository = $drequest->getRepository(); 94 95 $commits = id(new PhabricatorRepositoryCommit())->loadAllWhere( 96 'repositoryID = %d AND commitIdentifier IN (%Ls)', 97 $repository->getID(), 98 $identifiers); 99 $commits = mpull($commits, null, 'getCommitIdentifier'); 100 101 // Build empty commit objects for every commit, so we can show unparsed 102 // commits in history views (as "Importing") instead of not showing them. 103 // This makes the process of importing and parsing commits clearer to the 104 // user. 105 106 $commit_list = array(); 107 foreach ($identifiers as $identifier) { 108 $commit_obj = idx($commits, $identifier); 109 if (!$commit_obj) { 110 $commit_obj = new PhabricatorRepositoryCommit(); 111 $commit_obj->setRepositoryID($repository->getID()); 112 $commit_obj->setCommitIdentifier($identifier); 113 $commit_obj->makeEphemeral(); 114 } 115 $commit_list[$identifier] = $commit_obj; 116 } 117 $commits = $commit_list; 118 119 $commit_ids = array_filter(mpull($commits, 'getID')); 120 if ($commit_ids) { 121 $commit_data = id(new PhabricatorRepositoryCommitData())->loadAllWhere( 122 'commitID in (%Ld)', 123 $commit_ids); 124 $commit_data = mpull($commit_data, null, 'getCommitID'); 125 } 126 127 foreach ($commits as $commit) { 128 if (!$commit->getID()) { 129 continue; 130 } 131 if (idx($commit_data, $commit->getID())) { 132 $commit->attachCommitData($commit_data[$commit->getID()]); 133 } 134 } 135 136 return $commits; 137 } 138 139 final public static function loadHistoryForCommitIdentifiers( 140 array $identifiers, 141 DiffusionRequest $drequest) { 142 143 if (!$identifiers) { 144 return array(); 145 } 146 147 $repository = $drequest->getRepository(); 148 $commits = self::loadCommitsByIdentifiers($identifiers, $drequest); 149 150 if (!$commits) { 151 return array(); 152 } 153 154 $path = $drequest->getPath(); 155 156 $conn_r = $repository->establishConnection('r'); 157 158 $path_normal = DiffusionPathIDQuery::normalizePath($path); 159 $paths = queryfx_all( 160 $conn_r, 161 'SELECT id, path FROM %T WHERE pathHash IN (%Ls)', 162 PhabricatorRepository::TABLE_PATH, 163 array(md5($path_normal))); 164 $paths = ipull($paths, 'id', 'path'); 165 $path_id = idx($paths, $path_normal); 166 167 $commit_ids = array_filter(mpull($commits, 'getID')); 168 169 $path_changes = array(); 170 if ($path_id && $commit_ids) { 171 $path_changes = queryfx_all( 172 $conn_r, 173 'SELECT * FROM %T WHERE commitID IN (%Ld) AND pathID = %d', 174 PhabricatorRepository::TABLE_PATHCHANGE, 175 $commit_ids, 176 $path_id); 177 $path_changes = ipull($path_changes, null, 'commitID'); 178 } 179 180 $history = array(); 181 foreach ($identifiers as $identifier) { 182 $item = new DiffusionPathChange(); 183 $item->setCommitIdentifier($identifier); 184 $commit = idx($commits, $identifier); 185 if ($commit) { 186 $item->setCommit($commit); 187 try { 188 $item->setCommitData($commit->getCommitData()); 189 } catch (Exception $ex) { 190 // Ignore, commit just doesn't have data. 191 } 192 $change = idx($path_changes, $commit->getID()); 193 if ($change) { 194 $item->setChangeType($change['changeType']); 195 $item->setFileType($change['fileType']); 196 } 197 } 198 $history[] = $item; 199 } 200 201 return $history; 202 } 203 }
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 |