variable_realm.drush.inc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * @file
  4. * Drush commands for Variable Realm.
  5. */
  6. /**
  7. * Implements hook_drush_command().
  8. */
  9. function variable_realm_drush_command() {
  10. $items['variable-realm-get'] = array(
  11. 'description' => 'Get a variable for a specific realm and key.',
  12. 'examples' => array(
  13. 'drush variable-realm-get language es site_frontpage',
  14. 'drush variable-realm-get language es',
  15. ),
  16. 'arguments' => array(
  17. 'domain_name' => 'The realm name for the variable.',
  18. 'domain_key' => 'The domain key for the variable.',
  19. 'variable_name' => 'Optional variable name variable to get. If not present list all variables for that realm and key.',
  20. ),
  21. );
  22. $items['variable-realm-set'] = array(
  23. 'description' => 'Set a variable for a specific realm and key.',
  24. 'examples' => array(
  25. 'drush variable-realm-set language es site_frontpage /home ',
  26. ),
  27. 'arguments' => array(
  28. 'domain_name' => 'The realm name for the variable.',
  29. 'domain_key' => 'The domain key for the variable.',
  30. 'variable_name' => 'The name variable to set (e.g. site_frontpage).',
  31. 'value' => 'The value to set for this variable.'
  32. ),
  33. );
  34. $items['variable-realm-del'] = array(
  35. 'description' => 'Delete a variable for a specific realm and key.',
  36. 'examples' => array(
  37. 'drush variable-realm-del language es site_frontpage',
  38. ),
  39. 'arguments' => array(
  40. 'domain_name' => 'The realm name for the variable.',
  41. 'domain_key' => 'The domain key for the variable.',
  42. 'variable_name' => 'The name variable to set (e.g. site_frontpage).',
  43. ),
  44. );
  45. return $items;
  46. }
  47. /**
  48. * Implements hook_drush_help().
  49. */
  50. function variable_realm_drush_help($section) {
  51. $items = variable_realm_drush_command();
  52. $name = str_replace('domain:', '', $section);
  53. if (isset($items[$name])) {
  54. return dt($items[$name]['description']);
  55. }
  56. }
  57. /**
  58. * Drush command callback.
  59. * Set realm's variables.
  60. */
  61. function drush_variable_realm_set($realm_name, $realm_key, $variable_name, $value) {
  62. variable_realm_set($realm_name, $realm_key, $variable_name, $value);
  63. drush_print('Variable set.');
  64. }
  65. /**
  66. * Drush command callback.
  67. * Validate parameters
  68. */
  69. function drush_variable_realm_set_validate($realm_name = NULL, $realm_key = NULL, $variable_name = NULL, $value = NULL) {
  70. if (is_null($realm_name) | is_null($realm_key) || is_null($variable_name) || is_null($value)) {
  71. return drush_set_error('variable_realm', dt('Please enter all four required arguments, "dc-set realm_name realm_key variable_name value".'));
  72. }
  73. }
  74. /**
  75. * Drush command callback.
  76. * Delete realm's variables.
  77. */
  78. function drush_variable_realm_del($realm_name, $realm_key, $variable_name) {
  79. variable_realm_del($realm_name, $realm_key, $variable_name);
  80. drush_print('Variable deleted.');
  81. }
  82. /**
  83. * Drush command callback.
  84. * List realm's variables.
  85. */
  86. function drush_variable_realm_get($realm_name, $realm_key, $variable_name) {
  87. if ($variable_name) {
  88. $variables[$variable_name] = variable_realm_get($realm_name, $realm_key, $variable_name);
  89. }
  90. else {
  91. $variables = variable_realm($realm_name, $realm_key)->variable_list();
  92. }
  93. foreach ($variables as $name => $value) {
  94. drush_print_pipe(drush_format($value, $name, 'export'));
  95. drush_print(drush_format($value, $name));
  96. $returns[$name] = $value;
  97. }
  98. if (empty($variables)) {
  99. return drush_set_error('No matching variable found.');
  100. }
  101. else {
  102. return $returns;
  103. }
  104. }