~fabiocbalbuquerque/sahana-agasti/web-services

« back to all changes in this revision

Viewing changes to apps/frontend/lib/util/agLuceneIndex.class.php

  • Committer: Fabio Albuquerque
  • Date: 2011-08-08 22:10:34 UTC
  • mfrom: (1.26.1 push-trunk)
  • Revision ID: fabiocbalbuquerque@gmail.com-20110808221034-vfr4ggsbxsdllq82
Merges from CUNY SPS

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
{
20
20
 
21
21
  /**
 
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
24
 
   */
 
25
  */
25
26
  public static function indexAll(sfEvent $event = null, $reset = 0)
26
27
  {
27
28
    if (isset($event)) {
36
37
      return;
37
38
    }
38
39
 
 
40
    self::indexModels($models, $context, $reset);
 
41
  }
 
42
 
 
43
  /**
 
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
 
49
   */
 
50
  public static function indexModels(array $models, sfContext $context = NULL, $reset = 0)
 
51
  {
 
52
    ignore_user_abort(true);
 
53
    set_time_limit(0);
 
54
 
 
55
    if (is_null($context)) {
 
56
      $context = sfContext::getInstance();
 
57
    }
 
58
 
39
59
    $dispatcher = $context->getEventDispatcher();
40
60
    $task = new luceneReindexTask($dispatcher, new sfFormatter());
41
61
 
42
 
    // "Tricks" plugin into thinking we're in a project directory
43
62
    $oldDir = getcwd();
44
 
    chdir(sfConfig::get('sf_root_dir'));
45
 
 
46
 
    if (isset($models)) {
47
 
      foreach ($models as $indexModel) {
 
63
    try {
 
64
      // "Tricks" plugin into thinking we're in a project directory
 
65
      chdir(sfConfig::get('sf_root_dir'));
 
66
      if (isset($models)) {
 
67
        foreach ($models as $indexModel) {
 
68
          $task->run(
 
69
              array('model' => $indexModel),
 
70
              array(
 
71
            'reset' => $reset,
 
72
            'env' => 'all',
 
73
            'connection' => 'doctrine',
 
74
            'application' => 'frontend'
 
75
              )
 
76
          );
 
77
        }
 
78
      } else {
48
79
        $task->run(
49
 
            array('model' => $indexModel),
 
80
            array(),
50
81
            array(
51
 
              'reset' => $reset,
52
 
              'env' => 'all',
53
 
              'connection' => 'doctrine',
54
 
              'application' => 'frontend'
 
82
          'reset' => $reset,
 
83
          'env' => 'all',
 
84
          'connection' => 'doctrine',
 
85
          'application' => 'frontend'
55
86
            )
56
87
        );
57
88
      }
58
 
    } else {
59
 
      $task->run(
60
 
          array(),
61
 
          array(
62
 
            'reset' => $reset,
63
 
            'env' => 'all',
64
 
            'connection' => 'doctrine',
65
 
            'application' => 'frontend'
66
 
          )
67
 
      );
 
89
    } catch(Exception $e) {
 
90
      $this->sfContext->getLogger()->warning("Failed execute reindex task: \n" . $e->getMessage());
68
91
    }
69
92
 
70
93
    // restores context