mimemail.install 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for Mime Mail module.
  5. */
  6. /**
  7. * Implements hook_enable().
  8. */
  9. function mimemail_enable() {
  10. module_load_include('module', 'mailsystem');
  11. mailsystem_set(
  12. array(
  13. mailsystem_default_id() => 'MimeMailSystem',
  14. 'mimemail' => 'MimeMailSystem',
  15. )
  16. );
  17. user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('edit mimemail user settings'));
  18. }
  19. /**
  20. * Implements hook_disable().
  21. */
  22. function mimemail_disable() {
  23. mailsystem_clear(array('mimemail' => 'MimeMailSystem'));
  24. variable_set('mimemail_alter', FALSE);
  25. }
  26. /**
  27. * Implements hook_uninstall().
  28. */
  29. function mimemail_uninstall() {
  30. $variables = array(
  31. 'mimemail_alter',
  32. 'mimemail_crlf',
  33. 'mimemail_engine',
  34. 'mimemail_incoming',
  35. 'mimemail_key',
  36. 'mimemail_textonly',
  37. 'mimemail_sitestyle',
  38. 'mimemail_name',
  39. 'mimemail_mail',
  40. 'mimemail_format',
  41. 'mimemail_simple_address',
  42. 'mimemail_linkonly',
  43. 'mimemail_preserve_class'
  44. );
  45. foreach ($variables as $variable) {
  46. variable_del($variable);
  47. }
  48. }
  49. /**
  50. * Implements hook_requirements().
  51. *
  52. * Ensures that the newly-required Mail System module is available, or else
  53. * disables the Mime Mail module and returns an informative error message.
  54. */
  55. function mimemail_requirements($phase) {
  56. if ($phase === 'install' || module_exists('mailsystem')) {
  57. return array();
  58. }
  59. $args = array(
  60. '!mailsystem' => url('http://drupal.org/project/mailsystem'),
  61. '%mailsystem' => 'Mail System',
  62. '!mimemail' => url('http://drupal.org/project/mimemail'),
  63. '%mimemail' => 'Mime Mail',
  64. );
  65. if ( module_enable(array('mailsystem'))
  66. && module_load_include('module', 'mailsystem')
  67. ) {
  68. drupal_set_message(
  69. t('The %mailsystem module has been enabled because the %mimemail module now requires it.', $args)
  70. );
  71. return array();
  72. }
  73. return array(
  74. 'mimemail_mailsystem' => array(
  75. 'title' => t('%mailsystem module', $args),
  76. 'value' => t('Not installed'),
  77. 'description' => t(
  78. 'The <a href="!smtp">%mimemail</a> module dependencies have changed. Please download and install the required <a href="!mailsystem">%mailsystem</a> module, then re-enable the <a href="!mimemail">%mimemail</a> module.', $args
  79. ),
  80. 'severity' => REQUIREMENT_ERROR,
  81. ),
  82. );
  83. }
  84. /**
  85. * Check installation requirements.
  86. */
  87. function mimemail_update_7000() {
  88. if ($requirements = mimemail_requirements('runtime')) {
  89. throw new DrupalUpdateException($requirements['mimemail_mailsystem']['description']);
  90. }
  91. }
  92. /**
  93. * Deletes useless variables.
  94. */
  95. function mimemail_update_7001() {
  96. variable_del('mimemail_theme');
  97. }
  98. /**
  99. * Generate new key for authenticating incoming messages.
  100. */
  101. function mimemail_update_7002() {
  102. variable_set('mimemail_key', drupal_random_key());
  103. return t('Mime Mail has generated a new key to authenticate incoming messages.');
  104. }