smtp.install 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /**
  3. * @file
  4. * The installation instructions for the SMTP Authentication Support.
  5. */
  6. /**
  7. * Implements hook_requirements().
  8. */
  9. function smtp_requirements($phase) {
  10. $requirements = array();
  11. $t = get_t();
  12. if ($phase == 'runtime') {
  13. if (variable_get('smtp_queue', FALSE) || variable_get('smtp_queue_fail', FALSE)) {
  14. $count = db_query("SELECT count('name') FROM {queue} WHERE name='smtp_send_queue'")->fetchField();
  15. $requirements['smtp_queue'] = array(
  16. 'title' => $t('SMTP Queue'),
  17. 'value' => '',
  18. 'severity' => REQUIREMENT_INFO,
  19. );
  20. if ($count > 0) {
  21. $requirements['smtp_queue']['value'] = format_plural($count, 'There is 1 message queued for delivery.', 'There are @count messages queued for delivery.', array('@count' => $count))
  22. . ' '
  23. . $t('Delivery of the message(s) will be attempted the next time cron runs.');
  24. }
  25. else {
  26. $requirements['smtp_queue']['value'] = $t('There are no messages queued for delivery.');
  27. }
  28. }
  29. }
  30. return $requirements;
  31. }
  32. /**
  33. * Implements hook_install().
  34. */
  35. function smtp_install() {
  36. variable_set('smtp_on', 0);
  37. }
  38. /**
  39. * Implements hook_uninstall().
  40. */
  41. function smtp_uninstall() {
  42. variable_del('smtp_allowhtml');
  43. variable_del('smtp_from');
  44. variable_del('smtp_fromname');
  45. variable_del('smtp_host');
  46. variable_del('smtp_hostbackup');
  47. variable_del('smtp_on');
  48. variable_del('smtp_password');
  49. variable_del('smtp_port');
  50. variable_del('smtp_protocol');
  51. variable_del('smtp_verify_peer');
  52. variable_del('smtp_verify_peer_name');
  53. variable_del('smtp_allow_self_signed');
  54. variable_del('smtp_queue');
  55. variable_del('smtp_queue_fail');
  56. variable_del('smtp_username');
  57. variable_del('smtp_debugging');
  58. variable_del('smtp_client_hostname');
  59. variable_del('smtp_client_helo');
  60. variable_del('smtp_deliver');
  61. variable_del('smtp_reroute_address');
  62. }
  63. /**
  64. * Implements hook_disable().
  65. */
  66. function smtp_disable() {
  67. $mail_modes = variable_get('mail_system');
  68. $mail_modes['default-system'] = 'DefaultMailSystem';
  69. variable_set('mail_system', $mail_modes);
  70. }
  71. /**
  72. * Implementations of hook_update_N().
  73. */
  74. /**
  75. * Upgrade to Drupal 7.x
  76. */
  77. function smtp_update_7000() {
  78. if (variable_get('smtp_on', 0) != 0) {
  79. variable_set('mail_system', array('default-system' => 'SmtpMailSystem'));
  80. }
  81. // Not used any more in D7.
  82. variable_del('smtp_library');
  83. }
  84. /**
  85. * Back to default mail system if the status flag is off.
  86. */
  87. function smtp_update_7100() {
  88. $mail_modes = variable_get('mail_system', array('default-system' => 'DefaultMailSystem'));
  89. if ($mail_modes['default-system'] == 'SmtpMailSystem' && !variable_get('smtp_on', FALSE)) {
  90. $mail_modes['default-system'] = 'DefaultMailSystem';
  91. variable_set('mail_system', $mail_modes);
  92. }
  93. }
  94. /**
  95. * Updating variable value now that new SMTP logging behavior has been
  96. * implemented.
  97. */
  98. function smtp_update_7101() {
  99. $old_debugging_value = variable_get('smtp_debugging', 0);
  100. $logging = SMTP_LOGGING_NONE;
  101. if ($old_debugging_value == 1) {
  102. $logging = SMTP_LOGGING_ERRORS;
  103. }
  104. variable_set('smtp_debugging', $logging);
  105. }
  106. /**
  107. * Remove the unused 'smtp_library' variable.
  108. */
  109. function smtp_update_7102() {
  110. variable_del('smtp_library');
  111. }
  112. /**
  113. * Delete the variable "smtp_test_address". It is unlikely that this would
  114. * actually be set in the normal course of events, and it's no longer needed as
  115. * it was replaced with a form submit handler.
  116. */
  117. function smtp_update_7103() {
  118. variable_del('smtp_test_address');
  119. }
  120. /**
  121. * Add "smtp_verify_peer", "smtp_verify_peer_name", "smtp_allow_self_signed" variables
  122. * based on current running PHP version for most compatibility.
  123. */
  124. function smtp_update_7104() {
  125. if (version_compare(phpversion(), '5.6.0', '>=')) {
  126. variable_set('smtp_verify_peer', TRUE);
  127. variable_set('smtp_verify_peer_name', TRUE);
  128. }
  129. else {
  130. variable_set('smtp_verify_peer', FALSE);
  131. }
  132. variable_set('smtp_allow_self_signed', FALSE);
  133. }