4 * Sync_enable adds options to sql-sync to enable and disable
5 * modules after an sql-sync operation. One use case for this
6 * is to use Drush site aliases to automatically enable your
7 * development modules whenever you sync from your live site to
8 * your dev site. You may also add or remove permissions at
13 * $aliases['dev'] = array (
14 * 'root' => '/srv/www/drupal',
15 * 'uri' => 'site.com',
16 * 'target-command-specific' => array(
17 * 'sql-sync' => array(
18 * 'enable' => array('devel', 'hacked'),
19 * 'disable' => array('securepages'),
20 * 'permission' => array(
21 * 'authenticated user' => array(
22 * 'add' => array('access devel information', 'access environment indicator'),
23 * 'remove' => 'change own password',
25 * 'anonymous user' => array(
26 * 'add' => 'access environment indicator',
33 * To use this feature, copy the 'target-command-specific'
34 * item from the example alias above, place it in your development
35 * site aliases, and customize the development module list
36 * to suit. You must also copy the sync_enable.drush.inc
37 * file to a location where Drush will find it, such as
38 * $HOME/.drush. See `drush topic docs-commands` for more
43 * Implement hook help alter.
45 * When a hook extends a command with additional options, it must
46 * implement help alter and declare the option(s). Doing so will add
47 * the option to the help text for the modified command, and will also
48 * allow the new option to be specified on the command line. Without
49 * this, Drush will fail with an error when a user attempts to use
52 function sync_enable_drush_help_alter(&$command) {
53 if ($command['command'] == 'sql-sync') {
54 $command['options']['enable'] = "Enable the specified modules in the target database after the sync operation has completed.";
55 $command['options']['disable'] = "Disable the specified modules in the target database after the sync operation has completed.";
56 $command['options']['permission'] = "Add or remove permissions from a role in the target database after the sync operation has completed. The value of this option must be an array, so it may only be specified in a site alias record or drush configuration file. See `drush topic docs-example-sync-extension`.";
61 * Implement hook post sql sync.
63 * The post hook is only called if the sql-sync operation completes
64 * without an error. When called, we check to see if the user specified
65 * any modules to enable/disable. If so, we will call pm-enable/pm-disable on each module.
67 function drush_sync_enable_post_sql_sync($source = NULL
, $destination = NULL
) {
68 $modules_to_enable = drush_get_option_list('enable');
69 if (!empty($modules_to_enable)) {
70 drush_log(dt("Enable !modules post-sql-sync", array('!modules' => implode(',', $modules_to_enable))), 'ok');
71 drush_invoke_process($destination, 'pm-enable', $modules_to_enable, array('yes' => TRUE
));
73 $modules_to_disable = drush_get_option_list('disable');
74 if (!empty($modules_to_disable)) {
75 drush_log(dt("Disable !modules post-sql-sync", array('!modules' => implode(',', $modules_to_disable))), 'ok');
76 drush_invoke_process($destination, 'pm-disable', $modules_to_disable, array('yes' => TRUE
));
78 $permissions_table = drush_get_option('permission');
79 if (!empty($permissions_table)) {
80 foreach ($permissions_table as
$role_name => $actions) {
81 if (array_key_exists('add', $actions)) {
82 $permissions_to_add = is_array($actions['add']) ?
$actions['add'] : explode(', ', $actions['add']);
83 foreach ($permissions_to_add as
$permission) {
84 $values = drush_invoke_process($destination, 'role-add-perm', array($role_name, $permission), array(), array('integrate' => TRUE
));
87 if (array_key_exists('remove', $actions)) {
88 $permissions_to_remove = is_array($actions['remove']) ?
$actions['remove'] : explode(', ', $actions['remove']);
89 foreach ($permissions_to_remove as
$permission) {
90 $values = drush_invoke_process($destination, 'role-remove-perm', array($role_name, $permission), array(), array('integrate' => TRUE
));