22
* An event-driven way to index models related to a specific event
23
* @param sfEvent $event A symfony event
22
24
* @param boolean $reset by default is 0, meaning the entire index is rewritten.
23
* @todo maybe refactor to do all this stuff by reference? -UA
25
26
public static function indexAll(sfEvent $event = null, $reset = 0)
27
28
if (isset($event)) {
40
self::indexModels($models, $context, $reset);
44
* Reindexes models passed in the $models array
45
* @param array $models An array of models to reindex
46
* @param sfContext $context The sfContext instance to use
47
* @param boolean $reset by default is 0, meaning the entire index is rewritten.
48
* @todo maybe refactor to do all this stuff by reference? -UA
50
public static function indexModels(array $models, sfContext $context = NULL, $reset = 0)
52
ignore_user_abort(true);
55
if (is_null($context)) {
56
$context = sfContext::getInstance();
39
59
$dispatcher = $context->getEventDispatcher();
40
60
$task = new luceneReindexTask($dispatcher, new sfFormatter());
42
// "Tricks" plugin into thinking we're in a project directory
43
62
$oldDir = getcwd();
44
chdir(sfConfig::get('sf_root_dir'));
47
foreach ($models as $indexModel) {
64
// "Tricks" plugin into thinking we're in a project directory
65
chdir(sfConfig::get('sf_root_dir'));
67
foreach ($models as $indexModel) {
69
array('model' => $indexModel),
73
'connection' => 'doctrine',
74
'application' => 'frontend'
49
array('model' => $indexModel),
53
'connection' => 'doctrine',
54
'application' => 'frontend'
84
'connection' => 'doctrine',
85
'application' => 'frontend'
64
'connection' => 'doctrine',
65
'application' => 'frontend'
89
} catch(Exception $e) {
90
$this->sfContext->getLogger()->warning("Failed execute reindex task: \n" . $e->getMessage());
70
93
// restores context