filters.utils.inc

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

A filter to run some basic utility functions. Basically any useful option not big enough to justify it's own class.

Classes

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

File

modules/contrib/backup_migrate/includes/filters.utils.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * A filter to run some basic utility functions. Basically any useful option not big enough to justify it's own class.
  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_utils extends backup_migrate_filter {
  12. var $saved_devel_query = NULL;
  13. /**
  14. * Get the default backup settings for this filter.
  15. */
  16. function backup_settings_default() {
  17. return array(
  18. 'utils_disable_query_log' => TRUE,
  19. 'utils_site_offline' => FALSE,
  20. 'utils_description' => '',
  21. );
  22. }
  23. /**
  24. * Get the default restore settings for this filter.
  25. */
  26. function restore_settings_default() {
  27. return array(
  28. 'utils_disable_query_log' => TRUE,
  29. 'utils_site_offline' => FALSE,
  30. );
  31. }
  32. /**
  33. * Get the form for the backup settings for this filter.
  34. */
  35. function backup_settings_form($settings) {
  36. $form = array();
  37. if (module_exists('devel') && variable_get('dev_query', 0)) {
  38. $form['database']['utils_disable_query_log'] = array(
  39. '#type' => 'checkbox',
  40. '#title' => t('Disable query log'),
  41. '#default_value' => !empty($settings['utils_disable_query_log']) ? $settings['utils_disable_query_log'] : NULL,
  42. '#description' => t('Disable the devel module\'s query logging during the backup operation. It will be enabled again after backup is complete. This is very highly recommended.'),
  43. );
  44. }
  45. $form['advanced']['utils_site_offline'] = array(
  46. '#type' => 'checkbox',
  47. '#title' => t('Take site offline'),
  48. '#default_value' => !empty($settings['utils_site_offline']) ? $settings['utils_site_offline'] : NULL,
  49. '#description' => t('Take the site offline during backup and show a maintenance message. Site will be taken back online once the backup is complete.'),
  50. );
  51. $form['advanced']['utils_site_offline_message'] = array(
  52. '#type' => 'textarea',
  53. '#title' => t('Site off-line message'),
  54. '#default_value' => !empty($settings['utils_site_offline_message']) ? $settings['utils_site_offline_message'] : variable_get('maintenance_mode_message', t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => variable_get('site_name', 'Drupal')))),
  55. '#description' => t('Message to show visitors when the site is in off-line mode.')
  56. );
  57. $form['advanced']['utils_description'] = array(
  58. '#type' => 'textarea',
  59. '#title' => t('Description'),
  60. '#default_value' => !empty($settings['utils_description']) ? $settings['utils_description'] : NULL,
  61. '#description' => t('Add a short description to the backup file.'),
  62. );
  63. return $form;
  64. }
  65. /**
  66. * Get the form for the restore settings for this filter.
  67. */
  68. function restore_settings_form($settings) {
  69. $form = array();
  70. if (module_exists('devel') && variable_get('dev_query', 0)) {
  71. $form['advanced']['utils_disable_query_log'] = array(
  72. '#type' => 'checkbox',
  73. '#title' => t('Disable query log'),
  74. '#default_value' => @$settings['utils_disable_query_log'],
  75. '#description' => t('Disable the devel module\'s query logging during the restore operation. It will be enabled again after restore is complete. This is very highly recommended.'),
  76. );
  77. }
  78. $form['advanced']['utils_site_offline'] = array(
  79. '#type' => 'checkbox',
  80. '#title' => t('Take site offline'),
  81. '#default_value' => !empty($settings['utils_site_offline']) ? $settings['utils_site_offline'] : NULL,
  82. '#description' => t('Take the site offline during restore and show a maintenance message. Site will be taken back online once the restore is complete.'),
  83. );
  84. $form['advanced']['utils_site_offline_message'] = array(
  85. '#type' => 'textarea',
  86. '#title' => t('Site off-line message'),
  87. '#default_value' => !empty($settings['utils_site_offline_message']) ? $settings['utils_site_offline_message'] : variable_get('maintenance_mode_message', t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => variable_get('site_name', 'Drupal')))),
  88. '#description' => t('Message to show visitors when the site is in off-line mode.')
  89. );
  90. return $form;
  91. }
  92. function pre_backup($source, $file, $settings) {
  93. $this->take_site_offline($settings);
  94. $this->disable_devel_query($settings);
  95. }
  96. function post_backup($source, $file, $settings) {
  97. $this->enable_devel_query($settings);
  98. $this->take_site_online($settings);
  99. $this->add_file_info($file, $settings);
  100. }
  101. function pre_restore($file, $settings) {
  102. $this->disable_devel_query($settings);
  103. $this->take_site_offline($settings);
  104. }
  105. function post_restore($file, $settings) {
  106. $this->enable_devel_query($settings);
  107. $this->take_site_online($settings);
  108. }
  109. /**
  110. * Disable devel query logging if it's active and the user has chosen to do so.
  111. */
  112. function disable_devel_query($settings) {
  113. $this->saved_devel_query = variable_get('dev_query', 0);
  114. if (module_exists('devel') && variable_get('dev_query', 0) && !empty($settings->filters['utils_disable_query_log'])) {
  115. variable_set('dev_query', 0);
  116. }
  117. }
  118. /**
  119. * Restore devel query to previous state.
  120. */
  121. function enable_devel_query($settings) {
  122. if (module_exists('devel')) {
  123. variable_set('dev_query', $this->saved_devel_query);
  124. }
  125. }
  126. /**
  127. * Add the backup metadata to the file.
  128. */
  129. function add_file_info($file, $settings) {
  130. $file->file_info['description'] = $settings->filters['utils_description'];
  131. $file->file_info['datestamp'] = time();
  132. $file->file_info['generator'] = 'Backup and Migrate (http://drupal.org/project/backup_migrate)';
  133. $file->file_info['generatorversion'] = BACKUP_MIGRATE_VERSION;
  134. $file->file_info['sites'] = array(
  135. '0' => array(
  136. 'version' => VERSION,
  137. 'name' => variable_get('site_name', ''),
  138. 'url' => url('', array('absolute' => TRUE)),
  139. ),
  140. );
  141. }
  142. /**
  143. * Take the site offline if configured to do so.
  144. */
  145. function take_site_offline($settings) {
  146. // Save the current state of the site in case a restore overwrites it.
  147. $this->saved_site_offline = variable_get('maintenance_mode', 0);
  148. if (@$settings->filters['utils_site_offline']) {
  149. $this->saved_site_offline_message = variable_get('maintenance_mode_message', NULL);
  150. if (!empty($settings->filters['utils_site_offline_message'])) {
  151. $this->saved_site_offline_message = variable_get('maintenance_mode_message', NULL);
  152. variable_set('maintenance_mode_message', $settings->filters['utils_site_offline_message']);
  153. }
  154. variable_set('maintenance_mode', 1);
  155. _backup_migrate_message('Site was taken offline.');
  156. }
  157. }
  158. /**
  159. * Take the site online again after backup or restore.
  160. */
  161. function take_site_online($settings) {
  162. // Take the site back off/online because the restored db may have changed that setting.
  163. variable_set('maintenance_mode', $this->saved_site_offline);
  164. if ($settings->filters['utils_site_offline']) {
  165. if (!empty($this->saved_site_offline_message)) {
  166. variable_set('maintenance_mode_message', $this->saved_site_offline_message);
  167. }
  168. _backup_migrate_message('Site was taken online.');
  169. }
  170. }
  171. }