Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
provision_tasks_extra/provision_tasks_extra.drush.inc
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
201 lines (178 sloc)
6.77 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * @file | |
| * Provision/Drush hooks for the provision_tasks_extra module. | |
| * | |
| * These are the hooks that will be executed by the drush_invoke function. | |
| */ | |
| /** | |
| * Implementation of hook_drush_command(). | |
| */ | |
| function provision_tasks_extra_drush_command() { | |
| $items['provision-flush_cache'] = array( | |
| 'description' => 'Flushes all caches on a site', | |
| 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, | |
| ); | |
| $items['provision-rebuild_registry'] = array( | |
| 'description' => 'Rebuilds the registry on a site', | |
| 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, | |
| ); | |
| $items['provision-run_cron'] = array( | |
| 'description' => 'Runs cron on a site', | |
| 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, | |
| ); | |
| $items['provision-update'] = array( | |
| 'description' => dt('Runs db updates on a site'), | |
| 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, | |
| ); | |
| $items['provision-flush_drush_cache'] = array( | |
| 'description' => 'Flushes the Drush cache on the server', | |
| 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, | |
| ); | |
| $items['provision-site_health_check'] = array( | |
| 'description' => 'Runs health check on a site', | |
| 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH | |
| ); | |
| return $items; | |
| } | |
| /** | |
| * Implements the provision-site_health_check command. | |
| */ | |
| function drush_provision_tasks_extra_provision_site_health_check() { | |
| drush_errors_on(); | |
| $sitename = d()->name; | |
| $dmv = DRUSH_MAJOR_VERSION; | |
| drush_log(dt("This is Drush major version: %dmv", array('%dmv' => $dmv)), 'notice'); | |
| drush_shell_exec("drush6 $sitename en update -y"); | |
| $array = drush_shell_exec_output(); | |
| drush_log(dt($array), 'notice'); | |
| drush_log(dt('Health Check ###---### update module enabled temporarily'), 'success'); | |
| drush_log(dt('Health Check ###---### drush6 clean-modules ###---### start'), 'warning'); | |
| drush_shell_exec("drush6 $sitename clean-modules -y 2>&1"); | |
| $array = drush_shell_exec_output(); | |
| drush_log(dt($array), 'notice'); | |
| drush_log(dt('Health Check ###---### drush6 pm-updatestatus ###---### start'), 'warning'); | |
| drush_shell_exec("drush6 $sitename ups --field-labels 2>&1"); | |
| $array = drush_shell_exec_output(); | |
| drush_log(dt($array), 'notice'); | |
| drush_log(dt('Health Check ###---### drush6 status-report ###---### start'), 'warning'); | |
| drush_shell_exec("drush6 $sitename status-report 2>&1"); | |
| $array = drush_shell_exec_output(); | |
| drush_log(dt($array), 'notice'); | |
| drush_log(dt('Health Check ###---### drush6 updatedb-status ###---### start'), 'warning'); | |
| drush_shell_exec("drush6 $sitename updatedb-status 2>&1"); | |
| $array = drush_shell_exec_output(); | |
| drush_log(dt($array), 'notice'); | |
| if (drush_drupal_major_version(d()->root) >= 7) { | |
| drush_log(dt('Health Check ###---### drush6 security-review ###---### start'), 'warning'); | |
| drush_shell_exec("drush6 $sitename secrev --check=input_formats,field,error_reporting,query_errors,failed_logins,upload_extensions,admin_permissions,untrusted_php,temporary_files 2>&1"); | |
| $array = drush_shell_exec_output(); | |
| drush_log(dt($array), 'notice'); | |
| } | |
| drush_log(dt('Health Check ###---### FIN'), 'success'); | |
| provision_file()->chmod(d()->site_path, 0755) | |
| ->succeed('Changed permissions of <code>@path</code> to @perm') | |
| ->fail('Could not change permissions of <code>@path</code> to @perm'); | |
| } | |
| /** | |
| * Implements the provision-flush_cache command. | |
| */ | |
| function drush_provision_tasks_extra_provision_flush_cache() { | |
| drush_errors_on(); | |
| provision_backend_invoke(d()->name, 'cache-clear all'); | |
| drush_log(dt('All caches cleared')); | |
| } | |
| /** | |
| * Implements the provision-rebuild_registry command. | |
| */ | |
| function drush_provision_tasks_extra_provision_rebuild_registry() { | |
| drush_errors_on(); | |
| if (d()->type === 'site') { | |
| if (drush_drupal_major_version(d()->root) == 7) { | |
| provision_backend_invoke(d()->name, 'registry-rebuild --fire-bazooka'); | |
| drush_log(dt('Registry rebuilt with --fire-bazooka plus all caches cleared')); | |
| } | |
| else { | |
| provision_backend_invoke(d()->name, 'registry-rebuild'); | |
| drush_log(dt('Registry rebuilt w/o --fire-bazooka plus all caches cleared')); | |
| } | |
| } | |
| } | |
| /** | |
| * Implements the provision-run_cron command. | |
| */ | |
| function drush_provision_tasks_extra_provision_run_cron() { | |
| drush_errors_on(); | |
| provision_backend_invoke(d()->name, 'core-cron'); | |
| drush_log(dt('Drush core-cron task completed')); | |
| } | |
| /** | |
| * Implements the provision-update command. | |
| */ | |
| function drush_provision_tasks_extra_provision_update() { | |
| drush_errors_on(); | |
| provision_backend_invoke(d()->name, 'updatedb'); | |
| drush_log(dt('Drush updatedb task completed')); | |
| } | |
| /** | |
| * Implements drush_hook_COMMAND_pre_validate(). | |
| * | |
| * Make a backup of the site before we mess with it. | |
| */ | |
| function drush_provision_tasks_extra_provision_update_pre_validate() { | |
| /* Set offline mode to true and re-generate the settings.php. This will write a | |
| * $conf['site_offline'] = 1; to the settings.php | |
| */ | |
| drush_log(dt("Putting the site under maintenance")); | |
| d()->site_enabled = FALSE; | |
| _provision_drupal_create_settings_file(); | |
| provision_drupal_push_site(); | |
| // Ensure a unique backup file is used. | |
| $backup_file = d()->platform->server->backup_path . '/' . d()->uri . '-pre-update-' . date("Ymd.His", time()) . '.tar.gz'; | |
| $count = 0; | |
| while (is_file($backup_file)) { | |
| $count++; | |
| $backup_file = d()->platform->server->backup_path . '/' . d()->uri . '-pre-update-' . date('Ymd.His', time()) . '_' . $count . '.tar.gz'; | |
| } | |
| drush_set_option('pre_update_backup_file', $backup_file); | |
| drush_set_option('force', true); | |
| $success = drush_invoke_process('@self', 'provision-backup', array($backup_file)); | |
| if (!$success) { | |
| // If the backup failed, we don't want to try restoring it in the rollback. | |
| drush_set_option('pre_update_backup_file', FALSE); | |
| } | |
| } | |
| /** | |
| * Implements drush_hook_COMMAND_rollback(). | |
| */ | |
| function drush_provision_tasks_extra_provision_update_rollback() { | |
| $restore_file = drush_get_option('pre_update_backup_file', FALSE); | |
| if ($restore_file) { | |
| drush_set_option('force', true); | |
| drush_invoke_process('@self', 'provision-restore', array($restore_file)); | |
| drush_unset_option('force'); | |
| } | |
| // Set site_offline to false and regenerate the config | |
| drush_log(dt("Bringing the site out of maintenance")); | |
| d()->site_enabled = TRUE; | |
| _provision_drupal_create_settings_file(); | |
| provision_drupal_push_site(); | |
| } | |
| /** | |
| * Implements drush_hook_post_COMMAND(). | |
| */ | |
| function drush_provision_tasks_extra_post_provision_update() { | |
| // Set site_offline to false and regenerate the config | |
| drush_log(dt("Bringing the site out of maintenance")); | |
| d()->site_enabled = TRUE; | |
| _provision_drupal_create_settings_file(); | |
| provision_drupal_push_site(); | |
| } | |
| /** | |
| * Implements the provision-flush_drush_cache command. | |
| */ | |
| function drush_provision_tasks_extra_provision_flush_drush_cache() { | |
| drush_errors_on(); | |
| provision_backend_invoke(d()->name, 'cache-clear drush'); | |
| drush_log(dt('Drush cache on the server cleared')); | |
| } |