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
diff -u -r1.25 data_ui.admin.inc
--- data_ui/data_ui.admin.inc	28 Jul 2009 19:21:20 -0000	1.25
+++ data_ui/data_ui.admin.inc	27 Oct 2009 21:32:43 -0000
@@ -200,6 +200,60 @@
 }
 
 /**
+ * Form callback for adopt table form.
+ */
+function data_ui_adopt_form($form_state) {
+  $form = array();
+
+  // compile a list of database tables that don't have active schema definitions
+  $modules = module_list();
+  sort($modules);
+  $modules = array_flip($modules);
+  $drupal_schema = drupal_get_schema(NULL, TRUE);
+  $db_schema = schema_invoke('inspect');
+  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,
+  );
+  $form['schemas'] = array(
+    '#type' => 'value',
+    '#value' => $orphaned_schemas,
+  );
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => 'Adopt',
+  );
+  return $form;
+}
+
+function data_ui_adopt_form_submit($form, &$form_state) {
+  $tables = array_keys(array_filter($form_state['values']['orphaned_tables']));
+  foreach ($tables as $t) {
+    $properties['name'] = $form_state['values']['schemas'][$t]['name'];
+    $properties['table_schema'] = $form_state['values']['schemas'][$t];
+    drupal_write_record('data_tables', $properties);
+  }
+
+  // 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
diff -u -r1.15 data_ui.module
--- data_ui/data_ui.module	27 Jul 2009 15:15:38 -0000	1.15
+++ data_ui/data_ui.module	27 Oct 2009 21:32:43 -0000
@@ -41,6 +41,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/content/data/create'] = array(
     'title' => 'Create a table',
