Skip to content
This repository has been archived by the owner on Mar 1, 2021. It is now read-only.

Commit

Permalink
fixed command and cs
Browse files Browse the repository at this point in the history
  • Loading branch information
bamarni committed May 20, 2012
1 parent 24e62c9 commit 655b460
Showing 1 changed file with 16 additions and 24 deletions.
@@ -1,19 +1,14 @@
<?php <?php


namespace Doctrine\ODM\MongoDB\Symfony\TailableCursorBundle\Command; namespace Doctrine\Bundle\MongoDBTailableCursorBundle\Command;


use Symfony\Bundle\FrameworkBundle\Command\Command; use Doctrine\Bundle\MongoDBTailableCursorBundle\ProcessorInterface;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\ODM\MongoDB\Symfony\TailableCursorBundle\ProcessorInterface;
use ReflectionClass;
use Exception;
use InvalidArgumentException;


class TailableCursorCommand extends Command class TailableCursorCommand extends ContainerAwareCommand
{ {
protected function configure() protected function configure()
{ {
Expand All @@ -28,30 +23,27 @@ protected function configure()


protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$dm = $this->container->get('doctrine.odm.mongodb.document_manager'); $dm = $this->getContainer()->get('doctrine.odm.mongodb.document_manager');
$repository = $dm->getRepository($input->getArgument('document')); $repository = $dm->getRepository($input->getArgument('document'));
$repositoryReflection = new ReflectionClass(get_class($repository)); $repositoryReflection = new \ReflectionClass(get_class($repository));
$documentReflection = $repository->getDocumentManager()->getMetadataFactory()->getMetadataFor($input->getArgument('document'))->getReflectionClass(); $documentReflection = $repository->getDocumentManager()->getMetadataFactory()->getMetadataFor($input->getArgument('document'))->getReflectionClass();
$processor = $this->container->get($input->getArgument('processor')); $processor = $this->getContainer()->get($input->getArgument('processor'));


if ( ! $processor instanceof ProcessorInterface) { if (!$processor instanceof ProcessorInterface) {
throw new InvalidArgumentException('A tailable cursor processor must implement the ProcessorInterface.'); throw new \InvalidArgumentException('A tailable cursor processor must implement the ProcessorInterface.');
} }


$processorReflection = new ReflectionClass(get_class($processor)); $processorReflection = new \ReflectionClass(get_class($processor));
$method = $input->getArgument('finder'); $method = $input->getArgument('finder');


$output->writeln(sprintf('Getting cursor for <info>%s</info> from <info>%s#%s</info>', $input->getArgument('document'), $repositoryReflection->getShortName(), $method)); $output->writeln(sprintf('Getting cursor for <info>%s</info> from <info>%s#%s</info>', $input->getArgument('document'), $repositoryReflection->getShortName(), $method));
$output->writeln(null); $output->writeln(null);


$cursor = $repository->$method(); $cursor = $repository->$method();


if (!count($cursor)) {
$output->writeln('<comment>Nothing found, waiting to try again</comment>');
}

while (true) { while (true) {
if ( ! $cursor->hasNext()) { while (!$cursor->hasNext()) {
$output->writeln('<comment>Nothing found, waiting to try again</comment>');
// read all results so far, wait for more // read all results so far, wait for more
sleep(10); sleep(10);
} }
Expand All @@ -66,14 +58,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln(null); $output->writeln(null);


try { try {
$processor->process($output, $document); $processor->process($document);
} catch (Exception $e) { } catch (\Exception $e) {
$output->writeln(sprintf('Error occurred while processing document: <error>%s</error>', $e->getMessage())); $output->writeln(sprintf('Error occurred while processing document: <error>%s</error>', $e->getMessage()));
continue; continue;
} }


$dm->flush(array('safe' => true)); $dm->flush();
$dm->clear(); $dm->clear();
} }
} }
} }

0 comments on commit 655b460

Please sign in to comment.