Index: content_views.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/content_views.inc,v
retrieving revision 1.2.2.5
diff -u -r1.2.2.5 content_views.inc
--- content_views.inc	5 Jan 2007 11:57:46 -0000	1.2.2.5
+++ content_views.inc	19 Jan 2007 20:04:07 -0000
@@ -66,6 +66,9 @@
         $table['sorts'][$main_column['column']] = array(
           'name' => $field_types[$field['type']]['label'] .': '. $field['widget']['label'] .' ('. $field['field_name'] .')',
           'field' => $main_column['column'],
+          'content_db_info' => $db_info,
+          'content_field' => $field,
+          'content_field_module' => $module,
         );
       }
 
@@ -82,6 +85,9 @@
           $init = array(
             'name' => $name,
             'field' => $main_column['column'],
+            'content_db_info' => $db_info,
+            'content_field' => $field,
+            'content_field_module' => $module,
           );
           $table['filters'][$main_column['column'] .'_'. $key] = array_merge($filter, $init);
         }
@@ -250,30 +256,53 @@
 }
 
 /**
- * Rebuild the cached queries for the views using a given field
- * used when a field changes its 'multiple' status
- * plus helper function for updates
+ * Rebuild the cached queries for the views using a given field.
+ * Called when a field changes its 'multiple' status.
+ * Can also be useful for updates.
  *
  * @param unknown_type $update_fields
  */
+
 function _content_views_rebuild_views($update_fields) {
+  $updated_views = array();
   views_load_cache();
-  $tables = _views_get_tables();
+  $tables = _views_get_tables(true);
   $result = db_query("SELECT name, query FROM {view_view} ORDER BY name");
+  // TODO : do we have to do that for default views as well ?
   while ($row = db_fetch_array($result)) {
     // if a query has been stored for the view
     if (!empty($row['query'])) {
       $view = views_get_view($row['name']);
-      // TODO : check for arguments / sorts / filters as well ?
+      $view_content_fields = array();
+
       foreach ($view->field as $field) {
-        // if the view contains one of the fields that require updating
-        $field_info = $tables[$field['tablename']]['fields'][$field['field']];
-        if (isset($field_info['content_field']) && in_array($field_info['content_field']['field_name'], $update_fields)) {
-          // re-save the view (forces the query to be updated)
-          _views_save_view($view);
-          break;
+        $info = $tables['fields']['base'][$field['fullname']];
+        if (isset($info['content_field'])) {
+          $view_content_fields[] = $info['content_field']['field_name'];
+        }
+      }
+
+      foreach ($view->filter as $filter) {
+        $info = $tables['filters']['base'][$filter['field']];
+        if (isset($info['content_field'])) {
+          $view_content_fields[] = $info['content_field']['field_name'];
         }
       }
+
+      foreach ($view->sort as $sort) {
+        $info = $tables['sorts']['base'][$sort['field']];
+        if (isset($info['content_field'])) {
+          $view_content_fields[] = $info['content_field']['field_name'];
+        }
+      }
+
+      // no need to check arguments : a view with arguments is not cacheable
+
+      if (count(array_intersect($view_content_fields, $update_fields))) {
+        _views_save_view($view);
+        $updated_views[] = $view->name;
+      }
     }
   }
+  return $updated_views;
 }
Index: content.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/content.install,v
retrieving revision 1.14.2.9
diff -u -r1.14.2.9 content.install
--- content.install	21 Jan 2007 16:50:30 -0000	1.14.2.9
+++ content.install	24 Jan 2007 00:50:32 -0000
@@ -307,3 +307,75 @@
 
   return $ret;
 }
+
+/**
+ *  Rename data tables to avoid collision with core node_* tables
+ */
+function content_update_1003() {
+  $ret = array();
+
+  include_once('./'. drupal_get_path('module', 'content') .'/content.module');
+  include_once('./'. drupal_get_path('module', 'content') .'/content_admin.inc');
+
+  $rename = array();
+
+  $types = content_types();
+  $fields = content_fields();
+
+  // "per content type" tables
+  foreach ($types as $type) {
+    $old_name = _content_tablename($type['type'], CONTENT_DB_STORAGE_PER_CONTENT_TYPE);
+    $new_name = _content_tablename($type['type'], CONTENT_DB_STORAGE_PER_CONTENT_TYPE, 1003);
+    if (db_table_exists($old_name)) {
+      if (!in_array($old_name, array('node_access',  'node_comments_statistics', 'node_counter', 'node_field', 'node_field_instance', 'node_group', 'node_group_fields', 'node_revisions', 'node_type'))) {
+        $rename[$old_name] = $new_name;
+      }
+      else {
+        // TODO : what ? create the table ?
+      }
+    }
+  }
+
+  // "per field" tables
+  foreach ($fields as $field) {
+    $old_name = _content_tablename($field['field_name'], CONTENT_DB_STORAGE_PER_FIELD);
+    $new_name = _content_tablename($field['field_name'], CONTENT_DB_STORAGE_PER_FIELD, 1003);
+    $old_name = 'node_data_'.$field['field_name'];
+    $new_name = 'content_'. $field['field_name'];
+    if (db_table_exists($old_name)) {
+      $rename[$old_name] = $new_name;
+    }
+  }
+
+  // rename
+  foreach ($rename as $old_name => $new_name) {
+    switch ($GLOBALS['db_type']) {
+      case 'mysql':
+      case 'mysqli':
+        $ret[] = update_sql("RENAME TABLE {$old_name} TO {$new_name}");
+        break;
+
+      case 'pgsql':
+        $ret[] = update_sql("ALTER TABLE {$old_name} RENAME TO {$new_name}");
+        break;
+    }
+  }
+
+
+  // regenerate views
+  content_clear_type_cache();
+  if (module_exists('views')) {
+    include_once('./'. drupal_get_path('module', 'content') .'/content_views.inc');
+    $updated_views = _content_views_rebuild_views(array_keys(content_fields()));
+    foreach ($updated_views as $view) {
+      $ret[] = array(
+        'query' => strtr('The views %view has been regenerated.', array('%view' => $view)),
+        'success' => TRUE
+      );
+    }
+  }
+
+  variable_set('content_schema_version', 1003);
+
+  return $ret;
+}
Index: content.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/content.module,v
retrieving revision 1.90.2.29
diff -u -r1.90.2.29 content.module
--- content.module	23 Jan 2007 22:58:38 -0000	1.90.2.29
+++ content.module	24 Jan 2007 00:54:12 -0000
@@ -769,11 +769,11 @@
         $info['fields'][$field['field_name']] = $field;
       }
 
-      $type_result = db_query('SELECT * FROM {node_type} nt ORDER BY nt.type ASC');
+      $type_result = db_query('SELECT * FROM {node_type} ORDER BY type ASC');
       while ($type = db_fetch_array($type_result)) {
         $type['url_str'] = str_replace('_', '-', $type['type']);
         $type['fields'] = array();
-        $type['table'] = _content_tablename($type['type']);
+        $type['table'] = _content_tablename($type['type'], CONTENT_DB_STORAGE_PER_CONTENT_TYPE);
         $field_result = db_query("SELECT nfi.field_name, nfi.weight, nfi.label, nfi.widget_type, nfi.widget_settings, nfi.display_settings, nfi.description FROM {node_field_instance} nfi WHERE nfi.type_name = '%s' ORDER BY nfi.weight ASC, nfi.label ASC", $type['type']);
         while ($field = db_fetch_array($field_result)) {
           // Overwrite global field information with specific information
@@ -859,7 +859,7 @@
   $db_info = array();
 
   if ($field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD) {
-    $db_info['table'] = _content_tablename($field['field_name'], 'field');
+    $db_info['table'] = _content_tablename($field['field_name'], CONTENT_DB_STORAGE_PER_FIELD);
   }
   else {
     $type = content_types($field['type_name']);
@@ -998,11 +998,27 @@
  * @return
  *   A string containing the generated name for the database table
  */
-function _content_tablename($name, $entity = 'type') {
-  switch ($entity) {
-    case 'type' :
+function _content_tablename($name, $entity, $version = NULL) {
+  if (is_null($version)) {
+    $version = variable_get('content_schema_version', 0);
+  }
+
+  if ($version < 1003) {
+    $version = 0;
+  }
+  else {
+    $version = 1003;
+  }
+
+  switch ($version .'-'. $entity) {
+    case '0-'. CONTENT_DB_STORAGE_PER_CONTENT_TYPE :
       return 'node_'.$name;
-    case 'field' :
+    case '0-'. CONTENT_DB_STORAGE_PER_FIELD :
       return 'node_data_'.$name;
+    case '1003-'. CONTENT_DB_STORAGE_PER_CONTENT_TYPE :
+      return 'content_type_'.$name;
+    case '1003-'. CONTENT_DB_STORAGE_PER_FIELD :
+      return 'content_'.$name;
   }
 }
+
Index: content_crud.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/content_crud.inc,v
retrieving revision 1.4.2.7
diff -u -r1.4.2.7 content_crud.inc
--- content_crud.inc	7 Jan 2007 00:06:36 -0000	1.4.2.7
+++ content_crud.inc	24 Jan 2007 00:52:14 -0000
@@ -75,7 +75,7 @@
     // Rename the content fields table to match new content type name.
     $old_type = content_types($info->old_type);
     $old_name = $old_type['table'];
-    $new_name = _content_tablename($info->type);
+    $new_name = _content_tablename($info->type, CONTENT_DB_STORAGE_PER_CONTENT_TYPE);
     if (db_table_exists($old_name)) {
       switch ($GLOBALS['db_type']) {
         case 'mysql':
