protected function execute($arguments = array(), $options = array())
 {
     $this->standardBootstrap($arguments['application'], $options['env']);
     $remove = sfLuceneToolkit::getDirtyIndexRemains();
     if (count($remove) == 0) {
         $this->dispatcher->notify(new sfEvent($this, 'command.log', array($this->formatter->format('Nothing to do!', 'INFO'))));
     } elseif ($arguments['confirmation'] == 'delete') {
         $this->dispatcher->notify(new sfEvent($this, 'command.log', array($this->formatter->format('Delete confirmation provided.  Deleting directories now...', array('fg' => 'red', 'bold' => true)))));
         foreach ($remove as $dir) {
             sfToolkit::clearDirectory($dir);
             rmdir($dir);
             $this->dispatcher->notify(new sfEvent($this, 'command.log', array($this->formatter->formatSection('dir-', $dir))));
         }
     } else {
         $messages = array($this->formatter->format('The following directories are alien and not referenced by your configuration:', 'INFO'));
         for ($c = count($remove), $x = 0; $x < $c; $x++) {
             $messages[] = '  ' . ($x + 1) . ') ' . $remove[$x];
         }
         $messages[] = '';
         $messages[] = 'These directories were ' . $this->formatter->format('not', array('fg' => 'red', 'bold' => true)) . ' deleted.  To delete these directories, please run:';
         $messages[] = '';
         $messages[] = '     ' . $this->formatter->format('symfony lucene:clean ' . $arguments['application'] . ' delete', 'INFO');
         $messages[] = '';
         $this->dispatcher->notify(new sfEvent($this, 'command.log', $messages));
     }
 }
<?php

/*
 * This file is part of the sfLucenePlugin package
 * (c) 2007 - 2008 Carl Vondrick <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
sfLuceneToolkit::loadZend();
/**
 * symfony adapter for Zend_Search_Lucene_Storage_File_Filesystem
 * @package sfLucenePlugin
 * @subpackage Addon
 * @version SVN: $Id: sfLuceneFileStorage.class.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $
 */
class sfLuceneFileStorage extends Zend_Search_Lucene_Storage_File_Filesystem
{
    public function __construct($filename, $mode = 'r+b')
    {
        parent::__construct($filename, $mode);
        sfLuceneStorageFilesystem::chmod($filename, 0777);
    }
}
 /**
  * Returns an instance of sfLucene configured for this environment.
  */
 protected function getLuceneInstance()
 {
     return sfLuceneToolkit::getApplicationInstance();
 }
 public function __construct(sfLucene $search)
 {
     sfLuceneToolkit::loadZend();
     $this->query = new Zend_Search_Lucene_Search_Query_Boolean();
     $this->search = $search;
 }
 /**
  * Zend Search Lucene makes it awfully hard to have multiple Lucene indexes
  * open at the same time. This method combats that by configuring all the
  * static variables for this instance.
  */
 public function configure()
 {
     sfLuceneToolkit::loadZend();
     $this->getEventDispatcher()->notify(new sfEvent($this, 'lucene.configure.pre'));
     Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding($this->getParameter('encoding'));
     switch (strtolower($this->getParameter('analyzer'))) {
         default:
             throw new sfLuceneException('Unknown analyzer: ' . $this->getParameter('analzyer'));
         case 'text':
             $analyzer = new Zend_Search_Lucene_Analysis_Analyzer_Common_Text();
             break;
         case 'textnum':
             $analyzer = new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum();
             break;
         case 'utf8':
         case 'utf-8':
             $analyzer = new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8();
             break;
         case 'utf8num':
         case 'utf-8num':
             $analyzer = new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num();
             break;
     }
     if (!$this->getParameter('case_sensitive', false)) {
         $analyzer->addFilter(new sfLuceneLowerCaseFilter($this->getParameter('mb_string', false)));
     }
     if (count($this->getParameter('stop_words'))) {
         $analyzer->addFilter(new Zend_Search_Lucene_Analysis_TokenFilter_StopWords($this->getParameter('stop_words')));
     }
     if ($this->getParameter('short_words') > 0) {
         $analyzer->addFilter(new Zend_Search_Lucene_Analysis_TokenFilter_ShortWords($this->getParameter('short_words')));
     }
     Zend_Search_Lucene_Analysis_Analyzer::setDefault($analyzer);
     $this->getEventDispatcher()->notify(new sfEvent($this, 'lucene.configure.post'));
 }
$root = sfConfig::get('sf_data_dir') . '/index/';
// build valid indexes structure
sfLucene::getInstance('testLucene', 'en')->getLucene();
sfLucene::getInstance('testLucene', 'fr')->getLucene();
// build invalid indexes structures
file_put_contents($root . 'testLucene/en/random_file', 'r@nd()');
mkdir($root . 'testLucene/foo', 0777, true);
file_put_contents($root . 'testLucene/foo/bar', 'foo');
mkdir($root . 'badIndex/en', 0777, true);
file_put_contents($root . 'badIndex/bar', 'foo');
$dirty = sfLuceneToolkit::getDirtyIndexRemains();
$t->ok(in_array($root . 'testLucene/foo', $dirty), '::getDirtyIndexRemains() schedules valid indexes but invalid cultures for deletion');
$t->ok(in_array($root . 'badIndex', $dirty), '::getDirtyIndexRemains() schedules the entire of a bad index for deletion');
$t->ok(!in_array($root . 'testLucene', $dirty), '::getDirtyIndexRemains() did not schedule an entire valid index for deletion');
$t->ok(!in_array($root . 'testLucene/en', $dirty), '::getDirtyIndexRemains() did not schedule a valid index and valid culture for deletion');
$t->ok(!in_array($root . 'testLucene/fr', $dirty), '::getDirtyIndexRemains() did not schedule another valid index and valid culture for deletion');
$t->ok(!in_array($root . 'testLucene/en/random_file', $dirty), '::getDirtyIndexRemains() did not schedule an alien file in a valid index and valid culture for deletion');
$t->diag('testing ::getApplicationInstance');
$t->ok(sfLuceneToolkit::getApplicationInstance('en') === sfLucene::getInstance('testLucene', 'en'), '::getApplicationInstance() guesses the first index with no configuration parameter set');
sfConfig::set('app_lucene_index', 'fooLucene');
$t->ok(sfLuceneToolkit::getApplicationInstance('en') === sfLucene::getInstance('fooLucene', 'en'), '::getApplicationInstance() acknowledges manual override from app.yml');
$limeade->config()->remove('app_lucene_index');
$cswap = $app->cswap($luceneade->config_dir . '/search.yml')->write('<?php $config = array();');
try {
    $e = $t->exception('::getApplicationInstance() fails if search.yml is empty');
    sfLuceneToolkit::getApplicationInstance();
    $e->no();
} catch (Exception $ex) {
    $e->caught($ex);
}
$cswap->restore();