Book Image

Drush User's Guide

By : Juan Pablo Novillo Requena
Book Image

Drush User's Guide

By: Juan Pablo Novillo Requena

Overview of this book

<p>Drush is a command line interface for Drupal. Most of the tasks for building and maintaining a website are repetitive and involve filling in forms on administration pages. The majority of these tasks can be achieved with a single Drush command, shortening the development and maintenance time of a project drastically.</p> <p><em>Drush User's Guide</em> will allow you to be more productive and efficient in building and maintaining your Drupal sites through the command line. You will learn to install Drush on different platforms, and manage and configure your Drupal site by learning how to use and create Drush commands.</p> <p>Become a Drush expert by exploring its command toolkit; customizing it to suit your needs, and extending it with contributed modules.</p> <p>The command line will allow you to download, enable and upgrade Drupal projects in seconds. Back up your files, code and data in one single file, clear the cache, interact with databases, and deploy sites to remote machines - all using simply the command line. Use Drush with your own commands or alter existing ones; and extend the toolkit with a long list of contributed modules.</p> <p><em>Drush User's Guide</em> has everything you need to extend your use of the command line to easily build and manage your Drupal sites.</p>
Table of Contents (10 chapters)

Writing a custom command


So far you have seen most of the Drush command toolkit. Now it is time for us to think about how Drush can help us accomplish tasks that cannot be done with a few commands. Hence, it is time to write our own Drush command.

Here are some examples where you should choose to write a Drush command:

  • To run a periodic task that needs to be completely isolated because it can take a long time to complete and therefore cannot be executed through Cron

  • To extend the capabilities of an existing command in order to perform extra tasks needed in the production environments of your websites

  • To perform a task without a graphic interface, such as the content generator command of the Devel module

Drush commands follow a syntax very similar to Drupal. They are defined within a hook as an array of properties and a callback function does the processing. They also have hooks before, during, and after their execution. These will be explained in the next section.

Commands in Drush have the...