You are here

function drush_devel_generate_terms in Devel 7

Command callback. Generate a number of terms in given vocabs.

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

File

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

Code

function drush_devel_generate_terms($vname = NULL, $num_terms = 10) {

  // Try to convert machine name to a vocab ID
  if (!($vocab = taxonomy_vocabulary_machine_name_load($vname))) {
    return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', dt('Invalid vocabulary name: !name', array(
      '!name' => $vname,
    )));
  }
  if (drush_generate_is_number($num_terms) == FALSE) {
    return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', dt('Invalid number of terms: !num', array(
      '!num' => $num_terms,
    )));
  }
  drush_generate_include_devel();
  if (drush_get_option('kill')) {
    devel_generate_delete_vocabulary_terms($vocab->vid);
    drush_log(dt('Deleted existing terms.'), 'success');
  }
  $new_terms = devel_generate_terms($num_terms, array(
    $vocab->vid => $vocab,
  ), '12');
  if (!empty($new_terms)) {
    drush_log(dt("Created the following new terms:\n!terms", array(
      '!terms' => implode("\n", $new_terms),
    )), 'success');
  }
}