function similar_cron in Similar Entries 7
Same name and namespace in other branches
- 6.2 similar.module \similar_cron()
- 7.2 similar.module \similar_cron()
Implements hook_cron().
Checks if an index rebuild is needed as determined in Drupal variables. If the similar_index variable is not empty it will have an array of field names which were added on the last cron run. If field settings have changed since that last cron run then the old index will be deleted and a new one added that includes all the relevant fields in the table. This is because ideally we want a single index for multiple fields in a table.
1 call to similar_cron()
- similar_install in ./
similar.install - Implements hook_install().
File
- ./
similar.module, line 47 - Module that shows a block listing similar entries. NOTE: Uses MySQL's FULLTEXT indexing for MyISAM tables.
Code
function similar_cron() {
if (module_exists('field')) {
$indices = similar_get_indices();
// Get all text columns defined for fields in the database.
$data = array();
foreach (field_info_fields() as $field => $info) {
if ($info['type'] == 'text') {
$table = key($info['storage']['details']['sql'][FIELD_LOAD_CURRENT]);
$data[$table][] = $info['storage']['details']['sql'][FIELD_LOAD_CURRENT][$table]['value'];
}
}
// For each table check if the index needs to be reset.
foreach ($data as $table => $fields) {
_similar_add_index($table, $data[$table]);
}
}
}