You are here

expire.drush.inc in Cache Expiration 7.2

Same filename and directory in other branches
  1. 6 expire.drush.inc
  2. 7 expire.drush.inc

This is the drush integration for the expire module.

File

expire.drush.inc
View source
<?php

/**
 * @file
 * This is the drush integration for the expire module.
 */

/**
 * Implements hook_drush_command().
 */
function expire_drush_command() {

  // Expire absolute URLs.
  $items['expire-url'] = array(
    'description' => 'Expire fully qualified URLs.',
    'arguments' => array(
      'urls' => 'URLs to expire separated by spaces.',
    ),
    'examples' => array(
      'drush expire-url http://example.com/testpage.html' => 'Expire a single URL.',
      'drush xp-url http://example.com/ http://test.com/logo.jpg' => 'Expire multiple URLs.',
    ),
    'aliases' => array(
      'xp-url',
    ),
    'drupal dependencies' => array(
      'expire',
    ),
    'callback' => 'drush_expire_absolute_url',
  );

  // Expire internal paths.
  $items['expire-path'] = array(
    'description' => 'Expire a drupal path.',
    'arguments' => array(
      'paths' => 'A list drupal paths to expire separated by spaces.',
    ),
    'examples' => array(
      'drush expire-path node/123' => 'Expire a single drupal path.',
      'drush expire-path FRONT' => 'Expire the front page.',
      'drush xp-path FRONT node/234 contact' => 'Expire multiple drupal paths.',
    ),
    'aliases' => array(
      'xp-path',
    ),
    'drupal dependencies' => array(
      'expire',
    ),
    'callback' => 'drush_expire_internal_path',
  );

  // Expire node objects.
  $items['expire-node'] = array(
    'description' => 'Expire a node by node ID.',
    'arguments' => array(
      'nids' => 'Numeric node-ids to expire separated by spaces.',
    ),
    'examples' => array(
      'drush expire-node 2' => 'Expire single node by node ID.',
      'drush xp-node 2 24 612' => 'Expire multiple nodes by node IDs.',
    ),
    'aliases' => array(
      'xp-node',
    ),
    'drupal dependencies' => array(
      'expire',
    ),
    'callback' => 'drush_expire_node',
  );

  // Expire taxonomy term objects.
  $items['expire-term'] = array(
    'description' => 'Expire a taxonomy term by term ID.',
    'arguments' => array(
      'tids' => 'Numeric term ids to expire separated by spaces.',
    ),
    'examples' => array(
      'drush expire-term 2' => 'Expire single taxonomy term by term ID.',
      'drush xp-term 2 24 612' => 'Expire multiple taxonomy terms by term IDs.',
    ),
    'aliases' => array(
      'xp-term',
    ),
    'drupal dependencies' => array(
      'expire',
    ),
    'callback' => 'drush_expire_term',
  );

  // Expire user objects.
  $items['expire-user'] = array(
    'description' => 'Expire a user by user ID.',
    'arguments' => array(
      'uids' => 'Numeric user IDs to expire separated by spaces.',
    ),
    'examples' => array(
      'drush expire-user 2' => 'Expire single user by his ID.',
      'drush xp-user 2 24 612' => 'Expire multiple users by their IDs.',
    ),
    'aliases' => array(
      'xp-user',
    ),
    'drupal dependencies' => array(
      'expire',
    ),
    'callback' => 'drush_expire_user',
  );

  // Expire comment objects.
  $items['expire-comment'] = array(
    'description' => 'Expire a comment by comment ID.',
    'arguments' => array(
      'cids' => 'Numeric comment IDs to expire separated by spaces.',
    ),
    'examples' => array(
      'drush expire-comment 2' => 'Expire single comment by its ID.',
      'drush xp-comment 2 24 612' => 'Expire multiple comments by their IDs.',
    ),
    'aliases' => array(
      'xp-comment',
    ),
    'drupal dependencies' => array(
      'expire',
      'comment',
    ),
    'callback' => 'drush_expire_comment',
  );
  return $items;
}

/**
 * Callback for expire-url drush command.
 */
function drush_expire_absolute_url() {

  // Get drush params.
  $absolute_urls = drush_get_arguments();
  unset($absolute_urls[0]);

  // Expire urls.
  ExpireAPI::executeExpiration($absolute_urls, '', NULL, TRUE);
}

/**
 * Callback for expire-path drush command.
 */
function drush_expire_internal_path() {

  // Get drush params.
  $paths = drush_get_arguments();
  unset($paths[0]);
  $internal_paths = array();
  foreach ($paths as &$path) {
    if ($path === 'FRONT') {
      $internal_paths += ExpireAPI::getFrontPageUrls();
    }
    else {
      $internal_paths[] = $path;
    }
  }

  // Expire internal paths.
  ExpireAPI::executeExpiration($internal_paths);
}

/**
 * Callback for expire-node drush command.
 */
function drush_expire_node() {
  _drush_expire_entity('node');
}

/**
 * Callback for expire-term drush command.
 */
function drush_expire_term() {
  _drush_expire_entity('taxonomy_term');
}

/**
 * Callback for expire-user drush command.
 */
function drush_expire_user() {
  _drush_expire_entity('user');
}

/**
 * Callback for expire-comment drush command.
 */
function drush_expire_comment() {
  _drush_expire_entity('comment');
}

/**
 * Internal function for expiration of all entities.
 */
function _drush_expire_entity($entity_type) {

  // Get drush params.
  $ids = drush_get_arguments();
  unset($ids[0]);
  $handler = _expire_get_expiration_handler($entity_type);
  $entities = entity_load($entity_type, $ids);
  if (is_object($handler) && !empty($entities)) {
    foreach ($entities as $entity) {
      $handler
        ->expire($entity, 0, $skip_action_check = TRUE);
    }
  }
}

Functions

Namesort descending Description
drush_expire_absolute_url Callback for expire-url drush command.
drush_expire_comment Callback for expire-comment drush command.
drush_expire_internal_path Callback for expire-path drush command.
drush_expire_node Callback for expire-node drush command.
drush_expire_term Callback for expire-term drush command.
drush_expire_user Callback for expire-user drush command.
expire_drush_command Implements hook_drush_command().
_drush_expire_entity Internal function for expiration of all entities.