function drush_devel_generate_generate_content

Command callback. Generate a number of content.

File

./devel_generate.drush.inc, line 96

Code

function drush_devel_generate_generate_content($num_nodes = NULL, $max_comments = NULL, $add_language = NULL) {
    if (drush_generate_is_number($num_nodes) == FALSE) {
        drush_set_error('DEVEL_GENERATE_INVALID_NUM_NODES', dt('Invalid number of nodes'));
    }
    if (!empty($max_comments) && drush_generate_is_number($max_comments) == FALSE) {
        drush_set_error('DEVEL_GENERATE_INVALID_NUM_COMMENTS', 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_flip(array_intersect($add_language, array_keys(locale_language_list())));
    }
    // Let's load user 1, seems to be need for creating comments.
    global $user;
    $user_one = user_load(array(
        'uid' => '1',
    ));
    $user = $user_one;
    session_save_session(FALSE);
    drush_generate_include_devel();
    $values['values']['kill_content'] = drush_get_option('kill', FALSE);
    $values['values']['title_length'] = '8';
    $values['values']['num_nodes'] = $num_nodes;
    $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);
    $all_types = array_keys(devel_generate_content_types());
    if (drush_get_option('types')) {
        $types = explode(',', drush_get_option('types'));
        $types = array_intersect($types, $all_types);
    }
    else {
        $types = $all_types;
    }
    $values['values']['node_types'] = drupal_map_assoc($types);
    drush_op('devel_generate_content', $values);
    drush_log(dt('Generated @num_nodes nodes, @max_comments comments per node', array(
        '@num_nodes' => $num_nodes,
        '@max_comments' => $max_comments,
    )), 'ok');
}