firstval
1/3/2015 - 1:08 PM

toolkit.drush.inc.php

<?php

/**
 * Implements COMMANDFILE_drush_command().
 */
function toolkit_drush_command() {
  $items = array();

  // Command for Clear Cache All.
  // The 'cca' array key is what you type in the terminal, like: drush cca.
  // This will be a shortcut for drush cc all.
  $items['cca'] = array(
    'description' => "Clear all cached data. Similar to hitting the 'Clear cache' button in Drupal.",
    'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
  );

  // Command for Node Load.
  $items['nl'] = array(
    'description' => "Load a node given its node ID.",
    'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
  );

  return $items;
}

/**
 * Implements drush_COMMANDFILE_COMMANDNAME.
 *
 * Purpose: Clear Drupal's entire cache.
 * Syntax: drush cca
 * Related Command: drush cc all.
 */
function drush_toolkit_cca() {
  // Call the Drupal API's function for clearing the site's cache.
  drupal_flush_all_caches();

  // Display some notifications in the terminal.
  drush_print("All caches have been cleared! Ready for more action!");
}

/**
 * Implements drush_COMMANDFILE_COMMANDNAME.
 *
 * Purpose: Load a node to view/analyze its properties/values.
 * Syntax: drush nl NODE_ID
 * Related Command: drush php-eval 'var_export(node_load(NODE_ID));'
 */
function drush_toolkit_nl($nid) {
  // Call the Drupal API's function for loading a node.
  $node_object = node_load($nid);

  // Display the object's attributes in terminal.
  // drush_print(var_export($node_object) is redundant.
  // drush_print($node_object) will not work since drush_print is for simple texts only.
  var_export($node_object);
}