Introducing Devit
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.
- The devit_ui sub-module provides a user interface that allows administrators to choose and execute Devit tasks (image above).
- Your own, custom devit tasks can be defined with a default status of TRUE—these will run when your site is deved via Drush.
- 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:
// Set whether a task should be executed when Devit is run.
$tasks = array(
// Key rows by task name.
'clear-caches' => 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:
/**
* Implements hook_devit_tasks().
*/
function yourmodule_devit_tasks() {
$tasks = array();
$tasks['disable-caching'] = array(
'title' => 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!
7.x,
devify, drupal, development, drush