You are here

function cleaner_cleaner_run in Cleaner 5

Same name and namespace in other branches
  1. 8 cleaner.module \cleaner_cleaner_run()
  2. 6 cleaner.module \cleaner_cleaner_run()
  3. 7 cleaner.module \cleaner_cleaner_run()

Implementation of hook_cleaner_run().

File

./cleaner.module, line 150
Allows the admin to set a schedule for clearing caches and other stuff.

Code

function cleaner_cleaner_run() {
  if (variable_get('cleaner_clear_cache', FALSE)) {

    // Clear out the cache tables.
    $list = array();
    $result = db_query("SHOW TABLES LIKE 'cache\\_%'");
    while ($table = db_result($result)) {

      // Note that use of '*' means the entire table is cleared, not just expired entries.
      cache_clear_all('*', $table, TRUE);
      $list[] = drupal_substr($table, 6);
    }
    watchdog('Cleaner', t('Cleared caches. (@list)', array(
      '@list' => implode(', ', $list),
    )));
  }
  if (variable_get('cleaner_empty_watchdog', FALSE)) {

    // Clear out the watchdog table.
    db_query("TRUNCATE {watchdog}");
    watchdog('Cleaner', t('Cleared watchdog.'));
  }
  if (variable_get('cleaner_clean_sessions', FALSE)) {

    // Delete sessions that are more than two weeks old.
    db_query("DELETE FROM {sessions} WHERE timestamp < %d", $_SESSION['time'] - 14 * 24 * 60 * 60);
    $count = db_affected_rows();
    watchdog('Cleaner', t('Cleared @count sessions.', array(
      '@count' => $count,
    )));
  }
}