Index: views.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/views.module,v
retrieving revision 1.166.2.43
diff -u -r1.166.2.43 views.module
--- views.module	14 Jul 2007 18:54:16 -0000	1.166.2.43
+++ views.module	25 Oct 2007 03:39:09 -0000
@@ -1045,28 +1045,29 @@
 
     db_query("INSERT INTO {view_view} (" . implode(", ", $k) . ") VALUES (" . implode(", ", $s) . ")", $v);
   }
-
+  $tables = _views_get_tables(TRUE);
+  $arguments = _views_get_arguments();
   foreach ($view->sort as $i => $sort) {
-    db_query("INSERT INTO {view_sort} (vid, position, field, sortorder, options) VALUES (%d, %d, '%s', '%s', '%s')", $view->vid, $i, $sort['field'], $sort['sortorder'], $sort['options']);
+    db_query("INSERT INTO {view_sort} (vid, module, position, field, sortorder, options) VALUES (%d, '%s', %d, '%s', '%s', '%s')", $view->vid, $tables['modules']['sorts'][$sort['field']], $i, $sort['field'], $sort['sortorder'], $sort['options']);
   }
 
   foreach ($view->argument as $i => $arg) {
-    db_query("INSERT INTO {view_argument} (vid, type, argdefault, title, options, position, wildcard, wildcard_substitution) VALUES (%d, '%s', %d, '%s', '%s', %d, '%s', '%s')", $view->vid, $arg['type'], $arg['argdefault'], $arg['title'], $arg['options'], $i, $arg['wildcard'], $arg['wildcard_substitution']);
+    db_query("INSERT INTO {view_argument} (vid, module, type, argdefault, title, options, position, wildcard, wildcard_substitution) VALUES (%d, '%s', '%s', %d, '%s', '%s', %d, '%s', '%s')", $view->vid, $arguments['modules'][$arg['type']], $arg['type'], $arg['argdefault'], $arg['title'], $arg['options'], $i, $arg['wildcard'], $arg['wildcard_substitution']);
   }
 
   foreach ($view->field as $i => $arg) {
-    db_query("INSERT INTO {view_tablefield} (vid, tablename, field, label, handler, sortable, defaultsort, options, position) VALUES (%d, '%s', '%s', '%s', '%s', %d, '%s', '%s', %d)", $view->vid, $arg['tablename'], $arg['field'], $arg['label'], $arg['handler'], $arg['sortable'], $arg['defaultsort'], $arg['options'], $i);
+    db_query("INSERT INTO {view_tablefield} (vid, module, tablename, field, label, handler, sortable, defaultsort, options, position) VALUES (%d, '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', %d)", $view->vid, $tables['modules']['fields'][$arg['tablename'] .'.'. $arg['field']], $arg['tablename'], $arg['field'], $arg['label'], $arg['handler'], $arg['sortable'], $arg['defaultsort'], $arg['options'], $i);
   }
 
   foreach ($view->filter as $i => $arg) {
     if (is_array($arg['value'])) {
       $arg['value'] = implode(',', $arg['value']);
     }
-    db_query("INSERT INTO {view_filter} (vid, tablename, field, value, operator, options, position) VALUES (%d, '%s', '%s', '%s', '%s', '%s', %d)", $view->vid, $arg['tablename'], $arg['field'], $arg['value'], $arg['operator'], $arg['options'], $i);
+    db_query("INSERT INTO {view_filter} (vid, module, tablename, field, value, operator, options, position) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', %d)", $view->vid, $tables['modules']['filters'][$arg['field']], $arg['tablename'], $arg['field'], $arg['value'], $arg['operator'], $arg['options'], $i);
   }
 
   foreach ($view->exposed_filter as $i => $arg) {
-    db_query("INSERT INTO {view_exposed_filter} (vid, field, label, optional, is_default, single, operator, position) VALUES (%d, '%s', '%s', %d, %d, %d, %d, %d)", $view->vid, $arg['field'], $arg['label'], $arg['optional'], $arg['is_default'], $arg['single'], $arg['operator'], $i);
+    db_query("INSERT INTO {view_exposed_filter} (vid, module, field, label, optional, is_default, single, operator, position) VALUES (%d, '%s', '%s', '%s', %d, %d, %d, %d, %d)", $view->vid, $tables['modules']['filters'][$arg['field']], $arg['field'], $arg['label'], $arg['optional'], $arg['is_default'], $arg['single'], $arg['operator'], $i);
   }
   cache_clear_all('views_urls', 'cache_views');
   cache_clear_all(); // clear the page cache as well.
@@ -2143,4 +2144,81 @@
 // An implementation of hook_devel_caches() from devel.module. Must be in views.module so it always is included.
 function views_devel_caches() {
   return array('cache_views');
+}
+
+/**
+ * Find all of a module's fields, filters, and arguments that are actually used in views.
+ */
+function views_get_module_fields($module) {
+  $tables = array('view_tablefield', 'view_filter', 'view_exposed_filter', 'view_argument', 'view_sort');
+  $fields = array();
+  foreach ($tables as $table) {
+    switch ($table) {
+      case 'view_filter':
+      case 'view_exposed_filter':
+      case 'view_sort':
+        $result = db_query("SELECT vid, field FROM {". $table ."} WHERE module='%s'", $module);
+        while($row = db_fetch_array($result)) {
+          $fields[$table][$row['vid']][] = $row['field'];
+        }
+        break;
+      case 'view_argument':
+        $result = db_query("SELECT vid, type FROM {". $table ."} WHERE module='%s'", $module);
+        while($row = db_fetch_array($result)) {
+          $fields[$table][$row['vid']][] = $row['type'];
+        }
+        break;
+      case 'view_tablefield':
+        $parts = explode('.', $field_name);
+        $result = db_query("SELECT vid, tablename, field FROM {". $table ."} WHERE module='%s'", $module);
+        while($row = db_fetch_array($result)) {
+          $fields[$table][$row['vid']][] = $row['tablename'] .'.'. $row['field'];
+        }
+        break;
+    }
+  }
+  return $fields;
+}
+
+/**
+ * Remove one or all of a module's fields, filters, and arguments from views.
+ */
+function views_delete_module_fields($module, $field_name = NULL) {
+  $tables = array('view_tablefield', 'view_filter', 'view_exposed_filter', 'view_argument', 'view_sort');
+  foreach ($tables as $table) {
+    if (empty($field_name)) {
+      db_query("DELETE FROM {". $table ." WHERE module='%s'", $module);
+    }
+    else {
+      switch ($table) {
+        case 'view_filter':
+        case 'view_exposed_filter':
+        case 'view_sort':
+          db_query("DELETE FROM {". $table ." WHERE module='%s' AND field='%s'", $module, $field_name);
+          break;
+        case 'view_argument':
+          db_query("DELETE FROM {". $table ." WHERE module='%s' AND type='%s'", $module, $field_name);
+          break;
+        case 'view_tablefield':
+          $parts = explode('.', $field_name);
+          db_query("DELETE FROM {". $table ." WHERE module='%s' AND tablename='%s' AND field='%s'", $module, $parts[0], $parts[1]);
+          break;
+      }
+    }
+  }
+}
+
+/**
+ * Pull up and save all current views.
+ * Use to update tables when fields, filters, or arguments may have changed.
+ */
+function views_save_all() {
+  views_load_cache();
+  views_invalidate_cache();
+  $result = db_query("SELECT name from {view_view}");
+  while ($name = db_fetch_object($result)) {
+    $view = views_get_view($name->name);
+    views_sanitize_view($view);
+    _views_save_view($view);
+  }
 }
\ No newline at end of file
Index: views_cache.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/Attic/views_cache.inc,v
retrieving revision 1.2.2.18
diff -u -r1.2.2.18 views_cache.inc
--- views_cache.inc	14 Jul 2007 19:12:02 -0000	1.2.2.18
+++ views_cache.inc	25 Oct 2007 04:04:11 -0000
@@ -23,7 +23,7 @@
  * are only constructed once per run.
  */
 function _views_get_arguments($titles = false) {
-  static $views_arguments;
+  //static $views_arguments;
   global $locale;
 
   if (!$views_arguments) {
@@ -33,7 +33,16 @@
       $views_arguments = $cache;
     }
     else {
-      $arguments = module_invoke_all('views_arguments');
+      //$arguments = module_invoke_all('views_arguments');
+      $arguments = array();
+      foreach (module_implements('views_arguments') as $module) {
+        $function = $module . '_views_arguments';
+        $add = $function();
+        foreach ($add as $name => $arg) {
+          $add[$name]['module'] = $module;
+        }
+        $arguments += $add;
+      }
       // allow modules to alter the definitions supplied others
       foreach (module_implements('views_arguments_alter') as $module) {
         $function = $module . '_views_arguments_alter';
@@ -52,6 +61,7 @@
         }
         $views_arguments['base'][$name] = $arg['name'];
         $views_arguments['title'][$name] = $arg;
+        $views_arguments['title']['modules'][$name] = $arg['module'];
       }
       $cache = $views_arguments;
       cache_set("views_arguments:$locale", 'cache_views', serialize($cache));
@@ -65,7 +75,7 @@
  * so that it will only be called once per run.
  */
 function _views_get_tables($full = false) {
-  static $views_tables;
+  //static $views_tables;
   global $locale;
 
   if (!$views_tables) {
@@ -76,17 +86,26 @@
       $views_tables = $cache;
     }
     else {
-      $table_data = module_invoke_all('views_tables');
-      
+      $table_data = array();
+      foreach (module_implements('views_tables') as $module) {
+        $function = $module . '_views_tables';
+        $add = $function();
+        foreach ($add as $name => $table) {
+          $add[$name]['module'] = $module;
+        }
+        $table_data += $add;
+      }
+
       // allow modules to alter the definitions supplied others
       foreach (module_implements('views_tables_alter') as $module) {
         $function = $module . '_views_tables_alter';
         $function($table_data);
       }
-      
+
       $views_tables['tables'] = $table_data;
 
       foreach ($table_data as $name => $table) {
+        $module = $table['module'];
         if (is_array($table['filters'])) {
           foreach ($table['filters'] as $filter => $data) {
             $data['table'] = $name;
@@ -110,6 +129,7 @@
             }
             $views_tables['filters']['titles']["$name.$filter"] = $data['name'];
             $views_tables['filters']['base']["$name.$filter"] = $data;
+            $views_tables['modules']['filters']["$name.$filter"] = $module;
           }
         }
         if (is_array($table['fields'])) {
@@ -125,6 +145,7 @@
             $data['table'] = $name;
             $views_tables['fields']['titles']["$name.$field"] = $data['name'];
             $views_tables['fields']['base']["$name.$field"] = $data;
+            $views_tables['modules']['fields']["$name.$field"] = $module;
           }
         }
         if (is_array($table['sorts'])) {
@@ -140,6 +161,7 @@
             }
             $views_tables['sorts']['titles']["$name.$field"] = $data['name'];
             $views_tables['sorts']['base']["$name.$field"] = $data;
+            $views_tables['modules']['sorts']["$name.$field"] = $module;
           }
         }
       }
Index: views.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/views.install,v
retrieving revision 1.21.4.16
diff -u -r1.21.4.16 views.install
--- views.install	14 Jul 2007 22:16:50 -0000	1.21.4.16
+++ views.install	25 Oct 2007 02:40:01 -0000
@@ -60,6 +60,7 @@
 
       db_query("CREATE TABLE if not exists {view_sort} (
         vid int(10) unsigned NOT NULL default '0',
+        module varchar(255),
         position int(2),
         field varchar(255),
         sortorder varchar(5),
@@ -70,6 +71,7 @@
 
       db_query("CREATE TABLE if not exists {view_argument} (
         vid int(10) unsigned NOT NULL default '0',
+        module varchar(255),
         type varchar(255),
         argdefault varchar(255),
         title varchar(255),
@@ -82,6 +84,7 @@
 
       db_query("CREATE TABLE if not exists {view_tablefield} (
         vid int(10) unsigned NOT NULL default '0',
+        module varchar(255),
         tablename varchar(255),
         field varchar(255),
         label varchar(255),
@@ -95,6 +98,7 @@
 
       db_query("CREATE TABLE if not exists {view_filter} (
         vid int(10) unsigned NOT NULL default '0',
+        module varchar(255),
         tablename varchar(255),
         field varchar(255),
         value longtext,
@@ -106,6 +110,7 @@
 
       db_query("CREATE TABLE if not exists {view_exposed_filter} (
         vid int(10) unsigned NOT NULL default '0',
+        module varchar(255),
         field varchar(255),
         label varchar(255),
         optional int(1),
@@ -145,7 +150,7 @@
         page_footer_format smallint NOT NULL,
         page_type varchar(20),
         use_pager smallint,
-        nodes_per_page smallint, 
+        nodes_per_page smallint,
         url varchar(255),
         -- menu fields
         menu smallint,
@@ -395,7 +400,7 @@
       $ret[] = update_sql("ALTER TABLE {view_view} MODIFY nodes_per_page smallint");
       break;
   }
-  
+
   return $ret;
 }
 
@@ -454,7 +459,7 @@
 
 function views_update_14() {
   $ret = array();
-  views_make_cache_table($ret); 
+  views_make_cache_table($ret);
   $ret[] = update_sql("DELETE FROM {cache_views}");
   return $ret;
 }
@@ -481,6 +486,16 @@
   return $ret;
 }
 
+function views_update_17() {
+  $ret = array();
+  db_add_column($ret, 'view_tablefield', 'module', 'varchar(255)');
+  db_add_column($ret, 'view_filter', 'module', 'varchar(255)');
+  db_add_column($ret, 'view_exposed_filter', 'module', 'varchar(255)');
+  db_add_column($ret, 'view_sort', 'module', 'varchar(255)');
+  db_add_column($ret, 'view_argument', 'module', 'varchar(255)');
+  views_invalidate_cache();
+  return $ret;
+}
 /**
  * This should go in every update to ensure that it's there from a 4.7 -> 5.x
  * update.
