Index: data_ui/data_ui.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/data/data_ui/data_ui.admin.inc,v
retrieving revision 1.25.2.13
diff -u -r1.25.2.13 data_ui.admin.inc
--- data_ui/data_ui.admin.inc	19 Oct 2009 19:30:34 -0000	1.25.2.13
+++ data_ui/data_ui.admin.inc	28 Oct 2009 03:25:50 -0000
@@ -226,6 +226,70 @@
 }
 
 /**
+ * Form callback for adopt table form.
+ *
+ * 'Orphaned' tables are database tables that don't have an active schema
+ * definition.
+ */
+function data_ui_adopt_form($form_state) {
+  $form = array();
+
+  // compile a list of orphaned tables
+  $drupal_schema = drupal_get_schema(NULL, TRUE);
+  $db_schema = schema_invoke('inspect');
+  $orphaned_tables = array();
+  foreach ($db_schema as $name => $table) {
+    if (!isset($drupal_schema[$name])) {
+      $orphaned_tables[$name] = $name;
+      $orphaned_schemas[$name] = $table;
+    }
+  }
+
+  $form['orphaned_tables'] = array(
+    '#type' => 'checkboxes',
+    '#title' => t('Orphaned Tables'),
+    '#options' => $orphaned_tables,
+  );
+  if (count($orphaned_tables) < 1) {
+    $form['no_orphaned_tables'] = array(
+      '#type' => 'item',
+      '#value' => t('There are no orphaned tables in your database.'),
+    );
+  }
+  $form['schemas'] = array(
+    '#type' => 'value',
+    '#value' => $orphaned_schemas,
+  );
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => 'Adopt',
+  );
+  return $form;
+}
+
+/**
+ * Submit handler for adopt table form.
+ */
+function data_ui_adopt_form_submit($form, &$form_state) {
+  data_include('DataTable');
+  $tables = array_keys(array_filter($form_state['values']['orphaned_tables']));
+  foreach ($tables as $t) {
+    $tmp = DataTable::instance($t);
+    $tmp->adopt($t, $form_state['values']['schemas'][$t], FALSE);
+  }
+
+  // Have views read new views information about table.
+  if (module_exists('views')) {
+    views_invalidate_cache();
+  }
+
+  // data ui exposes path to a new default view.
+  menu_rebuild();
+
+  $form_state['redirect'] = 'admin/build/data';
+}
+
+/**
  * Form callback for create table form.
  */
 function data_ui_create_form(&$form_state) {
Index: data_ui/data_ui.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/data/data_ui/data_ui.module,v
retrieving revision 1.15.2.6
diff -u -r1.15.2.6 data_ui.module
--- data_ui/data_ui.module	27 Oct 2009 22:49:50 -0000	1.15.2.6
+++ data_ui/data_ui.module	28 Oct 2009 03:25:50 -0000
@@ -13,6 +13,9 @@
     case 'admin/content/data':
       $output = '<p>'. t('View content in data tables. If you would like to edit these tables, visit the !data_manage_page.', array('!data_manage_page' => l(t('Data table management page'), 'admin/build/data'))) .'</p>';
       return $output;
+    case 'admin/build/data/adopt':
+      $output = '<p>' . t('Manage database tables that aren\'t claimed by other modules. Adopting tables listed here will add them to Data\'s list of tables.') . '</p>';
+      return $output;
     case 'admin/build/data':
       if (module_exists('views')) {
         $output = '<p>'. t('Manage data tables. If you would like to view the content of these tables, visit the !data_view_page.', array('!data_view_page' => l(t('Data table content page'), 'admin/content/data'))) .'</p>';
@@ -69,6 +72,16 @@
       'access arguments' => array('administer data tables'),
       'type' => MENU_LOCAL_TASK,
     );
+    $items['admin/build/data/adopt'] = array(
+      'title' => 'Adopt tables',
+      'description' => 'Adopt data tables that aren\'t claimed by any module.',
+      'page callback' => 'drupal_get_form',
+      'page arguments' => array('data_ui_adopt_form'),
+      'file' => 'data_ui.admin.inc',
+      'access arguments' => array('administer data tables'),
+      'type' => MENU_LOCAL_TASK,
+      'weight' => 10,
+    );
   }
   $items['admin/build/data/create'] = array(
     'title' => 'Create a table',
@@ -233,4 +246,4 @@
     return 'admin/content/data/view/'. $path . $name;
   }
   return '';
-}
\ No newline at end of file
+}
Index: includes/DataTable.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/data/includes/Attic/DataTable.inc,v
retrieving revision 1.1.2.6
diff -u -r1.1.2.6 DataTable.inc
--- includes/DataTable.inc	15 Oct 2009 15:38:02 -0000	1.1.2.6
+++ includes/DataTable.inc	28 Oct 2009 03:25:51 -0000
@@ -132,6 +132,42 @@
   }
 
   /**
+   * Let Data manage a table that already exists in the database.
+   *
+   * @param $name
+   *   The name of the database table.
+   * @param $schema
+   *   The SchemaAPI table definition.
+   * @param $clear_caches
+   *   Whether to clear the Views cache and rebuild the menus if necessary;
+   *   provided so that bulk adoptions aren't super slow.
+   * @return
+   *   TRUE if the table was successfully adopted; FALSE if the table was
+   *   already known to Data or if the query failed.
+   */
+  public function adopt($name, $table_schema, $clear_caches = TRUE) {
+    $properties['name'] = $name;
+    $properties['table_schema'] = $table_schema;
+
+    if (!$this->defined() && drupal_write_record('data_tables', $properties)) {
+      if ($clear_caches) {
+        // Have views read new views information about table.
+        if (module_exists('views')) {
+          views_invalidate_cache();
+        }
+
+        // data ui exposes path to a new default view.
+        if (module_exists('data_ui')) {
+          menu_rebuild();
+        }
+      }
+
+      return TRUE;
+    }
+    return FALSE;
+  }
+
+  /**
    * Determine whether a table is defined.
    *
    * @return
