function advanced_help_update_index in Advanced Help 6
Same name and namespace in other branches
- 5 advanced_help.module \advanced_help_update_index()
- 7 advanced_help.module \advanced_help_update_index()
Implements hook_update_index().
File
- ./
advanced_help.module, line 847 - 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'])) {
db_query("INSERT INTO {advanced_help_index} (module, topic, language) VALUES ('%s', '%s', '%s')", $module, $topic, $language->language);
$info['sid'] = db_last_insert_id('advanced_help_index', 'sid');
}
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(),
));
}