You are here

function _optimizedb_clear_cache_form_table in OptimizeDB 7

Cleaning table cache_form and cleaning time record.

Parameters

mixed $type:

5 calls to _optimizedb_clear_cache_form_table()
drush_optimizedb_cleaning in includes/optimizedb.drush.inc
Cleaning table cache_form.
OptimizedbFunctionsTestCase::testClearTable in ./optimizedb.test
Test _optimizedb_clear_cache_form_table() function.
optimizedb_admin_clear_table_all_submit in ./optimizedb.module
Form submission handler for optimizedb_admin().
optimizedb_admin_clear_table_submit in ./optimizedb.module
Form submission handler for optimizedb_admin().
optimizedb_cron in ./optimizedb.module
Implements hook_cron().

File

./optimizedb.module, line 820
Database Optimization.

Code

function _optimizedb_clear_cache_form_table($type = NULL) {
  if (is_null($type)) {
    $type = variable_get('optimizedb_clear_type', 0);
  }
  if ((int) $type === 1) {
    db_truncate('cache_form')
      ->execute();
  }
  else {
    $count_all = (int) db_select('cache_form')
      ->countQuery()
      ->execute()
      ->fetchField();
    if ($count_all !== 0) {
      $count_expire = (int) db_select('cache_form')
        ->condition('expire', REQUEST_TIME, '<')
        ->countQuery()
        ->execute()
        ->fetchField();
      $limit = (int) variable_get('optimizedb_clear_limit', 0);
      $limit_status = $limit === 0 ? TRUE : $count_all <= $limit;
      if ($count_all === $count_expire && $limit_status) {
        db_truncate('cache_form')
          ->execute();
      }
      else {
        if ($limit > 0) {
          $query = db_select('cache_form', 'cf');
          $query
            ->fields('cf', array(
            'cid',
          ));
          $query
            ->condition('cf.expire', REQUEST_TIME, '<');
          $query
            ->orderBy('cf.expire', 'ASC');
          $query
            ->range(0, $limit);
          $ids = $query
            ->execute()
            ->fetchCol();
          if (!empty($ids)) {
            db_delete('cache_form')
              ->condition('cid', $ids, 'IN')
              ->execute();
          }
        }
        else {
          db_delete('cache_form')
            ->condition('expire', REQUEST_TIME, '<')
            ->execute();
        }
      }
    }
  }

  // Update size tables.
  _optimizedb_tables_list();
  variable_set('optimizedb_last_clear', REQUEST_TIME);
}