Better logging for the population command

This commit is contained in:
ornicar 2011-04-15 12:19:27 -07:00
parent 7cb9d9ee71
commit 8f3b39d135
4 changed files with 17 additions and 6 deletions

View file

@ -32,8 +32,13 @@ class PopulateCommand extends Command
$output->writeln('Reseting indexes');
$this->container->get('foq_elastica.reseter')->reset();
$output->writeln('Setting mappings');
$this->container->get('foq_elastica.mapping_setter')->setMappings();
$output->writeln('Populating indexes');
$this->container->get('foq_elastica.populator')->populate();
$this->container->get('foq_elastica.populator')->populate(function($text) use ($output) {
$output->writeLn($text);
});
$output->writeln('Done');
}

View file

@ -19,7 +19,7 @@ class AddProviderPass implements CompilerPassInterface
$providers = array();
foreach ($container->findTaggedServiceIds('foq_elastica.provider') as $id => $attributes) {
$providers[] = new Reference($id);
$providers[$id] = new Reference($id);
}
$container->getDefinition('foq_elastica.populator')->setArgument(0, $providers);

View file

@ -2,6 +2,8 @@
namespace FOQ\ElasticaBundle;
use Closure;
class Populator
{
protected $providers;
@ -11,10 +13,12 @@ class Populator
$this->providers = $providers;
}
public function populate()
public function populate(Closure $loggerClosure)
{
foreach ($this->providers as $provider) {
$provider->populate();
foreach ($this->providers as $name => $provider) {
$provider->populate(function($text) use ($name, $loggerClosure) {
$loggerClosure(sprintf('Indexing %s, %s', $name, $text));
});
}
}
}

View file

@ -2,7 +2,9 @@
namespace FOQ\ElasticaBundle;
use Closure;
interface ProviderInterface
{
function populate();
function populate(Closure $loggerClosure);
}