Intro to Drush
July 13, 2012
David Watson Rensselaer Polytechnic Institute
Web Developer Experimental Media and Performing Arts Center (EMPAC)
Adjunct Professor Web Systems Development
Drupal Consultant ~3 years in the community Specialized Generalist
Development Problems Speed of performing tasks
Site Installation Module Management Site Administration Feature Management Creating Test Content
Ability to script tasks from the shell Shell scripts Integration with other systems/IDEs
Solution? Drush!
Drupal Shell Command line utility intended for *nix-based
environments Limited Windows support via cygwin
Exposes common Drupal tasks via the command line
Allows other modules to provide commands Devel Features
Drush Installation
Drush is not like most other projects! Collection of local scripts, not a module you
install on a site Up-to-date installation info can be found on the
drush project page drupal.org/project/drush
Site Installation (normal)
Open browser Visit drupal.org Download Drupal Decompress Run install.php from browser Choose install profile Configure site/database
Drupal Download (drush)
cd /path/to/destination/dir drush dl
Downloads the latest Drupal version when called with no arguments
Can also be used to download projects
Quick Note...
Most other commands that operate on a site must be run from within that site's root directory
Running the command within a subdirectory is also acceptable, though supplied paths are generally relative to the Drupal root, not the working directory
Site Installation (drush)
drush si [install_profile] Installs Drupal from scratch, flushing the
database first Optionally accepts the machine name of an
install profile Can supply database information via --db-url
flag if necessary
Adding a Module (normal)
Open the browser Visit module page on drupal.org Download the correct module version Decompress the module Move it into the appropriate directory
Adding a Module (drush)
drush dl [module_name] Downloads a module with the given project
shortname (the last part of the URL when you visit the project page)
The latest and most stable will be retrieved by default, use --select to be prompted to choose
Modules are downloaded to sites/default/files, use --destination=path/to/dest to specify (relative to Drupal root)
What About Themes?
Themes and other projects are downloaded the exact same way
Naturally, themes appear in sites/default/themes
Module Management (normal)
Visit the module page Scroll through a (usually very) long list Select the module and confirm Confirm dependencies
Module Management (drush)
drush en <module_name> Enables the module
drush dis <module_name> Disables the module
drush pm-uninstall <module_name> Uninstalls a disabled module completely
Module Management (drush)
drush up [module_names] Checks for module updates Automatically runs update.php Will even update Drupal core minor releases
if out of date! drush pmi <module_name>
Retrieve more information than you could possibly need about a module
Administrative Tasks
drush sql-dump --result-file=path/to/dest.sql Generate a SQL dump of the entire site
drush uli <username> Provides a one-time login link for a user
drush upwd <username> Set the password for a user
drush u[u]blk <username> (un)blocks a given user
Features Integration
drush fl Lists all features and their status
drush fd <feature_name> Takes the diff between features exports in
code and database Requires diff module
Features Integration
drush fr <feature_name> Reverts a feature to code
drush fra Reverts all features at once
Features Integration
drush fu <feature_name> Updates a feature's code from the current
database information, re-exporting it in place drush fe <feature_name>
[component_name, ...] Exports a series of components to a new or
existing feature Adding to an existing feature is “drush fa”
before drush 5.x
Devel Integration
drush fnv <function> Display source of a function
drush hook <hook_name> List all hook implementations for examination The hook name should be without the
“hook_” prefix
Devel Integration
drush genc <nodes> <comments> Generate a set number of nodes and
comments --types=types specifies which content types
to use Similar command exist for users, taxonomy,
etc.
All UI? Never Again!
drush si -y empac_cms drush dl feeds drush en -y feeds # UI – oops; broke something! drush fra # UI – hack hack hack drush fe empac_cms_events feeds:events bzr commit -m “Added Feeds Importer”
This is just the start!
drush help [command] Provides detailed help for a given command Command list and summary given with no
arguments Other advanced features exist as well Other modules may provide additional drush
integration
Questions?
Get in Touch!
d.o – davidwatson e – [email protected] t - @caughtexception in – linkedin.com/in/davidmwatson