Skip to content

Instantly share code, notes, and snippets.

@ranelpadon
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ranelpadon/8e991a8eb044098de66b to your computer and use it in GitHub Desktop.
Save ranelpadon/8e991a8eb044098de66b to your computer and use it in GitHub Desktop.
Custom Drush Commands Demo. Rename the file as toolkit.drush.inc ($ mv toolkit.drush.inc.php toolkit.drush.inc). Make it executable ($ sudo chmod a+x toolkit.drush.inc). Put this file in ~/.drush folder so that you will have now a ~/.drush/toolkit.drush.inc file.
<?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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment