views_send.install 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /**
  3. * @file
  4. * The install and update code for the Views Send module.
  5. *
  6. * @ingroup views_send.
  7. */
  8. /**
  9. * Implements hook_schema().
  10. */
  11. function views_send_schema() {
  12. $schema['views_send_spool'] = array(
  13. 'description' => 'Table holds e-mails that are being send on cron.',
  14. 'fields' => array(
  15. 'eid' => array(
  16. 'description' => 'The primary identifier for an e-mail.',
  17. 'type' => 'serial',
  18. 'unsigned' => TRUE,
  19. 'not null' => TRUE),
  20. 'uid' => array(
  21. 'description' => 'The user that has sent the message.',
  22. 'type' => 'int',
  23. 'not null' => TRUE,
  24. 'unsigned' => TRUE,
  25. 'default' => 0),
  26. 'timestamp' => array(
  27. 'description' => 'The Unix timestamp when the message was added to spool.',
  28. 'type' => 'int',
  29. 'not null' => TRUE,
  30. 'unsigned' => TRUE,
  31. 'default' => 0),
  32. 'status' => array(
  33. 'description' => 'Status: 0 = pending; 1 = sent.',
  34. 'type' => 'int',
  35. 'size' => 'tiny',
  36. 'not null' => TRUE,
  37. 'unsigned' => TRUE,
  38. 'default' => 0),
  39. 'tentatives' => array(
  40. 'description' => 'How many times we tried to send this message.',
  41. 'type' => 'int',
  42. 'not null' => TRUE,
  43. 'unsigned' => TRUE,
  44. 'default' => 0),
  45. 'from_name' => array(
  46. 'description' => 'The real name of the sender.',
  47. 'type' => 'varchar',
  48. 'length' => 255,
  49. 'not null' => FALSE,
  50. 'default' => ''),
  51. 'from_mail' => array(
  52. 'description' => 'The sender e-mail address.',
  53. 'type' => 'varchar',
  54. 'length' => 255,
  55. 'not null' => TRUE,
  56. 'default' => ''),
  57. 'to_name' => array(
  58. 'description' => 'The real name of the recipient.',
  59. 'type' => 'varchar',
  60. 'length' => 255,
  61. 'not null' => FALSE,
  62. 'default' => ''),
  63. 'to_mail' => array(
  64. 'description' => 'The recipient e-mail address.',
  65. 'type' => 'varchar',
  66. 'length' => 255,
  67. 'not null' => TRUE,
  68. 'default' => ''),
  69. 'subject' => array(
  70. 'description' => 'The e-mail subject.',
  71. 'type' => 'varchar',
  72. 'length' => 255,
  73. 'not null' => TRUE,
  74. 'default' => ''),
  75. 'body' => array(
  76. 'description' => 'The e-mail body.',
  77. 'type' => 'text',
  78. 'not null' => TRUE,
  79. 'size' => 'big',),
  80. 'headers' => array(
  81. 'description' => 'The e-mail additional headers.',
  82. 'type' => 'text',
  83. 'not null' => TRUE,
  84. 'size' => 'big',),
  85. ),
  86. 'indexes' => array(
  87. 'uid' => array('uid'),
  88. 'timestamp' => array('timestamp'),
  89. ),
  90. 'primary key' => array('eid'),
  91. );
  92. return $schema;
  93. }
  94. /**
  95. * Implements hook_uninstall().
  96. */
  97. function views_send_uninstall() {
  98. db_query("DELETE FROM {variable} WHERE name LIKE 'views_send_%'");
  99. db_query("DELETE FROM {cache} WHERE cid LIKE 'variables%'");
  100. }
  101. /**
  102. * Remove unused variables.
  103. */
  104. function views_send_update_6001() {
  105. variable_del('views_send_format');
  106. variable_del('views_send_from_mail');
  107. variable_del('views_send_from_name');
  108. variable_del('views_send_headers');
  109. variable_del('views_send_message');
  110. variable_del('views_send_priority');
  111. variable_del('views_send_receipt');
  112. variable_del('views_send_remember');
  113. variable_del('views_send_subject');
  114. variable_del('views_send_tokens');
  115. variable_del('views_send_to_mail');
  116. variable_del('views_send_to_name');
  117. return array();
  118. }
  119. /**
  120. * Remove views_send_format variables.
  121. */
  122. function views_send_update_6002() {
  123. $ret = array();
  124. $ret[] = update_sql("DELETE FROM {variable} WHERE name LIKE 'views_send_format_%'");
  125. return $ret;
  126. }
  127. /**
  128. * Backend structure is altered for implementing http://drupal.org/node/808058
  129. */
  130. function views_send_update_6003() {
  131. $ret = array();
  132. // Get updated schema.
  133. $schema = views_send_schema();
  134. // Rename body field from 'message' to 'body'.
  135. db_change_field($ret, 'views_send_spool', 'message', 'body', $schema['views_send_spool']['fields']['body']);
  136. // Drop other fields that are obsolete after spooling.
  137. db_drop_field($ret, 'views_send_spool', 'format');
  138. db_drop_field($ret, 'views_send_spool', 'priority');
  139. db_drop_field($ret, 'views_send_spool', 'receipt');
  140. return $ret;
  141. }