print_mail.install 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the print_mail module.
  5. *
  6. * @ingroup print
  7. */
  8. /**
  9. * Implements hook_enable().
  10. */
  11. function print_mail_enable() {
  12. // Module weight.
  13. db_update('system')
  14. ->fields(array(
  15. 'weight' => 1,
  16. ))
  17. ->condition('type', 'module')
  18. ->condition('name', 'print_mail')
  19. ->execute();
  20. if (module_exists('mailsystem')) {
  21. mailsystem_set(array('print_mail' => 'DefaultMailSystem'));
  22. }
  23. }
  24. /**
  25. * Implements hook_requirements().
  26. */
  27. function print_mail_requirements($phase) {
  28. $requirements = array();
  29. $t = get_t();
  30. switch ($phase) {
  31. // At runtime, make sure that a PDF generation tool is selected.
  32. case 'runtime':
  33. if (module_exists('mailsystem')) {
  34. $mail_system = mailsystem_get();
  35. if (($mail_system['default-system'] != 'DefaultMailSystem') && (!isset($mail_system['print_mail']) || ($mail_system['print_mail'] != 'DefaultMailSystem'))) {
  36. $requirements['print_mail_mailsystem'] = array(
  37. 'title' => $t('Printer, email and PDF versions - Send by email'),
  38. 'value' => $t('Incompatible Mail System setting detected'),
  39. 'description' => $t('The send by email module requires the use of the DefaultMailSystem, please configure it in the !url.', array('!url' => l($t('Mail System Settings page'), 'admin/config/system/mailsystem'))),
  40. 'severity' => REQUIREMENT_WARNING,
  41. );
  42. }
  43. }
  44. }
  45. return $requirements;
  46. }
  47. /**
  48. * Implements hook_disable().
  49. */
  50. function print_mail_disable() {
  51. if (module_exists('mailsystem')) {
  52. mailsystem_clear(array('print_mail' => ''));
  53. }
  54. }
  55. /**
  56. * Implements hook_uninstall().
  57. */
  58. function print_mail_uninstall() {
  59. variable_del('print_mail_display_sys_urllist');
  60. variable_del('print_mail_hourly_threshold');
  61. variable_del('print_mail_job_queue');
  62. variable_del('print_mail_link_text');
  63. variable_del('print_mail_link_text_enabled');
  64. variable_del('print_mail_send_option_default');
  65. variable_del('print_mail_teaser_choice');
  66. variable_del('print_mail_teaser_default');
  67. variable_del('print_mail_use_reply_to');
  68. variable_del('print_mail_user_recipients');
  69. variable_del('print_mail_book_link');
  70. variable_del('print_mail_link_class');
  71. variable_del('print_mail_link_pos');
  72. variable_del('print_mail_link_teaser');
  73. variable_del('print_mail_link_use_alias');
  74. variable_del('print_mail_show_link');
  75. variable_del('print_mail_sys_link_pages');
  76. variable_del('print_mail_sys_link_visibility');
  77. $settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'print\_mail\_display\_%'");
  78. foreach ($settings as $variable) {
  79. variable_del($variable->name);
  80. }
  81. }
  82. /**
  83. * Implements hook_schema().
  84. */
  85. function print_mail_schema() {
  86. $schema['print_mail_node_conf'] = array(
  87. 'description' => 'Send by email node-specific configuration settings',
  88. 'fields' => array(
  89. 'nid' => array(
  90. 'type' => 'int',
  91. 'unsigned' => TRUE,
  92. 'not null' => TRUE,
  93. 'description' => 'The {node}.nid of the node.',
  94. ),
  95. 'link' => array(
  96. 'type' => 'int',
  97. 'unsigned' => TRUE,
  98. 'not null' => TRUE,
  99. 'default' => 1,
  100. 'size' => 'tiny',
  101. 'description' => 'Show link',
  102. ),
  103. 'comments' => array(
  104. 'type' => 'int',
  105. 'unsigned' => TRUE,
  106. 'not null' => TRUE,
  107. 'default' => 1,
  108. 'size' => 'tiny',
  109. 'description' => 'Show link in individual comments',
  110. ),
  111. 'url_list' => array(
  112. 'type' => 'int',
  113. 'unsigned' => TRUE,
  114. 'not null' => TRUE,
  115. 'default' => 1,
  116. 'size' => 'tiny',
  117. 'description' => 'Show Printer-friendly URLs list',
  118. ),
  119. ),
  120. 'primary key' => array('nid'),
  121. );
  122. $schema['print_mail_page_counter'] = array(
  123. 'description' => 'Send by email version access counter',
  124. 'fields' => array(
  125. 'path' => array(
  126. 'type' => 'varchar',
  127. 'length' => 255,
  128. 'not null' => TRUE,
  129. 'description' => 'Page path',
  130. ),
  131. 'totalcount' => array(
  132. 'type' => 'int',
  133. 'unsigned' => TRUE,
  134. 'not null' => TRUE,
  135. 'default' => 0,
  136. 'size' => 'big',
  137. 'description' => 'Number of page accesses',
  138. ),
  139. 'timestamp' => array(
  140. 'type' => 'int',
  141. 'unsigned' => TRUE,
  142. 'not null' => TRUE,
  143. 'default' => 0,
  144. 'description' => 'Last access',
  145. ),
  146. 'sentcount' => array(
  147. 'type' => 'int',
  148. 'unsigned' => TRUE,
  149. 'not null' => TRUE,
  150. 'default' => 0,
  151. 'size' => 'big',
  152. 'description' => 'Number of sent emails',
  153. ),
  154. 'sent_timestamp' => array(
  155. 'type' => 'int',
  156. 'unsigned' => TRUE,
  157. 'not null' => TRUE,
  158. 'default' => 0,
  159. 'description' => 'Last email sent',
  160. ),
  161. ),
  162. 'primary key' => array('path'),
  163. );
  164. return $schema;
  165. }
  166. /**
  167. * Remove hardcoded numeric deltas from all blocks.
  168. */
  169. function print_mail_update_7000(&$sandbox) {
  170. $renamed_deltas = array(
  171. 'print_mail' => array(
  172. '0' => 'print_mail-top',
  173. ),
  174. );
  175. update_fix_d7_block_deltas($sandbox, $renamed_deltas, array());
  176. }
  177. /**
  178. * Disable MimeMailSystem for now.
  179. */
  180. function print_mail_update_7100(&$sandbox) {
  181. if (module_exists('mailsystem')) {
  182. mailsystem_set(array('print_mail' => 'DefaultMailSystem'));
  183. }
  184. }
  185. /**
  186. * Update permissions to new spellings.
  187. */
  188. function print_mail_update_7101(&$sandbox) {
  189. db_update('role_permission')
  190. ->fields(array('permission' => 'access send by email'))
  191. ->condition('permission', 'access send to friend')
  192. ->execute();
  193. db_update('role_permission')
  194. ->fields(array('permission' => 'send unlimited emails'))
  195. ->condition('permission', 'send unlimited e-mails')
  196. ->execute();
  197. }
  198. /**
  199. * Delete old variables.
  200. */
  201. function print_mail_update_7200(&$sandbox) {
  202. variable_del('print_mail_settings');
  203. variable_del('print_mail_node_link_pages');
  204. variable_del('print_mail_node_link_visibility');
  205. variable_del('print_mail_text_title');
  206. variable_del('print_mail_text_confirmation');
  207. variable_del('print_mail_text_message');
  208. variable_del('print_mail_text_subject');
  209. variable_del('print_mail_text_content');
  210. }
  211. /**
  212. * Enable block and help area links.
  213. */
  214. function print_mail_update_7202(&$sandbox) {
  215. $link_pos = variable_get('print_mail_link_pos', drupal_json_decode('{ "link": "link", "block": "block", "help": "help" }'));
  216. $link_pos['block'] = 'block';
  217. $link_pos['help'] = 'help';
  218. variable_set('print_mail_link_pos', $link_pos);
  219. }
  220. /**
  221. * Increase size of the path field in the print_mail_page_counter table.
  222. */
  223. function print_mail_update_7203(&$sandbox) {
  224. db_drop_primary_key('print_mail_page_counter');
  225. db_change_field('print_mail_page_counter', 'path', 'path',
  226. array(
  227. 'type' => 'varchar',
  228. 'length' => 255,
  229. 'not null' => TRUE,
  230. 'description' => 'Page path',
  231. ),
  232. array('primary key' => array('path')));
  233. }