1
0
Fork 0

Fix regression in previous merge

pull/171/head
Jordi Boggiano 2011-12-21 16:37:41 +01:00
parent 85ec42bac3
commit 9452a94e30
1 changed files with 20 additions and 23 deletions

View File

@ -70,15 +70,32 @@ EOT
return $composer->getRepositoryManager()->findPackage($input->getArgument('package'), $input->getArgument('version')); return $composer->getRepositoryManager()->findPackage($input->getArgument('package'), $input->getArgument('version'));
} }
// we only have a name, so search for the highest package where the name matches // check if we have a local installation so we can grab the right package/version
$localRepo = $composer->getRepositoryManager()->getLocalRepository();
foreach ($localRepo->getPackages() as $package) {
if ($package->getName() === $input->getArgument('package')) {
return $package;
}
}
// we only have a name, so search for the highest version of the given package
$highestVersion = null;
$repos = array_merge( $repos = array_merge(
array($composer->getRepositoryManager()->getLocalRepository()), array($composer->getRepositoryManager()->getLocalRepository()),
$composer->getRepositoryManager()->getRepositories() $composer->getRepositoryManager()->getRepositories()
); );
if ($package = $this->getHighestVersion($repos, $input->getArgument('package'))) { foreach ($repos as $repository) {
return $package; foreach ($repository->getPackages() as $package) {
if ($packageName === $package->getName()) {
if (null === $highestVersion || version_compare($package->getVersion(), $highestVersion->getVersion(), '>=')) {
$highestVersion = $package;
} }
} }
}
}
return $highestVersion;
}
/** /**
* prints package meta data * prints package meta data
@ -150,24 +167,4 @@ EOT
} }
} }
} }
/**
* get highest matching package name from an array of repositories
*/
protected function getHighestVersion(array $repos, $packageName)
{
$highest = null;
foreach ($repos as $repository) {
foreach ($repository->getPackages() as $package) {
if ($packageName === $package->getName()) {
if (null === $highest || version_compare($package->getVersion(), $highest->getVersion(), '>=')) {
$highest = $package;
}
}
}
}
return $highest;
}
} }