|
@@ -12,9 +12,12 @@
|
|
|
|
|
|
namespace Packagist\WebBundle\Command;
|
|
|
|
|
|
+use Packagist\WebBundle\Entity\Package;
|
|
|
+
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
+use Symfony\Component\Console\Input\InputArgument;
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
/**
|
|
@@ -31,7 +34,7 @@ class IndexPackagesCommand extends ContainerAwareCommand
|
|
|
->setName('packagist:index')
|
|
|
->setDefinition(array(
|
|
|
new InputOption('force', null, InputOption::VALUE_NONE, 'Force a re-indexing of all packages'),
|
|
|
- new InputOption('package', null, InputOption::VALUE_NONE, 'Package name to index'),
|
|
|
+ new InputArgument('package', InputArgument::OPTIONAL, 'Package name to index'),
|
|
|
))
|
|
|
->setDescription('Indexes packages')
|
|
|
->setHelp(<<<EOF
|
|
@@ -48,7 +51,7 @@ EOF
|
|
|
{
|
|
|
$verbose = $input->getOption('verbose');
|
|
|
$force = $input->getOption('force');
|
|
|
- $package = $input->getOption('package');
|
|
|
+ $package = $input->getArgument('package');
|
|
|
|
|
|
$doctrine = $this->getContainer()->get('doctrine');
|
|
|
$solarium = $this->getContainer()->get('solarium.client');
|
|
@@ -72,7 +75,7 @@ EOF
|
|
|
}
|
|
|
|
|
|
if ($package) {
|
|
|
- $packages = array($doctrine->getRepository('PackagistWebBundle:Package')->findOneByName($input->getOption('package')));
|
|
|
+ $packages = array($doctrine->getRepository('PackagistWebBundle:Package')->findOneByName($package));
|
|
|
} elseif ($force) {
|
|
|
$packages = $doctrine->getRepository('PackagistWebBundle:Package')->findAll();
|
|
|
} else {
|
|
@@ -88,17 +91,8 @@ EOF
|
|
|
$update = $solarium->createUpdate();
|
|
|
|
|
|
$document = $update->createDocument();
|
|
|
- $document->id = $package->getId();
|
|
|
- $document->name = $package->getName();
|
|
|
- $document->description = $package->getDescription();
|
|
|
-
|
|
|
- $tags = array();
|
|
|
- foreach ($package->getVersions() as $version) {
|
|
|
- foreach ($version->getTags() as $tag) {
|
|
|
- $tags[] = $tag->getName();
|
|
|
- }
|
|
|
- }
|
|
|
- $document->tags = array_unique($tags);
|
|
|
+
|
|
|
+ $this->updateDocumentFromPackage($document, $package);
|
|
|
|
|
|
$update->addDocument($document);
|
|
|
$update->addCommit();
|
|
@@ -114,4 +108,19 @@ EOF
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private function updateDocumentFromPackage(\Solarium_Document_ReadWrite $document, Package $package)
|
|
|
+ {
|
|
|
+ $document->id = $package->getId();
|
|
|
+ $document->name = $package->getName();
|
|
|
+ $document->description = $package->getDescription();
|
|
|
+
|
|
|
+ $tags = array();
|
|
|
+ foreach ($package->getVersions() as $version) {
|
|
|
+ foreach ($version->getTags() as $tag) {
|
|
|
+ $tags[] = $tag->getName();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $document->tags = array_unique($tags);
|
|
|
+ }
|
|
|
}
|