summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--devel_generate.inc77
-rw-r--r--devel_generate.module39
2 files changed, 39 insertions, 77 deletions
diff --git a/devel_generate.inc b/devel_generate.inc
index 606aa40..58b913a 100644
--- a/devel_generate.inc
+++ b/devel_generate.inc
@@ -31,54 +31,12 @@ function devel_create_users($num, $kill) {
drupal_set_message(t('!num_users created.', array('!num_users' => format_plural($num, '1 user', '@count users'))));
}
-function devel_generate_content($num_nodes, $num_comments, $title_length, $kill) {
+function devel_generate_content($num_nodes, $num_comments, $title_length, $kill, $node_types = array()) {
if ($kill) {
- db_query("DELETE FROM {comments}");
- db_query("DELETE FROM {node}");
- db_query("DELETE FROM {node_revisions}");
- db_query("DELETE FROM {node_comment_statistics}");
- if (db_table_exists('term_node')) {
- db_query("DELETE FROM {term_node}");
- }
- if (db_table_exists('forum')) {
- db_query("DELETE FROM {forum}");
- }
- if (db_table_exists('relatedlinks')) {
- db_query("DELETE FROM {relatedlinks}");
- db_query("DELETE FROM {relatedlinks_tracker}");
- }
- if (db_table_exists('nodequeue_nodes')) {
- db_query("DELETE FROM {nodequeue_nodes}");
- }
- db_query("DELETE FROM {url_alias}");
- switch ($GLOBALS['db_type']) {
- case 'mysql':
- case 'mysqli':
- db_query("UPDATE {sequences} SET id = '0' WHERE name = '{node}_nid'");
- db_query("UPDATE {sequences} SET id = '0' WHERE name = '{comments}_cid'");
- db_query("ALTER TABLE {node} AUTO_INCREMENT = 1");
- db_query("ALTER TABLE {comments} AUTO_INCREMENT = 1");
- break;
- case 'pgsql':
- db_query("SELECT setval('{node}_nid_seq', 1, false)");
- db_query("SELECT setval('{comments}_cid_seq', 1, false)");
- break;
- }
- drupal_set_message(t('Content deleted.'));
- }
- else {
- // Get the next nid without incrementing it.
- switch ($GLOBALS['db_type']) {
- case 'mysql':
- case 'mysqli':
- $next_nid = db_result(db_query("SELECT id FROM {sequences} WHERE name = '{node}_nid'")) + 1;
- break;
- case 'pgsql':
- // This little trick is necessery, as the currval() function won't work until the nextval()
- // function is called in the current session.
- $next_nid = db_result(db_query("SELECT nextval('{node}_nid_seq')"));
- db_query("SELECT setval('{node}_nid_seq', %d, false)", $next_nid);
- break;
+ $sql = 'SELECT nid FROM {node} WHERE type IN ('. implode(', ', array_fill(0, count($node_types), "'%s'")). ')';
+ $result = db_query($sql, $node_types);
+ while ($row = db_fetch_object($result)) {
+ node_delete($row->nid);
}
}
@@ -86,7 +44,7 @@ function devel_generate_content($num_nodes, $num_comments, $title_length, $kill)
$users = devel_get_users();
// Create $num_nodes pseudo-random nodes.
- devel_create_nodes($num_nodes, $users, $title_length);
+ devel_create_nodes($num_nodes, $users, $title_length, $node_types);
drupal_set_message(t('%num nodes created.', array('%num' => $num_nodes)));
$nodes = devel_get_nodes($next_nid);
@@ -97,28 +55,7 @@ function devel_generate_content($num_nodes, $num_comments, $title_length, $kill)
drupal_set_message(t('%num comments created.', array('%num' => $num_comments)));
}
-function devel_create_nodes($records, $users, $title_length = 8) {
-
- $sql = "SELECT type FROM node_type WHERE module IN ('node', 'forum')";
- $result = db_query($sql);
- while ($row = db_fetch_object($result)) {
- $possible_types[] = $row->type;
- }
-
- // For now, eliminate types which have any CCK fields. Help wanted.
- if (module_exists('content')) {
- $fields = content_fields();
- foreach ($fields as $field) {
- $ineligible[] = $field['type_name'];
- }
- $possible_types = array_diff($possible_types, $ineligible);
- }
-
- // Only use types that exist.
- $installed_types = array_keys(node_get_types('types'));
- $types = array_intersect($possible_types, $installed_types);
-
- $users = array_merge($users, array('0'));
+function devel_create_nodes($records, $users, $title_length = 8, $types = array()) {
if (is_array($types)) {
// Insert new data:
diff --git a/devel_generate.module b/devel_generate.module
index 794cd0c..253aaa2 100644
--- a/devel_generate.module
+++ b/devel_generate.module
@@ -79,10 +79,40 @@ function devel_generate_users_form_submit($form_id, $form_values) {
}
function devel_generate_content_form() {
+ if (module_exists('content')) {
+ $types = content_types();
+ $warn = '';
+ foreach ($types as $type) {
+ if (count($type['fields'])) {
+ $warn = t('. <strong>Warning</strong>. This type contains CCK fields which won\'t be populated. See !url', array('!url' => l(t('this CCK issue.'), 'http://drupal.org/node/187599')));
+ }
+ $options[$type['type']] = t($type['name']). $warn;
+ unset($warn);
+ }
+
+ }
+ else {
+ $types = node_get_types();
+ foreach ($types as $type) {
+ $options[$type->type] = t($type->name);
+ }
+ }
+ $form['node_types'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Which node types do you want to create?'),
+ '#options' => $options,
+ '#default_value' => array_keys($options),
+ );
+ $form['kill_content'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('<strong>Delete existing content</strong> before generating new content.'),
+ '#default_value' => FALSE,
+ );
+
$form['num_nodes'] = array(
'#type' => 'textfield',
'#title' => t('How many nodes would you like to generate?'),
- '#default_value' => 100,
+ '#default_value' => 50,
'#size' => 10,
);
$form['num_comments'] = array(
@@ -97,11 +127,6 @@ function devel_generate_content_form() {
'#default_value' => 8,
'#size' => 10,
);
- $form['kill_content'] = array(
- '#type' => 'checkbox',
- '#title' => t('Delete existing content before generating new content.'),
- '#default_value' => FALSE,
- );
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Do it!'),
@@ -111,7 +136,7 @@ function devel_generate_content_form() {
function devel_generate_content_form_submit($form_id, $form_values) {
require_once('devel_generate.inc');
- devel_generate_content($form_values['num_nodes'], $form_values['num_comments'], $form_values['title_length'], $form_values['kill_content']);
+ devel_generate_content($form_values['num_nodes'], $form_values['num_comments'], $form_values['title_length'], $form_values['kill_content'], array_filter($form_values['node_types']));
}
function devel_generate_taxonomy_form() {