? demo-204033.patch
Index: database_mysql_dump.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/demo/database_mysql_dump.inc,v
retrieving revision 1.5.2.5
diff -u -p -r1.5.2.5 database_mysql_dump.inc
--- database_mysql_dump.inc	13 Mar 2009 14:03:48 -0000	1.5.2.5
+++ database_mysql_dump.inc	17 May 2009 12:01:53 -0000
@@ -28,13 +28,18 @@ function demo_dump_db($filename, $exclud
     $header .= "SET FOREIGN_KEY_CHECKS = 0;\n";
     fwrite($fp, $header);
 
-    foreach (demo_enum_tables() as $table) {
+    $tables = demo_enum_tables();
+    $ignore_tables = variable_get('demo_ignore_tables', array());
+
+    foreach ($tables as $table) {
+      if (!in_array($table, $ignore_tables)) {
       // Always export structure to allow creating a new site
       // from a database dump
-      fwrite($fp, _demo_dump_table_structure($table));
+        fwrite($fp, _demo_dump_table_structure($table));
 
-      if (!in_array($table, $exclude)) {
-        fwrite($fp, _demo_dump_table_data($table));
+        if (!in_array($table, $exclude)) {
+          fwrite($fp, _demo_dump_table_data($table));
+        }
       }
     }
 
@@ -82,7 +87,7 @@ function _demo_dump_table_data($table) {
   $output .= "--\n";
   $output .= "-- Dumping data for table '$table'\n";
   $output .= "--\n\n";
-  
+
   // Dump table data
   $result = db_query("SELECT * FROM %s", $table);
 
Index: demo.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/demo/demo.admin.inc,v
retrieving revision 1.1.2.10
diff -u -p -r1.1.2.10 demo.admin.inc
--- demo.admin.inc	16 May 2009 17:54:50 -0000	1.1.2.10
+++ demo.admin.inc	17 May 2009 12:01:55 -0000
@@ -13,7 +13,7 @@ define('DEMO_DUMP_VERSION', '1.1');
 
 function demo_admin_settings() {
   global $base_url;
-  
+
   $form['status'] = array(
     '#type' => 'fieldset',
     '#title' => t('Status'),
@@ -31,9 +31,9 @@ function demo_admin_settings() {
   $form['status'][] = array(
     '#value' => t('<p><strong>Default snapshot:</strong> !snapshot</p>', array('!snapshot' => variable_get('demo_dump_cron', t('None')))),
   );
-  
+
   $fileconfig = demo_get_fileconfig();
-  
+
   $form['dump'] = array(
     '#type' => 'fieldset',
     '#title' => t('Dump settings'),
@@ -49,7 +49,7 @@ function demo_admin_settings() {
     '#options' => $period,
     '#description' => t('Select how often this demonstration site is automatically reset. Ensure that you have chosen a snapshot for cron runs in <a href="!manage">Manage snapshots</a> first. <strong>Note:</strong> This requires cron to run at least within this interval.', array('!manage' => url('admin/build/demo/manage'))),
   );
-  
+
   $form['dump']['path'] = array(
     '#type' => 'textfield',
     '#title' => t('Dump path'),
@@ -57,15 +57,31 @@ function demo_admin_settings() {
     '#size' => 30,
     '#description' => t('Enter a writable directory where dump files of this demonstration site are stored, f.e. %files. The name of this site (e.g. %confpath) is automatically appended to this directory, if required.<br /><br /><strong>Note: For security reasons you should store site dumps outside of the document root of your webspace!</strong>', array('%files' => file_directory_path() .'/demo', '%confpath' => $fileconfig['site'])),
   );
+
+  $form['dump']['ignore'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Ignore Selected Tables.'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+    '#description' => t('Demo module will ignore the following selected tables. Table contents remain unchanged during the reset and snapshot creation.')
+  );
+
+  $form['dump']['ignore']['demo_ignore_tables'] = array(
+    '#type' => 'checkboxes',
+    '#options' => drupal_map_assoc(demo_enum_tables()),
+    '#default_value' => variable_get('demo_ignore_tables', array())
+  );
+
   $form[] = array(
     '#type' => 'submit',
     '#value' => t('Save'),
   );
-  
+
   return $form;
 }
 
 function demo_admin_settings_submit($form, &$form_state) {
+  $tables = array();
   if (!file_check_directory($form_state['values']['path'], FILE_CREATE_DIRECTORY)) {
     form_set_error('path', t('The snapshot directory %directory could not be created.', array('%directory' => $form_state['values']['path'])));
     return FALSE;
@@ -73,6 +89,14 @@ function demo_admin_settings_submit($for
   else {
     variable_set('demo_dump_path', $form_state['values']['path']);
   }
+
+  foreach ($form_state['values']['demo_ignore_tables'] as $key => $value) {
+    if($value) {
+      $tables[$key] = $value;
+    }
+  }
+
+  variable_set('demo_ignore_tables', $tables);
   variable_set('demo_reset_interval', $form_state['values']['interval']);
   drupal_set_message(t('The configuration options have been saved.'));
 }
@@ -155,7 +179,7 @@ function demo_dump_submit($form, &$form_
   if (!$info) {
     return false;
   }
-  
+
   // Include database specific functions.
   $engine = ($db_type == 'mysqli' ? 'mysql' : $db_type);
   $inc_file = drupal_get_path('module', 'demo') .'/database_'. $engine .'_dump.inc';
@@ -166,10 +190,10 @@ function demo_dump_submit($form, &$form_
       // Set new default snapshot.
       demo_set_default($info['filename']);
     }
-  
+
     // Increase PHP's max_execution_time for large dumps.
     @set_time_limit(600);
-  
+
     // Perform dump.
     $fileconfig = demo_get_fileconfig($info['filename']);
     $exclude = array(
@@ -203,7 +227,7 @@ function demo_reset_confirm() {
     '#title' => t('Available snapshots'),
   );
   $form = array_merge_recursive($form, demo_get_dumps());
-  
+
   return confirm_form($form, t('Are you sure you want to reset the site?'), 'admin/build/demo', t('Resetting the site will overwrite all changes that have been made to this Drupal installation since the chosen snapshot.<br /><br /><div style="color: red; font-weight: bold; font-size: 18px;"><center>THIS ACTION CANNOT BE UNDONE!</center><br /></div>'), t('Reset'), t('Cancel'));
 }
 
@@ -215,7 +239,7 @@ function demo_reset_confirm_submit($form
   demo_reset($form_state['values']['filename']);
   // Save time of last reset.
   variable_set('demo_reset_last', time());
-  
+
   $form_state['redirect'] = isset($form_state['values']['redirect']) ? $form_state['values']['redirect'] : 'admin/build/demo';
 }
 
@@ -236,10 +260,15 @@ function demo_reset($filename = 'demo_si
 
   // Drop tables
   $dt_watchdog = db_prefix_tables('{watchdog}');
-  foreach (demo_enum_tables() as $table) {
-    // Skip watchdog, except for legacy dumps that included the watchdog table
-    if ($table != $dt_watchdog || $is_version_1_0_dump) {
-      db_query("DROP TABLE %s", $table);
+  $tables = demo_enum_tables();
+  $ignore_tables = variable_get('demo_ignore_tables', array());
+
+  foreach ($tables as $table) {
+    if (!in_array($table, $ignore_tables)) {
+      // Skip watchdog, except for legacy dumps that included the watchdog table
+      if ($table != $dt_watchdog || $is_version_1_0_dump) {
+        db_query("DROP TABLE %s", $table);
+      }
     }
   }
 
@@ -300,7 +329,7 @@ function demo_reset($filename = 'demo_si
 
 function demo_get_fileconfig($filename = 'demo_site') {
   $fileconfig = array();
-  
+
   // Build dump path.
   $fileconfig['path'] = variable_get('demo_dump_path', file_directory_path() .'/demo');
   $fileconfig['dumppath'] = $fileconfig['path'];
@@ -310,13 +339,13 @@ function demo_get_fileconfig($filename =
   if (strpos($fileconfig['path'], conf_path()) === FALSE && strpos($fileconfig['path'], '/all/') === FALSE) {
     $fileconfig['dumppath'] .= $fileconfig['site'];
   }
-  
+
   // Check if directory exists.
   file_check_directory($fileconfig['path'], FILE_CREATE_DIRECTORY, 'path');
   if (!file_check_directory($fileconfig['dumppath'], FILE_CREATE_DIRECTORY, 'path')) {
     return FALSE;
   }
-  
+
   // Protect dump files.
   $htaccess = $fileconfig['path'] ."/.htaccess";
   if (!is_file($htaccess)) {
@@ -326,21 +355,21 @@ function demo_get_fileconfig($filename =
       chmod($htaccess, 0664);
     }
   }
-    
+
   // Build SQL filename.
   $fileconfig['sql'] = $filename .'.sql';
   $fileconfig['sqlfile'] = $fileconfig['dumppath'] .'/'. $fileconfig['sql'];
-  
+
   // Build info filename.
   $fileconfig['info'] = $filename .'.info';
   $fileconfig['infofile'] = $fileconfig['dumppath'] .'/'. $fileconfig['info'];
-  
+
   return $fileconfig;
 }
 
 function demo_get_dumps() {
   $fileconfig = demo_get_fileconfig();
-  
+
   // Fetch list of available info files
   $files = file_scan_directory($fileconfig['dumppath'], '.info$');
 
@@ -351,7 +380,7 @@ function demo_get_dumps() {
 
   // Sort snapshots by date (ascending file modification time)
   uasort($files, create_function('$a, $b', 'return ($a->filemtime < $b->filemtime);'));
-  
+
   $options = array();
   // Forms API does not pass selected value of individual radio buttons,
   // so we manually insert an internal form value here.
@@ -364,7 +393,7 @@ function demo_get_dumps() {
     // Build basic file info
     $files[$filename] = (array)$files[$filename];
     $info = demo_get_info($filename);
-    
+
     // Convert file info for Forms API
     $option = array();
     $option['#type'] = 'radio';
@@ -386,13 +415,13 @@ function demo_get_dumps() {
       $option['#description'] .= t('Modules: ') . implode(', ', $info['modules']);
     }
     $option['#attributes'] = array('onclick' => "$('.description', this.parentNode.parentNode).slideToggle();");
-    
+
     $options['dump'][] = $option;
   }
-  
+
   // Attach stylesheet to initially hide descriptions
   drupal_add_js("$('div.form-item div.description', $('form')).hide();", 'inline', 'footer');
-  
+
   return $options;
 }
 
@@ -444,7 +473,7 @@ function demo_set_info($values = null) {
         $values['description'] = $old_description;
       }
     }
-    
+
     // Set values
     $infos = array();
     $infos['filename'] = $values['filename'];
@@ -459,7 +488,7 @@ function demo_set_info($values = null) {
       fwrite($infofile, $key .' = '. $info ."\n");
     }
     fclose($infofile);
-    
+
     return $infos;
   }
 }
