prod_check.drush.inc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * Implementation of hook_drush_command().
  4. */
  5. function prod_check_drush_command() {
  6. $items = array();
  7. $items['prod-check'] = array(
  8. 'callback' => 'drush_prod_check_status',
  9. 'description' => 'Display the Production Check status page.',
  10. 'aliases' => array('pchk'),
  11. );
  12. $items['prod-check-prodmode'] = array(
  13. 'callback' => 'drush_prod_check_prod_mode',
  14. 'description' => 'Switch the site to production mode.',
  15. 'options' => array(
  16. 'config' => 'Ask for additional options before switching to production mode.',
  17. ),
  18. 'aliases' => array('pchk-pmode'),
  19. );
  20. return $items;
  21. }
  22. /**
  23. * Status page callback
  24. */
  25. function drush_prod_check_status() {
  26. // Map error codes to shell colours.
  27. $severity = array (
  28. PROD_CHECK_REQUIREMENT_INFO => '1',
  29. PROD_CHECK_REQUIREMENT_OK => '1;32',
  30. PROD_CHECK_REQUIREMENT_WARNING => '1;33',
  31. PROD_CHECK_REQUIREMENT_ERROR => '1;31',
  32. );
  33. $error = 0;
  34. $functions = _prod_check_functions();
  35. // Not needed here.
  36. unset($functions['prod_mon']);
  37. unset($functions['perf_data']);
  38. foreach ($functions as $set => $data) {
  39. $rows[] = array('');
  40. $rows[] = array("\033[1m" . dt($data['title'])."\033[0m");
  41. foreach ($data['functions'] as $function => $title) {
  42. $result = call_user_func($function);
  43. $func = ltrim($function, '_');
  44. if (is_array($result) && !empty($result)) {
  45. $rows[] = array(
  46. $result[$func]['title'],
  47. "\033[" . $severity[$result[$func]['severity']] . 'm' . strip_tags($result[$func]['value']) . "\033[0m",
  48. );
  49. if ($error < $result[$func]['severity']) {
  50. $error = $result[$func]['severity'];
  51. }
  52. }
  53. }
  54. }
  55. drush_print("\033[1m" . dt('Production Check status')."\033[0m", 1);
  56. drush_print_table($rows);
  57. if ($error > 0) {
  58. // Would be cool if we could prefix the admin path with http://<host>/ so it
  59. // will become a clickable link in some terminals. Any ideas?
  60. drush_print("\033[1m" . dt('Some errors were reported!') . "\033[0m " . dt('Check the full status page on') . " \033[1m" . 'admin/reports/prod-check' . "\033[0m " . dt('for details.'));
  61. }
  62. }
  63. /**
  64. * Switch to production mode.
  65. */
  66. function drush_prod_check_prod_mode() {
  67. $options = array();
  68. // Ask extra input when the --config option is used.
  69. if (drush_get_option('config', FALSE)) {
  70. $options['site_mail'] = drush_prompt(dt('Site e-mail address'));
  71. if (module_exists('webform')) {
  72. $options['webform_default_from_address'] = drush_prompt(dt('Webform default from e-mail address'));
  73. }
  74. if (module_exists('googleanalytics')) {
  75. $options['googleanalytics_account'] = drush_prompt(dt('Google Analytics Web Property ID'));
  76. }
  77. $options['block_cache'] = drush_confirm(dt('Enable Block cache'));
  78. if (module_exists('dblog')) {
  79. $options['dblog'] = drush_confirm(dt('Disable Database logging'));
  80. }
  81. $options['nagios'] = drush_confirm(dt('Enable Nagios monitoring contrib module'));
  82. }
  83. // Adjust settings.
  84. module_load_include('inc', 'prod_check', 'includes/prod_check.admin');
  85. $variables = prod_check_prod_mode_settings($options);
  86. drush_print(dt('The following settings have been changed: !variables.', array('!variables' => implode(', ', array_keys($variables)))));
  87. // Enable / disable modules.
  88. $modules = prod_check_prod_mode_modules($options);
  89. if (!empty($modules['disable'])) {
  90. drush_print(dt('The following modules have been disabled: !modules.', array('!modules' => implode(', ', $modules['disable']))));
  91. }
  92. if (!empty($modules['enable'])) {
  93. drush_print(dt('The following modules have been enabled: !modules.', array('!modules' => implode(', ', $modules['enable']))));
  94. }
  95. }