You are here

function fac_cron in Fast Autocomplete 7

Same name and namespace in other branches
  1. 8 fac.module \fac_cron()

Implements hook_cron().

If cleaning up the Fast Autocomplete files is activated the expired files are deleted.

File

./fac.module, line 221
This file contains the main functions of the Fast Autocomplete module.

Code

function fac_cron() {

  // Change the HMAC key. Defaults to once a week.
  if ($interval = variable_get('fac_change_hmac_key_interval', 60 * 60 * 24 * 7)) {
    $key_timestamp = variable_get('fac_hmac_key_timestamp', 0);
    if (time() > $key_timestamp + $interval) {
      variable_set('fac_hmac_key', drupal_random_key());
      variable_set('fac_hmac_key_timestamp', time());

      // Clean up files; the paths are no longer valid with the new key.
      fac_delete_json_files();
    }
  }
  if (variable_get('fac_bulk_generate_json_enabled', FALSE)) {
    if (time() > variable_get('fac_bulk_generate_json_next_run', 0)) {
      $queue = DrupalQueue::get('fac_bulk_generate_json');
      $size = variable_get('fac_bulk_generate_json_size', 2);
      $keys = _fac_create_search_array($size);
      $languages = language_list('enabled');
      $languages = $languages[1];
      foreach ($languages as $language) {
        foreach ($keys as $key) {
          $data = new stdClass();
          $data->language = $language->language;
          $data->key = $key;
          $queue
            ->createItem($data);
        }
      }
      variable_set('fac_bulk_generate_json_next_run', time() + 24 * 60 * 60);
    }
  }
  if (variable_get('fac_clean_up_files', TRUE)) {
    $expire_time = strtotime(variable_get('fac_files_expire_time', '-1 day'));
    fac_delete_json_files($expire_time);
  }
}