Upgrade Your Drupal Skills

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

See Advanced Courses NAH, I know Enough

Introducing Devit

Parent Feed: 
Devit Admin You have a live website and you need to copy a fresh version of the (live) database onto your local machine for development. Next, you need to run through one or more of these rote tasks:
  • Disable Drupal core caches (page cache, block cache, CSS & JS optimization, etc.)
  • Sanitize user data
  • Update Drupal's file system paths (public, private, tmp directories)
  • Enable email rerouting
  • Update logging and error level settings
  • Re-configure a contrib module. E.g., Secure Site (enable, set permissions, guest accounts).

Does this sound familiar? If so, I have good news! I've created a module that will help you automate that process.

Devit allows you to select or create tasks that should be run when your database needs to be deved. You can initiate these tasks via an administrative page, or via Drush.

Devit comes with a submodule that will provide you with the basic tasks, but it also provides an API that allows you to create your own tasks! Ideally, various contrib modules will be packaged with their own Devit tasks. For example:

  • Secure Site could have a Devit task that enables secure_site and sets default permissions, passwords, etc.
  • Advagg could have a task that disables all of its fancy features.
  • Features could have a task that performs a features revert and enables the Features UI module.

Choosing & executing Devit tasks

There are a few ways to choose and execute the selection devit tasks that you'd like to run.
  1. The devit_ui sub-module provides a user interface that allows administrators to choose and execute Devit tasks (image above).
  2. Your own, custom devit tasks can be defined with a default status of TRUE—these will run when your site is deved via Drush.
  3. A selection of Devit tasks can be defined in a devit.settings.php file. This option allows you to easily define a set of Devit tasks that are unique to your development environment. These settings will supersede the default status of your tasks, and the Devit configuration stored in your database. Must be executed via Drush.

This file must be placed in your site directory, e.g., /sites/default. It contains a simple, flat array keyed by task names:

TRUE, 'update-file-paths' => FALSE, ); ?>

Here's a quick example of deving your site via Drush!

$ drush devit
Please enter the new password for all users [password]: new_pass
Set files directory path [sites/files]: new_files_dir
Files directory path changed to new_files_dir.                                                                         [success]
Site ready for development! 

Defining your own tasks

Devit provides an API that works much like the Menu API. The hook_devit_tasks() function allows you to define your own Devit tasks, and gives you the familiar framework to specify details like title, description, task callback, user access callback, file includes, etc. Here's a quick example:
 t('Disable core caching features'),
    'description' => t('Disables page cache, page compression, block cache, and CSS & JS optimization.'),
    'task callback' => 'yourmodule_disable_caching',
    'access arguments' => 'administer site configuration',
  );

  return $tasks;
}

/**
 * Disables core caching.
 */
function yourmodule_disable_caching() {
  variable_set('cache', "0");
  variable_set('block_cache', "0");
  variable_set('preprocess_js', "0");
  variable_set('preprocess_css', "0");
  variable_set('page_compression', "0");
}
?>

Wrap Up

This module is still very much in development, but I'd like to gauge the level of interest in this tool. Would you use it? Do you have any ideas to contribute?

You could say things like:

  • "I want to help you!"
  • "Great idea, but you should consider..."
  • "Matt, this is a terrible idea because...".
  • "This module is like a beautiful snowflake."

Thanks!

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