filters.statusnotify.inc

  1. nittany7 modules/contrib/backup_migrate/includes/filters.statusnotify.inc
  2. mooc7 modules/contrib/backup_migrate/includes/filters.statusnotify.inc

A filter for compressing bckups with zip, gz bzip etc.

Classes

Namesort descending Description
backup_migrate_filter_statusnotify A filter to send a notification email on success or failure of backup.

File

modules/contrib/backup_migrate/includes/filters.statusnotify.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * A filter for compressing bckups with zip, gz bzip etc.
  5. */
  6. /**
  7. * A filter to send a notification email on success or failure of backup.
  8. *
  9. * @ingroup backup_migrate_filters
  10. */
  11. class backup_migrate_filter_statusnotify extends backup_migrate_filter {
  12. /**
  13. * Get the default backup settings for this filter.
  14. */
  15. function backup_settings_default() {
  16. return array(
  17. 'notify_success_enable' => FALSE,
  18. 'notify_failure_enable' => FALSE,
  19. 'notify_success_email' => variable_get('site_mail', ''),
  20. 'notify_failure_email' => variable_get('site_mail', ''),
  21. );
  22. }
  23. /**
  24. * Get the form for the settings for this filter.
  25. */
  26. function backup_settings_form($settings) {
  27. $form = array();
  28. $form['advanced']['notify_success_enable'] = array(
  29. "#type" => 'checkbox',
  30. "#title" => t("Send an email if backup succeeds"),
  31. "#default_value" => @$settings['notify_success_enable'],
  32. );
  33. $form['advanced']['notify_success_email'] = array(
  34. "#type" => "textfield",
  35. "#title" => t("Email Address for Success Notices"),
  36. "#default_value" => @$settings['notify_success_email'],
  37. );
  38. $form['advanced']['notify_failure_enable'] = array(
  39. "#type" => 'checkbox',
  40. "#title" => t("Send an email if backup fails"),
  41. "#default_value" => @$settings['notify_failure_enable'],
  42. );
  43. $form['advanced']['notify_failure_email'] = array(
  44. "#type" => "textfield",
  45. "#title" => t("Email Address for Failure Notices"),
  46. "#default_value" => @$settings['notify_failure_email'],
  47. );
  48. return $form;
  49. }
  50. /**
  51. * Send the success email.
  52. */
  53. function backup_succeed($settings) {
  54. if (@$settings->filters['notify_success_enable'] && $to = @$settings->filters['notify_success_email']) {
  55. $messages = $this->get_messages();
  56. $subject = t('!site backup succeeded', array('!site' => variable_get('site_name', 'Drupal site')));
  57. if ($messages = $this->get_messages()) {
  58. $body = t("The site backup has completed successfully with the following messages:\n!messages", array('!messages' => $messages));
  59. }
  60. else {
  61. $body = t("The site backup has completed successfully.\n");
  62. }
  63. mail($settings->filters['notify_success_email'], $subject, $body);
  64. }
  65. }
  66. /**
  67. * Send the failure email.
  68. */
  69. function backup_fail($settings) {
  70. if (@$settings->filters['notify_failure_enable'] && $to = @$settings->filters['notify_failure_email']) {
  71. $messages = $this->get_messages();
  72. $subject = t('!site backup failed', array('!site' => variable_get('site_name', 'Drupal site')));
  73. if ($messages = $this->get_messages()) {
  74. $body = t("The site backup has failed with the following messages:\n!messages", array('!messages' => $messages));
  75. }
  76. else {
  77. $body = t("The site backup has failed for an unknown reason.");
  78. }
  79. mail($settings->filters['notify_failure_email'], $subject, $body);
  80. }
  81. }
  82. /**
  83. * Render the messages and errors for the email.
  84. */
  85. function get_messages() {
  86. $out = "";
  87. $messages = _backup_migrate_messages();
  88. foreach ($messages as $message) {
  89. $out .= strip_tags(t($message['message'], $message['replace'])) . "\n";
  90. }
  91. return $out;
  92. }
  93. }