htmlmail.install 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * @file
  4. * Installation for HTML Mail module.
  5. */
  6. /**
  7. * Implements hook_requirements().
  8. *
  9. * Ensures that the Mail System module is available, and
  10. * that HTML Mail uses its own MailSystemInterface class.
  11. */
  12. function htmlmail_requirements($phase) {
  13. $result = array();
  14. if ($phase === 'install') {
  15. return $result;
  16. }
  17. if (module_load_include('inc', 'mailsystem', 'html_to_text') !== FALSE) {
  18. return $result;
  19. }
  20. $args = array(
  21. '%htmlmail' => 'HTML Mail',
  22. '!htmlmail' => 'http://drupal.org/project/htmlmail',
  23. '%mailsystem' => 'Mail System',
  24. '!mailsystem' => 'http://drupal.org/project/mailsystem',
  25. );
  26. $result['htmlmail_mailsystem'] = array(
  27. 'title' => t('%mailsystem module', $args),
  28. 'value' => t('7.x-1.x'),
  29. 'description' => t(
  30. '<a href="!htmlmail">%htmlmail</a> new requires <a href="!mailsystem">%mailsystem</a> 7.x-2.6 or later. Please download and install a recent version of <a href+"!mailsystem">%mailsystem</a>, then re-enable the <a href="!htmlmail">%htmlmail</a> module.', $args
  31. ),
  32. 'severity' => REQUIREMENT_ERROR,
  33. );
  34. return $result;
  35. }
  36. /**
  37. * Implements hook_update_N().
  38. *
  39. * Removes variables that are no longer used.
  40. */
  41. function htmlmail_update_7200() {
  42. variable_del('htmlmail_header');
  43. variable_del('htmlmail_footer');
  44. variable_del('htmlmail_css');
  45. }
  46. /**
  47. * Implements hook_update_N().
  48. *
  49. * Rename HTMLMailMailSystem to HTMLMailSystem.
  50. */
  51. function htmlmail_update_7201() {
  52. module_load_include('module', 'mailsystem');
  53. foreach (mailsystem_get() as $name => $value) {
  54. if ($value == 'HTMLMailMailSystem') {
  55. mailsystem_set(array($name => 'HTMLMailSystem'));
  56. }
  57. }
  58. }
  59. /**
  60. * Implements hook_update_N().
  61. *
  62. * Increase module weight so dependent modules get loaded first.
  63. */
  64. function htmlmail_update_7202() {
  65. db_query("UPDATE {system} SET weight = 10 WHERE type = 'module' AND name = 'htmlmail'");
  66. }
  67. function htmlmail_update_7203() {
  68. if ($requirements = htmlmail_requirements('runtime')) {
  69. $requirement = array_shift($requirements);
  70. throw new DrupalUpdateException($requirement['description']);
  71. }
  72. }
  73. /**
  74. * Implements hook_enable().
  75. */
  76. function htmlmail_enable() {
  77. module_load_include('module', 'mailsystem');
  78. mailsystem_set(array('htmlmail' => 'HTMLMailSystem'));
  79. }
  80. /**
  81. * Implements hook_disable().
  82. */
  83. function htmlmail_disable() {
  84. // Check is necessary because a 7.x-1.x to 7.x-2.x upgrade
  85. // may not have mailsystem installed.
  86. if (function_exists('mailsystem_clear')) {
  87. mailsystem_clear(array('htmlmail' => 'HTMLMailSystem'));
  88. }
  89. }
  90. /**
  91. * Implements hook_install().
  92. */
  93. function htmlmail_install() {
  94. htmlmail_update_7202();
  95. }
  96. /**
  97. * Implements hook_uninstall().
  98. */
  99. function htmlmail_uninstall() {
  100. db_query("DELETE FROM {variable} WHERE name LIKE 'htmlmail_%'");
  101. cache_clear_all('variables', 'cache');
  102. }