Author: Jonathan.Wage
Date: 2010-02-12 20:26:09 +0100 (Fri, 12 Feb 2010)
New Revision: 27964
Modified:
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalSearchPlugin/lib/task/sfSympalBuildSearchIndexTask.class.php
Log:
[1.4][sfSympalPlugin][1.0] Improving task for building search indexes
Modified:
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalSearchPlugin/lib/task/sfSympalBuildSearchIndexTask.class.php
===================================================================
---
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalSearchPlugin/lib/task/sfSympalBuildSearchIndexTask.class.php
2010-02-12 18:43:55 UTC (rev 27963)
+++
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalSearchPlugin/lib/task/sfSympalBuildSearchIndexTask.class.php
2010-02-12 19:26:09 UTC (rev 27964)
@@ -7,6 +7,7 @@
$this->addOptions(array(
new sfCommandOption('application', null,
sfCommandOption::PARAMETER_OPTIONAL, 'The application',
sfSympalToolkit::getDefaultApplication()),
new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED,
'The environment', 'dev'),
+ new sfCommandOption('all', null, sfCommandOption::PARAMETER_NONE, 'Index
all applications'),
));
$this->aliases = array();
@@ -15,9 +16,17 @@
$this->briefDescription = 'Build the Sympal search index';
$this->detailedDescription = <<<EOF
-The [symfony sympal:build-search-index|INFO] task builds the search index.
+The [symfony sympal:build-search-index|INFO] task builds the search index for
the first Sympal site found in the applications directory.
[./symfony sympal:build-search-index|INFO]
+
+You can optionally specify an option to build all sites:
+
+ [./symfony sympal:build-search-index --all|INFO]
+
+Or you can build the index for a specific site:
+
+ [./symfony sympal:build-search-index --application=another_site|INFO]
EOF;
}
@@ -28,16 +37,39 @@
{
$this->createContext($this->configuration);
- $search = sfSympalSearch::getInstance();
- $models = sfSympalConfig::getSearchableModels();
- foreach ($models as $model)
+ if ($this->configuration instanceof sfApplicationConfiguration &&
!$options['all'])
{
- $records = Doctrine_Core::getTable($model)->findAll();
- foreach ($records as $record)
+ $this->sites = Doctrine_Core::getTable('sfSympalSite')
+ ->createQuery('s')
+ ->where('s.slug = ?', sfConfig::get('sf_app'))
+ ->execute();
+ } else {
+ $this->sites = Doctrine_Core::getTable('sfSympalSite')
+ ->createQuery('s')
+ ->execute();
+ }
+
+ foreach ($this->sites as $site)
+ {
+ if (!$this->configuration instanceof sfApplicationConfiguration ||
$options['all'])
{
- $this->logSection('sympal', sprintf('Updating index for %s #%s (%s)',
$model, $record->getId(), (string) $record));
- $search->updateSearchIndex($record);
+ $this->configuration = $this->createConfiguration($site->slug,
$options['env']);
+ $this->createContext($this->configuration);
}
+
+ $this->logSection('sympal', sprintf('Indexing models for site "%s"',
sfConfig::get('sf_app')));
+ $search = sfSympalSearch::getInstance();
+ $models = sfSympalConfig::getSearchableModels();
+ foreach ($models as $model)
+ {
+ $records = Doctrine_Core::getTable($model)->findAll();
+ $this->logBlock(sprintf('Indexing "%s"', $model), 'INFO');
+ foreach ($records as $record)
+ {
+ $this->logBlock(sprintf('...%s (%s)', $record->getId(), (string)
$record), 'COMMENT');
+ $search->updateSearchIndex($record);
+ }
+ }
}
}
}
\ No newline at end of file
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.