summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormoshe weitzman2009-12-05 16:10:15 (GMT)
committer moshe weitzman2009-12-05 16:10:15 (GMT)
commitf0713b0ec7d124155c2465c065c313d2c0c4b6e7 (patch)
tree4980ad447f1d8193d5fe0ffe4ce3317011bed39b
parent14bc219fb756e7aabdf4d08ab4781983807ce05d (diff)
#376111 by moshe weitzman. Randomize the number of comments generated per node. Also add support for attaching files and terms to generated nodes. Still seeing errors during node creation though. Help wanted.
-rw-r--r--devel_generate.drush.inc15
-rw-r--r--devel_generate.inc4
-rw-r--r--devel_generate.module10
3 files changed, 17 insertions, 12 deletions
diff --git a/devel_generate.drush.inc b/devel_generate.drush.inc
index 3de8359..99e6e4b 100644
--- a/devel_generate.drush.inc
+++ b/devel_generate.drush.inc
@@ -50,13 +50,16 @@ function devel_generate_drush_command() {
'callback' => 'drush_generate_nodescontent',
'description' => 'Creates content.',
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_LOGIN, // Various D7 code assumes we have a uid.
+ 'drupal dependencies' => array('devel_generate'),
'arguments' => array(
'number_nodes' => 'Number of nodes to generate.',
- 'number_comments' => 'Number of comments to generate.',
+ 'maximum_comments' => 'Maximum number of comments to generate.',
),
'options' => array(
'kill' => 'Specify \'kill\' to delete all content before generating new content.',
'types' => 'A comma delimited list of content types to create. Defaults to page,article.',
+ 'add-terms' => 'Add terms to generated nodes.',
+ 'add-upload' => 'Add an attached file to generated nodes.',
),
);
return $items;
@@ -94,11 +97,11 @@ function drush_generate_tax($num_vocab = NULL, $num_terms = NULL) {
/**
* Command callback. Generate a number of content.
*/
-function drush_generate_nodescontent($num_nodes = NULL, $num_comments = NULL) {
+function drush_generate_nodescontent($num_nodes = NULL, $max_comments = NULL) {
if (drush_generate_is_number($num_nodes) == FALSE) {
drush_set_error('DEVEL_GENERATE_INVALID_INPUT', t('Invalid number of nodes'));
}
- if (!empty($num_comments) && drush_generate_is_number($num_comments) == FALSE) {
+ if (!empty($max_comments) && drush_generate_is_number($max_comments) == FALSE) {
drush_set_error('DEVEL_GENERATE_INVALID_INPUT', t('Invalid number of comments.'));
}
@@ -113,11 +116,13 @@ function drush_generate_nodescontent($num_nodes = NULL, $num_comments = NULL) {
}
$values['values']['title_length'] = '8';
$values['values']['num_nodes'] = $num_nodes;
- $values['values']['num_comments'] = $num_comments;
+ $values['values']['max_comments'] = $max_comments;
+ $values['values']['add_terms'] = drush_get_option('add-terms', FALSE);
+ $values['values']['add_upload'] = drush_get_option('add-upload', FALSE);
$values['values']['node_types'] = drupal_map_assoc(explode(',', drush_get_option('types', 'page,article')));
drush_generate_include_devel();
devel_generate_content($values);
- drush_log(t('Generated @num_nodes nodes, @num_comments comments per node', array('@num_nodes' => (int)$num_nodes, '@num_comments' => (int)$num_comments)), 'success');
+ drush_log(t('Generated @num_nodes nodes, @max_comments comments per node', array('@num_nodes' => (int)$num_nodes, '@max_comments' => (int)$max_comments)), 'success');
}
//////////////////////////////////////////////////////////////////////////////
diff --git a/devel_generate.inc b/devel_generate.inc
index 6a6fa2c..d7cb5df 100644
--- a/devel_generate.inc
+++ b/devel_generate.inc
@@ -123,8 +123,8 @@ function devel_generate_content($form_state) {
drupal_set_message(format_plural($form_state['values']['num_nodes'], '1 node created.', '@count nodes created'));
}
-function devel_generate_add_comments($node, $users, $num_comments, $title_length = 8) {
- // Insert new data:
+function devel_generate_add_comments($node, $users, $max_comments, $title_length = 8) {
+ $num_comments = mt_rand(1, $max_comments);
for ($i = 1; $i <= $num_comments; $i++) {
$comment->nid = $node->nid;
$comment->cid = NULL;
diff --git a/devel_generate.module b/devel_generate.module
index 5ef7263..651bcab 100644
--- a/devel_generate.module
+++ b/devel_generate.module
@@ -137,9 +137,9 @@ function devel_generate_content_form() {
'#default_value' => 604800,
);
- $form['num_comments'] = array(
+ $form['max_comments'] = array(
'#type' => module_exists('comment') ? 'textfield' : 'value',
- '#title' => t('How many comments per node would you like to generate?'),
+ '#title' => t('Maximum number of comments per node.'),
'#description' => t('You must also enable comments for the node types you are generating.'),
'#default_value' => 0,
'#size' => 3,
@@ -191,7 +191,7 @@ function devel_generate_content_form() {
function devel_generate_content_form_submit($form_id, &$form_state) {
module_load_include('inc', 'devel_generate', 'devel_generate');
$form_state['values']['node_types'] = array_filter($form_state['values']['node_types']);
- if ($form_state['values']['num_nodes'] <= 50 && $form_state['values']['num_comments'] <= 10) {
+ if ($form_state['values']['num_nodes'] <= 50 && $form_state['values']['max_comments'] <= 10) {
module_load_include('inc', 'devel_generate');
devel_generate_content($form_state);
}
@@ -255,8 +255,8 @@ function devel_generate_node_insert(&$node) {
if (isset($node->devel_generate)) {
$results = $node->devel_generate;
- if (!empty($results['num_comments'])) {
- devel_generate_add_comments($node, $results['users'], $results['num_comments'], $results['title_length']);
+ if (!empty($results['max_comments'])) {
+ devel_generate_add_comments($node, $results['users'], $results['max_comments'], $results['title_length']);
}