Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Some Helpful "Utility" Drush Commands

Parent Feed: 

Here at Redfin we've come up with a couple of helpful Drush commands that help us with our everyday workflows. The first shows a database string as a URI for Drush aliases, and the second reverts all views that are in an overridden state without any prompting or confirmation.

The power of Drush aliases really help you to easily sync database from your staging or production environments down to your local development environment. When creating a drush alias, it likes database connection strings in URI format, like mysql://username:password@server/database.

The first command in the script is "drush rdb" (or "drush redfin-db" for long). This will read the settings.php (works with Drupal 6 and 7) and spit out a URI-formatted version of the connection string. We automate the creation of our aliases so it's nice to be able to call this from drush inside a bash script which generates the full alias file.

The second command is "drush rvr" ("drush redfin-vr"). **DANGER, DANGER** Ok, now that I have your attention, this command will revert ALL views currently in a state of "Overridden" to code. We use this as part of a deployment script to sites where the Views UI is completely disabled and all the views are managed in code. This means that when you push up your new view code, it gets pulled into the site. It's also helpful for local development when you've just synced down new views code from your fellow developers. You can also use the regular "drush vr" command for this, but that command first prompts you as to which views you'd like to revert, and you have to choose all as an option, which appears as a different number each time, preventing its use in automated scripts (like git post-receive hooks).

The code is available as a Gist. Just put this file in your home's .drush folder as redfin.drush.inc and you'll be able to use these two commands as-is, or modify them to suit your own needs.

DOWNLOAD/VIEW CODE

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web