function data_search_search in Data 8
Same name and namespace in other branches
- 6 data_search/data_search.module \data_search_search()
- 7 data_search/data_search.module \data_search_search()
Implements hook_search().
File
- data_search/
data_search.module, line 112
Code
function data_search_search($op = 'search', $keys = NULL) {
$connection = \Drupal::database();
switch ($op) {
case 'name':
return t('Data');
case 'reset':
$tables = data_search_get_tables();
foreach ($tables as $table) {
$name = $table
->get('name');
$connection
->update('search_dataset')
->fields(array(
'reindex' => Drupal::time()
->getRequestTime(),
))
->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 + $connection
->query("SELECT COUNT(*) FROM {{$name}}")
->fetchField();
// TODO Please convert this statement to the D7 database API syntax.
$remaining = $remaining + $connection
->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,
);
}
}