[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorOwnersPackagePathValidator { 4 5 /* 6 * If a file/directory was moved the paths in owners package become stale. 7 * This method updates the stale paths in the owners packages to their new 8 * paths. 9 */ 10 public static function updateOwnersPackagePaths( 11 PhabricatorRepositoryCommit $commit) { 12 $changes = self::loadDiffusionChangesForCommit($commit); 13 14 if (!$changes) { 15 return; 16 } 17 18 // TODO: (T603) This should be policy-aware. 19 $repository = 20 id(new PhabricatorRepository())->load($commit->getRepositoryID()); 21 $move_map = array(); 22 foreach ($changes as $change) { 23 if ($change->getChangeType() == DifferentialChangeType::TYPE_MOVE_HERE) { 24 $from_path = '/'.$change->getTargetPath(); 25 $to_path = '/'.$change->getPath(); 26 if ($change->getFileType() == DifferentialChangeType::FILE_DIRECTORY) { 27 $to_path = $to_path.'/'; 28 $from_path = $from_path.'/'; 29 } 30 $move_map[$from_path] = $to_path; 31 } 32 } 33 34 if ($move_map) { 35 self::updateAffectedPackages($repository, $move_map); 36 } 37 } 38 39 private static function updateAffectedPackages($repository, array $move_map) { 40 $paths = array_keys($move_map); 41 if ($paths) { 42 $packages = PhabricatorOwnersPackage::loadAffectedPackages($repository, 43 $paths); 44 foreach ($packages as $package) { 45 self::updatePackagePaths($package, $move_map); 46 } 47 } 48 } 49 50 private static function updatePackagePaths($package, array $move_map) { 51 $paths = array_keys($move_map); 52 $pkg_paths = $package->loadPaths(); 53 $new_paths = array(); 54 foreach ($pkg_paths as $pkg_path) { 55 $path_changed = false; 56 57 foreach ($paths as $old_path) { 58 if (strncmp($pkg_path->getPath(), $old_path, strlen($old_path)) === 0) { 59 $new_paths[] = array ( 60 'packageID' => $package->getID(), 61 'repositoryPHID' => $pkg_path->getRepositoryPHID(), 62 'path' => str_replace($pkg_path->getPath(), $old_path, 63 $move_map[$old_path]), 64 ); 65 $path_changed = true; 66 } 67 } 68 69 if (!$path_changed) { 70 $new_paths[] = array ( 71 'packageID' => $package->getID(), 72 'repositoryPHID' => $pkg_path->getRepositoryPHID(), 73 'path' => $pkg_path->getPath(), 74 ); 75 } 76 } 77 78 if ($new_paths) { 79 $package->attachOldPrimaryOwnerPHID($package->getPrimaryOwnerPHID()); 80 $package->attachUnsavedPaths($new_paths); 81 $package->save(); // save the changes and notify the owners. 82 } 83 } 84 85 private static function loadDiffusionChangesForCommit($commit) { 86 $repository = 87 id(new PhabricatorRepository())->load($commit->getRepositoryID()); 88 $data = array( 89 'user' => PhabricatorUser::getOmnipotentUser(), 90 'initFromConduit' => false, 91 'repository' => $repository, 92 'commit' => $commit->getCommitIdentifier(), 93 ); 94 $drequest = DiffusionRequest::newFromDictionary($data); 95 $change_query = 96 DiffusionPathChangeQuery::newFromDiffusionRequest($drequest); 97 return $change_query->loadChanges(); 98 } 99 }
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 |