protected function execute($arguments = array(), $options = array()) { $app = $arguments['application']; $index = $arguments['index']; $culture = $arguments['culture']; $limit = $options['limit']; $model = $options['model']; $this->checkAppExists($app); $this->standardBootstrap($app, $options['env']); if (sfConfig::get('sf_orm') != 'doctrine') { throw new LogicException('This feature is only implemented for Doctrine ORM'); } $start = microtime(true); $search = sfLucene::getInstance($index, $culture, is_null($model)); $search->optimize(); $this->setupEventDispatcher($search); $models = $search->getParameter('models')->getAll(); $factory = new sfLuceneIndexerFactory($search); $handler = null; foreach ($factory->getHandlers() as $handler) { if ($handler instanceof sfLuceneModelIndexerHandler) { break; } } if (!$handler instanceof sfLuceneModelIndexerHandler) { throw new LogicException('No sfLuceneModelIndexerHandler defined !'); } if ($model) { $this->update($handler, $app, $index, $culture, $model, $limit); } else { foreach ($models as $model => $params) { $this->update($handler, $app, $index, $culture, $model, $limit); } } $time = microtime(true) - $start; $final = $this->formatter->format('Update index done !!', array('fg' => 'green', 'bold' => true)); $final .= $this->formatter->format(number_format($time, 5), array('fg' => 'cyan')) . ' seconds.'; $this->dispatcher->notify(new sfEvent($this, 'command.log', array('', $final))); }
class Bar { } class sfLuceneActionIndexer { } $t = new limeade_test(14, limeade_output::get()); $limeade = new limeade_sf($t); $app = $limeade->bootstrap(); $luceneade = new limeade_lucene($limeade); $luceneade->configure()->clear_sandbox()->load_models(); $search = sfLucene::getInstance('testLucene'); $h = $search->getParameterHolder(); $t->diag('testing construct()'); try { $factory = new sfLuceneIndexerFactory($search); $t->pass('construct() accepts an instance of sfLucene'); } catch (Exception $e) { $t->fail('construct() accepts an instance of sfLucene'); } $t->diag('testing ->getHandlers()'); $handlers = $factory->getHandlers(); $t->is(array_keys($handlers), array('model', 'action'), '->getHandlers() returns instances of the model and action handler by default'); $t->ok($handlers['model'] == new sfLucenePropelIndexerHandler($search), '->getHandlers() returns a valid model handler'); $t->ok($handlers['action'] == new sfLuceneActionIndexerHandler($search), '->getHandlers() returns a valid action handler'); $h->get('factories')->set('indexers', array('action' => array('Foo', 'FooIndexer'))); $handlers = $factory->getHandlers(); $t->ok($handlers['action'] == new Foo($search), '->getHandlers() can overload built-in handlers'); $h->get('factories')->set('indexers', array('action' => null)); $t->is(array_keys($factory->getHandlers()), array('model'), '->getHandlers() can eliminate handlers'); $h->get('factories')->set('indexers', array('pdf' => array('Foo', 'FooIndexer')));