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:
<span style="color: #000000"><span style="color: #0000BB"><?php<br></span><span style="color: #FF8000">// Set whether a task should be executed when Devit is run.<br></span><span style="color: #0000BB">$tasks </span><span style="color: #007700">= array(<br> </span><span style="color: #FF8000">// Key rows by task name.<br> </span><span style="color: #DD0000">'clear-caches' </span><span style="color: #007700">=> </span><span style="color: #0000BB">TRUE</span><span style="color: #007700">,<br> </span><span style="color: #DD0000">'update-file-paths' </span><span style="color: #007700">=> </span><span style="color: #0000BB">FALSE</span><span style="color: #007700">,<br>);<br></span><span style="color: #0000BB">?></span></span>
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:
<span style="color: #000000"><span style="color: #0000BB"><?php<br></span><span style="color: #FF8000">/**<br> * Implements hook_devit_tasks().<br> */<br></span><span style="color: #007700">function </span><span style="color: #0000BB">yourmodule_devit_tasks</span><span style="color: #007700">() {<br> </span><span style="color: #0000BB">$tasks </span><span style="color: #007700">= array();<p> </p></span><span style="color: #0000BB">$tasks</span><span style="color: #007700">[</span><span style="color: #DD0000">'disable-caching'</span><span style="color: #007700">] = array(<br> </span><span style="color: #DD0000">'title' </span><span style="color: #007700">=> </span><span style="color: #0000BB">t</span><span style="color: #007700">(</span><span style="color: #DD0000">'Disable core caching features'</span><span style="color: #007700">),<br> </span><span style="color: #DD0000">'description' </span><span style="color: #007700">=> </span><span style="color: #0000BB">t</span><span style="color: #007700">(</span><span style="color: #DD0000">'Disables page cache, page compression, block cache, and CSS & JS optimization.'</span><span style="color: #007700">),<br> </span><span style="color: #DD0000">'task callback' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'yourmodule_disable_caching'</span><span style="color: #007700">,<br> </span><span style="color: #DD0000">'access arguments' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'administer site configuration'</span><span style="color: #007700">,<br> );<p> return </p></span><span style="color: #0000BB">$tasks</span><span style="color: #007700">;<br>}<p></p></span><span style="color: #FF8000">/**<br> * Disables core caching.<br> */<br></span><span style="color: #007700">function </span><span style="color: #0000BB">yourmodule_disable_caching</span><span style="color: #007700">() {<br> </span><span style="color: #0000BB">variable_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'cache'</span><span style="color: #007700">, </span><span style="color: #DD0000">"0"</span><span style="color: #007700">);<br> </span><span style="color: #0000BB">variable_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'block_cache'</span><span style="color: #007700">, </span><span style="color: #DD0000">"0"</span><span style="color: #007700">);<br> </span><span style="color: #0000BB">variable_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'preprocess_js'</span><span style="color: #007700">, </span><span style="color: #DD0000">"0"</span><span style="color: #007700">);<br> </span><span style="color: #0000BB">variable_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'preprocess_css'</span><span style="color: #007700">, </span><span style="color: #DD0000">"0"</span><span style="color: #007700">);<br> </span><span style="color: #0000BB">variable_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'page_compression'</span><span style="color: #007700">, </span><span style="color: #DD0000">"0"</span><span style="color: #007700">);<br>}<br></span><span style="color: #0000BB">?></span></span>
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