Skip to content

Commit

Permalink
Removed --limit option, added limit container parameter for Finders
Browse files Browse the repository at this point in the history
  • Loading branch information
tyomo4ka committed Jun 8, 2012
1 parent 09c6299 commit 1ef726c
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 44 deletions.
2 changes: 2 additions & 0 deletions app/config/parameters.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ parameters:
banner:
text: "Hello|[Edgar]"
url: "http://knpbundles.com"

knp_bundles.finder.limit: 2000
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ protected function configure()
{
$this
->setDefinition(array())
->addOption('limit', 'l', InputOption::VALUE_OPTIONAL, 'The maximal number of new bundles considered by the update', 2000)
->setName('kb:add:searched-bundles')
;
}
Expand All @@ -36,7 +35,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$updater->setOutput($output);
$updater->setUp();

$bundles = $updater->searchNewBundles((int) $input->getOption('limit'));
$bundles = $updater->searchNewBundles();
$updater->createMissingBundles($bundles);

$em = $this->getContainer()->get('knp_bundles.entity_manager');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ protected function configure()
{
$this
->setDefinition(array())
->addOption('limit', 'l', InputOption::VALUE_OPTIONAL, 'The maximal number of new bundles considered by the update', 1000)
->addOption('no-publish', null, InputOption::VALUE_NONE, 'Prevent the command from publishing a message to RabbitMQ producer')
->setName('kb:populate')
;
Expand All @@ -35,8 +34,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$container = $this->getContainer();

$em = $container->get('knp_bundles.entity_manager');

$updater = $container->get('knp_bundles.updater');

if (!$input->getOption('no-publish')) {
Expand All @@ -47,9 +44,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$updater->setOutput($output);
$updater->setUp();

$bundles = $em->getRepository('Knp\Bundle\KnpBundlesBundle\Entity\Bundle')->findAll();

$bundles = $updater->searchNewBundles((int) $input->getOption('limit'));
$bundles = $updater->searchNewBundles();
$updater->createMissingBundles($bundles);
$updater->updateBundlesData();
$updater->updateUsers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function evolutionAction()

public function listLatestAction()
{
$bundles = $this->getRepository('Bundle')->findAllSortedBy('createdAt', 50);
$bundles = $this->getRepository('Bundle')->findAllSortedBy('createdAt', 'desc', 50);

$format = $this->recognizeRequestFormat(array('atom'), 'atom');

Expand Down
21 changes: 10 additions & 11 deletions src/Knp/Bundle/KnpBundlesBundle/Repository/BundleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@

class BundleRepository extends EntityRepository
{
public function findAllSortedBy($field, $nb = null)
public function findAllSortedBy($field, $order = 'desc', $nb = null)
{
$query = $this->queryAllSortedBy($field);
$query = $this->queryAllSortedBy($field, $order);

if(null !== $nb) {
if (null !== $nb) {
$query->setMaxResults($nb);
}

return $query->execute();
}

public function queryAllSortedBy($field)
public function queryAllSortedBy($field, $order)
{
$qb = $this->createQueryBuilder('bundle');
$qb->orderBy('bundle.'.$field, 'name' === $field ? 'asc' : 'desc');
$qb = $this->createQueryBuilder('b');
$qb->orderBy('b.' . $field, $order);
$query = $qb->getQuery();

return $query;
Expand Down Expand Up @@ -77,14 +77,14 @@ public function queryByKeywordSlug($slug)

public function count()
{
return $this->getEntityManager()->createQuery('SELECT COUNT(bundle.id) FROM '.$this->getEntityName().' bundle')->getSingleScalarResult();
return $this->getEntityManager()->createQuery('SELECT COUNT(bundle.id) FROM ' . $this->getEntityName() . ' bundle')->getSingleScalarResult();
}

public function getLastCommits($nb)
{
$bundles = $this->findByLastCommitAt($nb);
$commits = array();
foreach($bundles as $bundle) {
foreach ($bundles as $bundle) {
$commits = array_merge($commits, $bundle->getLastCommits());
}
usort($commits, function($a, $b)
Expand Down Expand Up @@ -112,7 +112,7 @@ public function findOneByUsernameAndName($username, $name)
->setParameter('name', $name)
->getQuery()
->getSingleResult();
} catch(NoResultException $e) {
} catch (NoResultException $e) {
return null;
}
}
Expand All @@ -123,8 +123,7 @@ public function getStaleBundlesForIndexing()
->leftJoin('bundle.user', 'user')
->where('bundle.indexedAt IS NULL OR bundle.indexedAt < bundle.updatedAt')
->getQuery()
->getResult()
;
->getResult();
}

public function updateTrends()
Expand Down
29 changes: 8 additions & 21 deletions src/Knp/Bundle/KnpBundlesBundle/Resources/config/finder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,19 @@
<services>
<service id="knp_bundles.finder" class="%knp_bundles.finder.aggregate.class%" />

<!-- Search "site:github.com Symfony2 Bundle" on Google -->
<service class="%knp_bundles.finder.google.class%" public="false">
<tag name="knp_bundles.finder" />
<argument>site:github.com Symfony2 Bundle</argument>
<argument>300</argument>
</service>

<!-- Search "site:github.com Symfony2 Project" on Google -->
<service class="%knp_bundles.finder.google.class%" public="false">
<tag name="knp_bundles.finder" />
<argument>site:github.com Symfony2 Project</argument>
<argument>300</argument>
</service>
<!-- Example usage of Google finder: Search query "site:github.com Symfony2 Bundle" on Google -->
<!--<service class="%knp_bundles.finder.google.class%" public="false">-->
<!--<tag name="knp_bundles.finder" />-->
<!--<argument>site:github.com Symfony2 Bundle</argument>-->
<!--<argument>%knp_bundles.finder.limit%</argument>-->
<!--</service>-->

<!-- Search "Symfony2 Bundle" on Github -->
<service class="%knp_bundles.finder.github.class%" public="false">
<tag name="knp_bundles.finder" />
<argument>Symfony2 Bundle</argument>
<argument>300</argument>
<argument>Bundle</argument>
<argument>%knp_bundles.finder.limit%</argument>
</service>

<!-- Search "Symfony2 Project" on Github -->
<service class="%knp_bundles.finder.github.class%" public="false">
<tag name="knp_bundles.finder" />
<argument>Symfony2 Project</argument>
<argument>300</argument>
</service>
</services>
</container>
7 changes: 4 additions & 3 deletions src/Knp/Bundle/KnpBundlesBundle/Updater/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,16 @@ public function setBundleUpdateProducer(Producer $bundleUpdateProducer)
public function setUp()
{
$this->bundles = array();
foreach ($this->em->createQuery('SELECT b FROM KnpBundlesBundle:Bundle b ORDER BY b.updatedAt DESC')->execute() as $bundle) {
foreach ($this->em->getRepository('KnpBundlesBundle:Bundle')->findAllSortedBy('updatedAt') as $bundle) {
$this->bundles[strtolower($bundle->getFullName())] = $bundle;
}
$this->output->writeln(sprintf('Loaded %d bundles from the DB', count($this->bundles)));
}

public function searchNewBundles($nb)
public function searchNewBundles()
{
$foundBundles = $this->githubSearch->searchBundles($nb, $this->output);
$this->githubSearch->setOutput($this->output);
$foundBundles = $this->githubSearch->searchBundles();
$this->output->writeln(sprintf('Found %d bundle candidates', count($foundBundles)));

return $foundBundles;
Expand Down

0 comments on commit 1ef726c

Please sign in to comment.