You are here

function drush_devel_generate_content in Devel 7

Command callback. Generate a number of nodes and comments.

1 string reference to 'drush_devel_generate_content'
devel_generate_drush_command in devel_generate/devel_generate.drush.inc
Implementation of hook_drush_command().

File

devel_generate/devel_generate.drush.inc, line 144
Generate content, taxonomy, menu, and users via drush framework.

Code

function drush_devel_generate_content($num_nodes = NULL, $max_comments = NULL) {
  if (drush_generate_is_number($num_nodes) == FALSE) {
    return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', dt('Invalid number of nodes'));
  }
  if (!empty($max_comments) && drush_generate_is_number($max_comments) == FALSE) {
    return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', dt('Invalid number of comments.'));
  }
  $add_language = drush_get_option('languages');
  if (!empty($add_language)) {
    $add_language = explode(',', str_replace(' ', '', $add_language));

    // Intersect with the enabled languages to make sure the language args
    // passed are actually enabled.
    $values['values']['add_language'] = array_intersect($add_language, array_keys(locale_language_list()));
  }

  // Load user 1; is needed for creating *published* comments.
  if ($max_comments) {
    global $user;
    $user_one = user_load(1);
    $user = $user_one;
    drupal_save_session(FALSE);
  }
  $values['values']['kill_content'] = drush_get_option('kill');
  $values['values']['title_length'] = 6;
  $values['values']['num_nodes'] = $num_nodes;
  $values['values']['max_comments'] = $max_comments;
  $values['values']['node_types'] = drupal_map_assoc(explode(',', drush_get_option('types', 'page,article')));
  $node_types = array_filter($values['values']['node_types']);
  if (!empty($values['values']['kill_content']) && empty($node_types)) {
    return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', dt('Please provide content type (--types) in which you want to delete the content.'));
  }
  drush_generate_include_devel();
  devel_generate_content($values);
  drush_log(t('Generated @num_nodes nodes, @max_comments comments (or less) per node.', array(
    '@num_nodes' => (int) $num_nodes,
    '@max_comments' => (int) $max_comments,
  )), 'success');
}