O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Drush for Developers - Second Edition

Book Description

Effectively manage Drupal projects using Drush

In Detail

Drush for Developers, Second Edition, takes common challenges in Drupal projects and solves them using Drush. This book starts with the different installation approaches for Drush and its command structure. It then moves on to perhaps the trickiest challenge in Drupal projects: keeping code and configuration together during a project's lifetime. Next, we will deep dive into the tasks needed to keep a website under control and learn how to run, automate, and monitor them effectively.

Error validating and debugging our Drush commands is a must and this book has a whole chapter on that topic. The magic of managing remote Drupal projects through Drush site aliases is explained in the following chapters through a practical example. Finally, the book wraps up by putting in practice all the concepts covered in previous chapters in order to implement a development workflow for a team.

What You Will Learn

  • Update the database of a Drupal project to reflect changes in the codebase
  • Optimize, execute, and monitor periodic and one-off tasks
  • Browse through Drush and Drupal's hook implementations and functions
  • Implement a roll-back mechanism on your commands to handle errors
  • Define a group of site aliases to manage all the environments of your Drupal project
  • Create shell aliases and adjust the default behavior of frequent commands
  • Set up a development workflow for a team

Table of Contents

  1. Drush for Developers Second Edition
    1. Table of Contents
    2. Drush for Developers Second Edition
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Introduction, Installation, and Basic Usage
      1. Installation requirements
        1. Operating system
        2. PHP
        3. Installing Composer
        4. Drush installation on Linux and OSX
        5. Manual installation
      2. The Drush command structure
        1. Executing a command
        2. Providing arguments to a command
        3. Altering a command's behavior through options
        4. Structuring command invocations
        5. Command aliases
      3. Understanding Drush's context system
      4. Setting the context manually
      5. Summary
    9. 2. Keeping Database Configuration and Code Together
      1. Meeting the update path
        1. Rebuilding the registry
          1. Preparing the trap
          2. Breaking the registry
          3. Rebuilding Drupal's registry
        2. Running database updates
        3. Managing features
          1. Exporting configuration into code
        4. Running the update path on a different environment
        5. Analyzing results
          1. Reverting the feature components programmatically
      2. Summary
    10. 3. Running and Monitoring Tasks in Drupal Projects
      1. Running periodic tasks with cron
        1. Disabling Drupal's cron
          1. Verifying the current cron frequency
          2. Overriding cron frequency and exporting it to code
        2. Running cron with Drush
        3. Scheduling cron runs with Jenkins
          1. Installing Jenkins
        4. Creating a job through the web interface
        5. Monitoring cron runs
      2. Running a task outside cron
        1. Example – moving a Feeds importer from Drupal's cron to Drush
          1. Exporting the Feeds importer into code
          2. Writing a Drush command to trigger the Feeds importer
      3. Running long tasks in batches
        1. A sample Drush command using the Batch API
          1. Batch API operations
          2. Running the command and verifying the output
      4. Evaluating code on the fly and running scripts
        1. The php-eval command
        2. The php-script command
          1. A script to create nodes and revisions
      5. Logging messages in Drush
        1. The verbose and quiet modes
      6. Redirecting Drush output into a file
        1. Implementing your own logging mechanism
      7. Running a command in the background
      8. Summary
    11. 4. Error Handling and Debugging
      1. Validating input
        1. Validating an argument
        2. Validating options
          1. Ignoring options after the command name
          2. Allowing additional options
        3. Adding custom validation to a command
      2. Rolling back when an error happens
        1. Turning the update path into a single command
      3. Browsing hook implementations
      4. Inspecting the bootstrapping process
      5. Inspecting hook and function implementations
        1. Browsing and navigating hook implementations
        2. Viewing source code of a function or method
      6. Summary
    12. 5. Managing Local and Remote Environments
      1. Managing local environments
      2. Managing remote environments
        1. Verifying requirements
          1. Accessing a remote server through a public key
        2. Defining a group of remote site aliases for our project
        3. Using site aliases in commands
      3. Special site aliases
        1. Running a command on all site aliases of a group
        2. Avoiding a Drupal bootstrap with @none
        3. Referencing the current project with @self
      4. Adding site alias support to the update path
        1. Inspecting the command implementation and hooks
        2. Running the update path with a site alias
      5. Copying database and files between environments
        1. Defining Drush shell aliases for a team
        2. Blocking the execution of certain commands
        3. Ignoring tables on sql-sync
      6. Summary
    13. 6. Setting Up a Development Workflow
      1. Moving configuration, commands, and site aliases out of Drupal
        1. Installing Drupal Boilerplate
        2. Relocating Drush files
        3. Testing the new setup
      2. Configuring the development database for the team
        1. Configuring Jenkins to sync production to development
        2. Fine-tuning the development database
          1. Recreating the database on sql-sync
          2. Excluding table data from production
          3. Ignoring tables from production
          4. Sanitizing data
          5. Preventing e-mails from being sent
      3. Running post sql-sync tasks in local environments
      4. Summary
    14. Index