You are here

function search_files_attachments_update_index in Search Files 7.2

Same name and namespace in other branches
  1. 6.2 search_files_attachments.module \search_files_attachments_update_index()

Implements hook_update_index().

Parameters

$goto: (optional) drupal path - if this is called from the menu system we need to go back to $goto. If this is called from cron, cron has to go on.

1 string reference to 'search_files_attachments_update_index'
search_files_attachments_menu in ./search_files_attachments.module
Implements hook_menu().

File

./search_files_attachments.module, line 170
Used to index files in attachments

Code

function search_files_attachments_update_index($goto = FALSE) {
  variable_set('search_files_attachments_last_index', REQUEST_TIME);
  $public_file_dir = variable_get('file_public_path', 'sites/default/files');
  $limit = (int) variable_get('search_cron_limit', 100);

  // Select attached files related to search_files_att and marked to re-index.
  // UNION known files not yet related to 'search_files_att'.
  $field_id_list = _search_files_attachments_create_field_id_list();
  if (count($field_id_list) > 0) {
    $query_file = "\n      SELECT f.fid, f.uri AS filepath, f.filename, d.reindex FROM {file_managed} f\n      LEFT JOIN {search_dataset} d ON d.sid = f.fid\n      WHERE (f.fid in (:fid)\n      AND d.type = 'search_files_att'\n      AND (d.reindex != 0 OR d.reindex IS NULL))\n      UNION DISTINCT\n      SELECT f.fid, f.uri AS filepath, f.filename , NULL FROM {file_managed} f\n      WHERE f.fid NOT IN (\n        SELECT sid FROM {search_dataset} d\n        WHERE d.type = 'search_files_att'\n      )\n      ORDER BY reindex ASC, fid";
    $query_result = db_query_range($query_file, 0, $limit, array(
      ':fid' => $field_id_list,
    ));
    $found = $count = 0;
    foreach ($query_result as $file) {
      $found++;
      if (search_files_attachments_index_file($file)) {
        $count++;
      }
    }
  }

  // if we were called manually from dashboard, return to where we come from
  if ($goto) {
    search_files_update_totals('search_files_att');
    drupal_goto($goto);
  }
}