You are here

function similar_cron in Similar Entries 6.2

Same name and namespace in other branches
  1. 7.2 similar.module \similar_cron()
  2. 7 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.

@TODO: Ensure that the index sticks with the field when CCK fields are edited. If not, we may have to implement hook_content_fieldapi()'s update operations to reset the index.

2 calls to similar_cron()
similar_install in ./similar.install
Implements hook_install().
similar_reset_indices in ./similar.module
Resets all Similar Entries indexes.

File

./similar.module, line 56
Module that shows a block listing similar entries. NOTE: Uses MySQL's FULLTEXT indexing for MyISAM tables.

Code

function similar_cron() {
  if (module_exists('content')) {
    $indices = similar_get_indices();
    $data = array();

    // Get all columns for each field.
    foreach (content_fields() as $field) {
      if ($field['type'] == 'text') {
        $info = content_database_info($field);
        foreach ($info['columns'] as $column) {
          $data[$info['table']][$column['column']] = $column['column'];
        }
      }
    }

    // Check and reindex each table for each content type if necessary.
    foreach ($data as $table => $columns) {
      foreach ($columns as $column) {
        _similar_add_index($table, $column);
      }
    }
  }
}