25
Intro to Drush July 13, 2012

Intro to Drush

Embed Size (px)

DESCRIPTION

A brief introduction to the Drush command line utility for Drupal. Learn how to use Drush to quickly build new Drupal sites, simplify the management of existing sites, and even integrate with other systems and IDEs.

Citation preview

Page 1: Intro to Drush

Intro to Drush

July 13, 2012

Page 2: Intro to Drush

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

Page 3: Intro to Drush

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

Page 4: Intro to Drush

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

Page 5: Intro to Drush

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

Page 6: Intro to Drush

Site Installation (normal)

Open browser Visit drupal.org Download Drupal Decompress Run install.php from browser Choose install profile Configure site/database

Page 7: Intro to Drush

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

Page 8: Intro to Drush

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

Page 9: Intro to Drush

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

Page 10: Intro to Drush

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

Page 11: Intro to Drush

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)

Page 12: Intro to Drush

What About Themes?

Themes and other projects are downloaded the exact same way

Naturally, themes appear in sites/default/themes

Page 13: Intro to Drush

Module Management (normal)

Visit the module page Scroll through a (usually very) long list Select the module and confirm Confirm dependencies

Page 14: Intro to Drush

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

Page 15: Intro to Drush

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

Page 16: Intro to Drush

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

Page 17: Intro to Drush

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

Page 18: Intro to Drush

Features Integration

drush fr <feature_name> Reverts a feature to code

drush fra Reverts all features at once

Page 19: Intro to Drush

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

Page 20: Intro to Drush

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

Page 21: Intro to Drush

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.

Page 22: Intro to Drush

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”

Page 23: Intro to Drush

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

Page 24: Intro to Drush

Questions?

Page 25: Intro to Drush

Get in Touch!

d.o – davidwatson e – [email protected] t - @caughtexception in – linkedin.com/in/davidmwatson