You are here

function advanced_help_update_index in Advanced Help 7

Same name and namespace in other branches
  1. 5 advanced_help.module \advanced_help_update_index()
  2. 6 advanced_help.module \advanced_help_update_index()

Implements hook_update_index().

File

./advanced_help.module, line 1088
Pluggable system to provide advanced help facilities for Drupal and modules.

Code

function advanced_help_update_index() {
  global $language;

  // If we got interrupted by limit, this will contain the last module
  // and topic we looked at.
  $last = variable_get('advanced_help_last_cron', array(
    'time' => 0,
  ));
  $limit = intval(variable_get('search_cron_limit', 100));
  $topics = advanced_help_get_topics();
  advanced_help_get_sids($topics);
  $count = 0;
  foreach ($topics as $module => $module_topics) {

    // Fast forward if necessary.
    if (!empty($last['module']) && $last['module'] != $module) {
      continue;
    }
    foreach ($module_topics as $topic => $info) {

      // Fast forward if necessary.
      if (!empty($last['topic']) && $last['topic'] != $topic) {
        continue;
      }

      // If we've been looking to catch up, and we have, reset so we
      // stop fast forwarding.
      if (!empty($last['module'])) {
        unset($last['topic']);
        unset($last['module']);
      }
      $file = advanced_help_get_topic_filename($module, $topic);
      if ($file && (empty($info['sid']) || filemtime($file) > $last['time'])) {
        if (empty($info['sid'])) {
          $info['sid'] = db_insert('advanced_help_index')
            ->fields(array(
            'module' => $module,
            'topic' => $topic,
            'language' => $language->language,
          ))
            ->execute();
        }
        search_index($info['sid'], 'help', '<h1>' . $info['title'] . '</h1>' . file_get_contents($file));
        $count++;
        if ($count >= $limit) {
          $last['topic'] = $topic;
          $last['module'] = $module;

          // Don't change time if we stop.
          variable_set('advanced_help_last_cron', $last);
          return;
        }
      }
    }
  }
  variable_set('advanced_help_last_cron', array(
    'time' => time(),
  ));
}