Index: modules/taxonomy/taxonomy.install =================================================================== RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.install,v retrieving revision 1.43 diff -u -p -r1.43 taxonomy.install --- modules/taxonomy/taxonomy.install 23 May 2010 19:10:23 -0000 1.43 +++ modules/taxonomy/taxonomy.install 4 Jun 2010 19:42:50 -0000 @@ -423,14 +423,38 @@ function taxonomy_update_7005(&$sandbox) $query = db_select('taxonomy_term_node', 't'); $sandbox['total'] = $query->countQuery()->execute()->fetchField(); $found = (bool) $sandbox['total']; + $result = db_query('SELECT v.*, n.type FROM {taxonomy_vocabulary} v LEFT JOIN {taxonomy_vocabulary_node_type} n ON v.vid = n.vid ORDER BY v.weight, v.name'); + $vocabularies = array(); + foreach ($result as $record) { + // If no node types are associated with a vocabulary, the LEFT JOIN will + // return a NULL value for type. + if (isset($record->type)) { + $node_types[$record->vid][$record->type] = $record->type; + unset($record->type); + $record->nodes = $node_types[$record->vid]; + } + elseif (!isset($record->nodes)) { + $record->nodes = array(); + } + $vocabularies[$record->vid] = $record; + } + if (!empty($vocabularies)) { + $sandbox['vocabularies'] = $vocabularies; + } } else { + // Grab the current (first) vocabulary. When this vocabulary's terms have + // all been updated, it will be removed from the sandbox. + $vid = key(reset($sandbox['vocabularies'])); + $vocabulary = $sandbox['vocabularies'][$vid]; + // We do each pass in batches of 1000, this should result in a // maximum of 2000 insert queries each operation. $batch = 1000 + $sandbox['last']; // Query and save data for the current revision. $result = db_query_range('SELECT td.tid, tn.nid, td.weight, tn.vid, n2.type, n2.created, n2.sticky FROM {taxonomy_term_data} td INNER JOIN {taxonomy_term_node} tn ON td.tid = tn.tid INNER JOIN {node} n2 ON tn.nid = n2.nid INNER JOIN {node} n ON tn.vid = n.vid AND td.vid = :vocabulary_id ORDER BY td.weight ASC', array(':vocabulary_id' => $vocabulary->vid), $sandbox['last'], $batch); + $deltas = array(); foreach ($result as $record) { $found = TRUE; @@ -460,9 +484,25 @@ function taxonomy_update_7005(&$sandbox) db_insert($revision_table)->fields($columns)->values($values)->execute(); } $sandbox['last'] = $batch; + + // If there were no rows returned, we're finished with the current vocab. + // Advance vid counter and reset batch counter or fall through and finish + // if there are no vocabularies left. + if (!$found) { + unset($sandbox['vocabularies'][$vid]); + if (!empty($sandbox['vocabularies'])) { + $found = TRUE; + $sandbox['last'] = 0; + } + } } if (!$found) { - db_drop_table('taxonomy_term_node'); + db_drop_table('taxonomy_term_node'); + // If there are no vocabs, we're done. + $sanbox['#finished'] = TRUE; + } + else { + $sandbox['#finished'] = FALSE; } }