Implement populator and add corresponding command

This commit is contained in:
ornicar 2011-04-11 19:27:47 -07:00
parent c56f4e62f5
commit 02dd4d85cc
3 changed files with 67 additions and 0 deletions

View file

@ -0,0 +1,39 @@
<?php
namespace FOQ\ElasticaBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\Output;
/**
* Populate the search index
*/
class PopulateCommand extends Command
{
/**
* @see Command
*/
protected function configure()
{
$this
->setName('foq:elastica:populate')
->setDescription('Populates search indexes from providers');
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('Populating indexes');
$populator = $this->container->get('foq_elastica.populator');
$populator->populate();
$output->writeln('Done');
}
}

20
Populator.php Normal file
View file

@ -0,0 +1,20 @@
<?php
namespace FOQ\ElasticaBundle;
class Populator
{
protected $providers;
public function __construct(array $providers)
{
$this->providers = $providers;
}
public function populate()
{
foreach ($this->providers as $provider) {
$provider->populate();
}
}
}

8
ProviderInterface.php Normal file
View file

@ -0,0 +1,8 @@
<?php
namespace FOQ\ElasticaBundle;
interface ProviderInterface
{
function populate();
}