You are here

function data_search_search in Data 7

Same name and namespace in other branches
  1. 8 data_search/data_search.module \data_search_search()
  2. 6 data_search/data_search.module \data_search_search()

Implements hook_search().

File

data_search/data_search.module, line 108

Code

function data_search_search($op = 'search', $keys = NULL) {
  switch ($op) {
    case 'name':
      return t('Data');
    case 'reset':
      $tables = data_search_get_tables();
      foreach ($tables as $table) {
        $name = $table
          ->get('name');
        db_update('search_dataset')
          ->fields(array(
          'reindex' => REQUEST_TIME,
        ))
          ->condition('type', $name)
          ->execute();
      }
      return;
    case 'status':
      $total = $remaining = 0;
      $tables = data_search_get_tables();
      foreach ($tables as $table) {
        $name = $table
          ->get('name');
        $schema = $table
          ->get('table_schema');
        $base_field = current($schema['primary key']);

        // TODO Please convert this statement to the D7 database API syntax.
        $total = $total + db_query("SELECT COUNT(*) FROM {{$name}}")
          ->fetchField();

        // TODO Please convert this statement to the D7 database API syntax.
        $remaining = $remaining + db_query("SELECT COUNT(*) FROM {{$name}} dt LEFT JOIN {search_dataset} d ON d.type = '{$name}' AND d.sid = dt.{$base_field} WHERE (d.sid IS NULL OR d.reindex <> 0)")
          ->fetchField();
      }
      return array(
        'remaining' => $remaining,
        'total' => $total,
      );
  }
}