Index: devel_generate.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/devel/devel_generate.inc,v
retrieving revision 1.5
diff -u -F^f -b -r1.5 devel_generate.inc
--- devel_generate.inc	17 Jul 2007 17:17:11 -0000	1.5
+++ devel_generate.inc	19 Jul 2007 14:38:41 -0000
@@ -168,6 +168,127 @@ function devel_create_comments($records,
   return $cids;
 }
 
+function devel_generate_vocabs($records, $maxlength = 12, $types = array('story', 'blog', 'forum', 'page')) {
+  $vocs = array();
+
+  // Insert new data:
+  for ($i = 1; $i <= $records; $i++) {
+    $voc = array();
+    $voc['name'] = devel_generate_word(rand(2, $maxlength));
+    $voc['description'] = "description of ". $voc['name'];
+    $voc['nodes'] = array_flip(array($types[array_rand($types)]));
+    foreach ($voc['nodes'] as $key => $value) {
+      $voc['nodes'][$key] = $key;
+    }
+    $voc['multiple'] = 1;
+    $voc['required'] = 0;
+    $voc['relations'] = 1;
+    $voc['hierarchy'] = 1;
+    $voc['weight'] = rand(0,10);
+
+    taxonomy_save_vocabulary($voc);
+    $vocs[] = $voc['name'];
+  }
+  return $vocs;
+}
+
+function devel_generate_terms($records, $vocs, $maxlength = 12) {
+  $terms = array();
+
+  // Insert new data:
+  for ($i = 1; $i <= $records; $i++) {
+    switch ($i % 2) {
+      case 1:
+        $term['vid'] = $vocs[array_rand($vocs)];
+        // dont set a parent. handled by taxonomy_save_term()
+        // $term->parent = 0;
+        break;
+      case 2:
+      default:
+        $parent = db_fetch_object(db_query_range("SELECT t.tid, v.vid FROM {term_data} t INNER JOIN {vocabulary} v ON t.vid = v.vid ORDER BY RAND()", 0, 1));
+        $term['parent'] = array($parent->tid);
+        $term['vid'] = $parent->vid;
+        break;
+    }
+
+    $term['name'] = devel_generate_word(rand(2, $maxlength));
+    $term['description'] = "description of ". $term['name'];
+    $term['weight'] = rand(0,10);
+
+    $status = taxonomy_save_term($term);
+    $output = NULL;
+
+    if ($status) {
+      $terms[] = $term['name'];
+    }
+
+    unset($term);
+  }
+  return $terms;
+}
+
+function devel_generate_get_vocabs() {
+  $vocs = array();
+  $result = db_query("SELECT vid FROM {vocabulary}");
+  while($voc = db_fetch_object($result)){
+    $vocs[] = $voc->vid;
+  }
+  return $vocs;
+}
+
+function devel_generate_taxonomy_data($num_vocab, $num_terms, $title_length, $kill) {
+
+  if ($kill) {
+    db_query("DELETE FROM {term_data}");
+    db_query("DELETE FROM {term_node}");
+    db_query("DELETE FROM {term_hierarchy}");
+    db_query("DELETE FROM {term_relation}");
+    db_query("DELETE FROM {term_synonym}");
+    db_query("DELETE FROM {vocabulary}");
+    db_query("DELETE FROM {vocabulary_node_types}");
+    switch ($GLOBALS['db_type']) {
+      case 'mysql':
+      case 'mysqli':
+        db_query("ALTER TABLE {vocabulary} AUTO_INCREMENT = 1");
+        db_query("ALTER TABLE {term_data} AUTO_INCREMENT = 1");
+        break;
+      case 'pgsql':
+        db_query("SELECT setval('{vocabulary}_vid_seq', 1, false)");
+        db_query("SELECT setval('{term_data}_tid_seq', 1, false)");
+        break;
+    }
+    drupal_set_message(t('Deleted taxonomy.'));
+  }
+
+  $new_vocs = devel_generate_vocabs($num_vocab, $title_length);
+  if (!empty($new_vocs)) {
+    drupal_set_message(t('Created the following new vocabularies: !vocs', array('!vocs' => theme('item_list', $new_vocs))));
+  }
+  $vocs = devel_generate_get_vocabs();
+  $new_terms = devel_generate_terms($num_terms, $vocs, $title_length);
+  if (!empty($new_terms)) {
+    drupal_set_message(t('Created the following new terms: !terms', array('!terms' => theme('item_list', $new_terms))));
+  }
+}
+
+function devel_generate_word($length){
+  srand((double)microtime()*1000000);
+
+  $vowels = array("a", "e", "i", "o", "u");
+  $cons = array("b", "c", "d", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "u", "v", "w", "tr",
+  "cr", "br", "fr", "th", "dr", "ch", "ph", "wr", "st", "sp", "sw", "pr", "sl", "cl", "sh");
+
+  $num_vowels = count($vowels);
+  $num_cons = count($cons);
+  $word = '';
+
+  while(strlen($word) < $length){
+    $word .= $cons[rand(0, $num_cons - 1)] . $vowels[rand(0, $num_vowels - 1)];
+  }
+
+  return substr($word, 0, $length);
+}
+
 function devel_create_content() {
   $nparas = rand(1,12);
   $type = rand(0,3);
Index: devel_generate.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/devel/devel_generate.module,v
retrieving revision 1.5
diff -u -F^f -b -r1.5 devel_generate.module
--- devel_generate.module	17 Jul 2007 17:17:11 -0000	1.5
+++ devel_generate.module	19 Jul 2007 14:38:41 -0000
@@ -68,24 +68,6 @@ function devel_generate_users_form_submi
   devel_create_users($form_state['values']['num'], $form_state['values']['kill_users']);
 }
 
-function devel_generate_word($length){
-  srand((double)microtime()*1000000); 
-  
-  $vowels = array("a", "e", "i", "o", "u"); 
-  $cons = array("b", "c", "d", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "u", "v", "w", "tr", 
-  "cr", "br", "fr", "th", "dr", "ch", "ph", "wr", "st", "sp", "sw", "pr", "sl", "cl", "sh"); 
-   
-  $num_vowels = count($vowels); 
-  $num_cons = count($cons); 
-  $word = '';
-  
-  while(strlen($word) < $length){ 
-    $word .= $cons[rand(0, $num_cons - 1)] . $vowels[rand(0, $num_vowels - 1)]; 
-  } 
-
-  return substr($word, 0, $length);
-}
-
 function devel_generate_content_form() {
   $form['num_nodes'] = array(
     '#type' => 'textfield',
@@ -122,75 +104,6 @@ function devel_generate_content_form_sub
   devel_generate_content($form_state['values']['num_nodes'], $form_state['values']['num_comments'], $form_state['values']['title_length'], $form_state['values']['kill_content']);
 }
 
-function devel_generate_vocabs($records, $maxlength = 12) {
-  $types = array("story", "blog", "forum", "page");
-  $output = NULL;
-  // Insert new data:
-  for ($i = 1; $i <= $records; $i++) {
-    $voc = array();
-    $voc['name'] = devel_generate_word(rand(2, $maxlength));
-    $voc['description'] = "description of ". $voc['name'];
-    $voc['nodes'] = array_flip(array($types[array_rand($types)]));
-    foreach ($voc['nodes'] as $key => $value) {
-      $voc['nodes'][$key] = $key;
-    }
-    $voc['multiple'] = 1;
-    $voc['required'] = 0;
-    $voc['relations'] = 1;
-    $voc['hierarchy'] = 1;
-    $voc['weight'] = rand(0,10);    
-
-    taxonomy_save_vocabulary($voc);
-    $output .= "created vocabulary ". $voc['name']. "<br />";
-  }
-
-  return $output;
-}
-
-function devel_generate_terms($records, $vocs, $maxlength = 12) {
-  // Insert new data:
-  for ($i = 1; $i <= $records; $i++) {
-    switch ($i % 2) {
-      case 1:
-        $term['vid'] = $vocs[array_rand($vocs)];
-        // dont set a parent. handled by taxonomy_save_term()
-        // $term->parent = 0;
-        break;
-      case 2:
-      default:
-        $parent = db_fetch_object(db_query_range("SELECT t.tid, v.vid FROM {term_data} t INNER JOIN {vocabulary} v ON t.vid = v.vid ORDER BY RAND()", 0, 1));
-        $term['parent'] = array($parent->tid);
-        $term['vid'] = $parent->vid;
-        break;
-    }
-
-    $term['name'] = devel_generate_word(rand(2, $maxlength));
-    $term['description'] = "description of ". $term['name'];
-    $term['weight'] = rand(0,10);
-
-    $status = taxonomy_save_term($term);
-    $output = NULL;
-    
-    if ($status) {
-      $output .= t("Created term @term", array('@term' => $term['name'])). "<br />";
-    }
-    else {
-      $output .= t("There was an error creating term @term", array('@term' => $term['name'])). "<br />";
-    }
-    unset($term);
-  }
-  return $output;
-}
-
-function devel_generate_get_vocabs() {
-  $vocs = array();
-  $result = db_query("SELECT vid FROM {vocabulary}");
-  while($voc = db_fetch_object($result)){
-    $vocs[] = $voc->vid;
-  }
-  return $vocs;
-}
-
 function devel_generate_taxonomy_form() {
   $form['num_vocab'] = array(
     '#type' => 'textfield',
@@ -204,17 +117,17 @@ function devel_generate_taxonomy_form() 
     '#default_value' => 50,
     '#size' => 10,
   );
-  $form['kill_taxonomy'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Delete existing terms and vocabularies before generating new content.'),
-    '#default_value' => FALSE,  
-  );
   $form['title_length'] = array(
     '#type' => 'textfield',
     '#title' => t('Max word length of term/vocab names'),
     '#default_value' => 12,
     '#size' => 10,
   );
+  $form['kill_taxonomy'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Delete existing terms and vocabularies before generating new content.'),
+    '#default_value' => FALSE,
+  );
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Do it!'),
@@ -223,24 +136,6 @@ function devel_generate_taxonomy_form() 
 }
 
 function devel_generate_taxonomy_form_submit($form_id, &$form_state) {
-  $vocs = array();
-  $result = db_query("SELECT vid FROM {vocabulary}");
-  while($voc = db_fetch_object($result)){
-    $vocs[] = $voc->vid;
-  }
-
-  if ($form_state['values']['kill_taxonomy']) {
-    db_query("DELETE FROM {term_data}");
-    db_query("DELETE FROM {term_node}");
-    db_query("DELETE FROM {term_hierarchy}");
-    db_query("DELETE FROM {term_relation}");
-    db_query("DELETE FROM {term_synonym}");
-    db_query("DELETE FROM {vocabulary}");
-    db_query("DELETE FROM {vocabulary_node_types}");
-  }
-
-  $output = devel_generate_vocabs($form_state['values']['num_vocab'], $form_state['values']['title_length']);
-  $vocs = devel_generate_get_vocabs();
-  $output .= devel_generate_terms($form_state['values']['num_terms'], $vocs, $form_state['values']['title_length']);
-  drupal_set_message($output);
+  require_once('devel_generate.inc');
+  devel_generate_taxonomy_data($form_state['values']['num_vocab'], $form_state['values']['num_terms'], $form_state['values']['title_length'], $form_state['values']['kill_taxonomy']);
 }
