mimemail.install 2.9 KB

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