pm_email_notify.install

  1. 1 pm_email_notify/pm_email_notify.install
  2. 7-1 pm_email_notify/pm_email_notify.install
  3. 7-2 pm_email_notify/pm_email_notify.install
  4. 6-2 pm_email_notify/pm_email_notify.install

This file contains installation and update hooks for pm_email_notify.

File

pm_email_notify/pm_email_notify.install
View source
  1. <?php
  2. /**
  3. * @file
  4. *
  5. * This file contains installation and update hooks for pm_email_notify.
  6. */
  7. /**
  8. * Implements hook_uninstall().
  9. */
  10. function pm_email_notify_uninstall() {
  11. variable_del('pm_email_notify_body');
  12. variable_del('pm_email_notify_default');
  13. variable_del('pm_email_notify_subject');
  14. variable_del('pm_email_notify_from');
  15. variable_del('privatemsg_setting_email_notify_level');
  16. variable_del('privatemsg_setting_email_notify_only_user');
  17. }
  18. /**
  19. * Implements hook_update_dependencies().
  20. */
  21. function pm_email_notify_update_dependencies() {
  22. $dependencies['pm_email_notify']['7200']['privatemsg'] = '7201';
  23. return $dependencies;
  24. }
  25. /**
  26. * Replace old placeholders with new tokens.
  27. */
  28. function pm_email_notify_update_7000() {
  29. $replacements = array(
  30. '!author' => '[privatemsg_message:author]',
  31. '!username' => '[privatemsg_message:recipient]',
  32. '!author_uid' => '[privatemsg_message:author:uid]',
  33. '!pm_subject' => '[privatemsg_message:subject]',
  34. '!pm_body' => '[privatemsg_message:body]',
  35. '!thread' => '[privatemsg_message:thread_id]',
  36. '!site' => '[site:name]',
  37. '!login-url' => '[site:login-url]',
  38. '!uri' => ' [site:url]',
  39. '!uri_brief' => '[site:url-brief]',
  40. '!message' => '[privatemsg_message:url]',
  41. '!settings' => '[privatemsg_message:recipient:edit-url]',
  42. );
  43. // Only update if there was actually something saved.
  44. if ($subject = variable_get('pm_email_notify_subject', FALSE)) {
  45. variable_set('pm_email_notify_subject', str_replace(array_keys($replacements), array_values($replacements), $subject));
  46. }
  47. if ($body = variable_get('pm_email_notify_body', FALSE)) {
  48. variable_set('pm_email_notify_body', str_replace(array_keys($replacements), array_values($replacements), $body));
  49. }
  50. }
  51. /**
  52. * Convert the old table to privatemsg settings API.
  53. */
  54. function pm_email_notify_update_7200() {
  55. // If the table was already deleted, this is a upgrade from 6-x.2.x. Nothing to do, then.
  56. if (!db_table_exists('pm_email_notify')) {
  57. return;
  58. }
  59. // Update the site-wide default setting.
  60. if (variable_get('pm_email_notify_default', TRUE)) {
  61. variable_set('privatemsg_setting_email_notify_level', PM_EMAIL_NOTIFY_LEVEL_ALL);
  62. }
  63. else {
  64. variable_set('privatemsg_setting_email_notify_level', PM_EMAIL_NOTIFY_LEVEL_DISABLED);
  65. }
  66. variable_del('pm_email_notify_default');
  67. // Convert user saved settings.
  68. $result = db_query('SELECT * FROM {pm_email_notify}');
  69. foreach ($result as $row) {
  70. privatemsg_set_setting('user', $row->user_id, 'email_notify_level', $row->email_notify_is_enabled ? PM_EMAIL_NOTIFY_LEVEL_DEFAULT : PM_EMAIL_NOTIFY_LEVEL_DISABLED);
  71. }
  72. db_drop_table('pm_email_notify');
  73. }

Functions

Namesort descending Description
pm_email_notify_uninstall Implements hook_uninstall().
pm_email_notify_update_7000 Replace old placeholders with new tokens.
pm_email_notify_update_7200 Convert the old table to privatemsg settings API.
pm_email_notify_update_dependencies Implements hook_update_dependencies().