Skip to content

Instantly share code, notes, and snippets.

@greylabel
Created June 9, 2015 17:12
Show Gist options
  • Save greylabel/883a6a545a920340ee0f to your computer and use it in GitHub Desktop.
Save greylabel/883a6a545a920340ee0f to your computer and use it in GitHub Desktop.
Provides a drush command to trim specific number of expired items on cache_form table
<?php
/**
* @file
* Provides a drush command to trim specific number of expired items on cache_form table
*/
define("FORCE_FCT_DEFAULT_LIMIT", 1000);
/**
* Implements hook_drush_help().
*/
function force_fct_drush_help($command) {
switch ($command) {
case 'drush:force-fct':
return dt('Clears specified number of expired items from cache_form. Defaults to 1000 items.');
}
}
/**
* Implements hook_drush_command().
*/
function force_fct_drush_command() {
$items = array();
$items['ffct'] = array(
'description' => dt('Clear a given number of expired form_cache items'),
'arguments' => array(
'limit' => dt('Number of entries to delete'),
),
'examples' => array(
'Standard example' => 'drush force-fct',
'Argument example' => 'drush force-fct 2500',
),
);
return $items;
}
/**
* Callback function for the drush command
*/
function drush_force_fct_ffct($limit = FORCE_FCT_DEFAULT_LIMIT ) {
if (is_int($limit) && $limit > 1) {
db_query("DELETE FROM {cache_form} where expire <> " . CACHE_PERMANENT . " AND expire < " . time() . " ORDER BY expire DESC LIMIT " . $limit);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment