/[drupal]/contributions/modules/devel/devel_generate.drush.inc
ViewVC logotype

Contents of /contributions/modules/devel/devel_generate.drush.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.7 - (show annotations) (download) (as text)
Wed Oct 14 20:55:51 2009 UTC (6 weeks, 2 days ago) by weitzman
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +4 -2 lines
File MIME type: text/x-php
Update drush integration for creating users with roles on D7. untested.
1 <?php
2 // $Id: devel_generate.drush.inc,v 1.6 2009/05/30 04:35:31 weitzman Exp $
3
4 /**
5 * @file
6 * Generate content, taxonomy, and users via drush framework.
7 */
8
9 /**
10 * Implementation of hook_drush_help().
11 */
12 function devel_generate_drush_help($section) {
13 switch ($section) {
14 case 'drush:generate users':
15 return dt('Usage: drush [options] generate users <number_users> <kill>. <kill> is optional, Specify "kill" if you want to delete the users first.');
16 case 'drush:generate taxonomy':
17 return dt('Usage: drush [options] generate tax <number_vocab> <number_terms> <kill>. <kill> is optional; specify "kill" if you want to delete all taxonomy first.');
18 case 'drush:generate content':
19 return dt('Usage: drush [options] generate content <number_nodes> <number_comments>. <kill> is optional; specify "kill" if you want to delete all content first.');
20 }
21 }
22
23 /**
24 * Implementation of hook_drush_command().
25 */
26 function devel_generate_drush_command() {
27 $items['generate users'] = array(
28 'callback' => 'drush_generate_users',
29 'description' => 'Creates users.',
30 'arguments' => array(
31 'n' => 'Number of users to generate.',
32 ),
33 'options' => array(
34 'kill' => 'Specify \'kill\' to delete all users before generating new ones.',
35 'roles' => 'A comma delimited list of role IDs which should be granted to the new users. No need to specify authenticated user role.',
36 ),
37 );
38 $items['generate taxonomy'] = array(
39 'callback' => 'drush_generate_tax',
40 'description' => 'Creates taxonomy.',
41 'arguments' => array(
42 'n' => 'Vocabulary ID into which new terms will be inserted.',
43 ),
44 'options' => array(
45 'kill' => 'Specify \'kill\' to delete all terms in specified vocab before generating.'
46 ),
47
48 );
49 $items['generate content'] = array(
50 'callback' => 'drush_generate_nodescontent',
51 'description' => 'Creates content.',
52 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_LOGIN, // Various D7 code assumes we have a uid.
53 'arguments' => array(
54 'n' => 'Number of nodes to generate.',
55 'c' => 'Number of comments to generate.',
56 ),
57 'options' => array(
58 'kill' => 'Specify \'kill\' to delete all content before generating new content.'
59 ),
60 );
61 return $items;
62 }
63
64
65 /**
66 * Command callback. Generate a number of users.
67 */
68 function drush_generate_users($num_users = NULL) {
69 if (drush_generate_is_number($num_users) == FALSE) {
70 drush_set_error('DEVEL_GENERATE_INVALID_INPUT', t('Invalid number of users.'));
71 }
72 drush_generate_include_devel();
73 $roles = drush_get_option('roles') ? explode(',', drush_get_option('roles')) : array();
74 devel_create_users($num_users, drush_get_option('kill'), 0, $roles);
75 drush_log(t('Generated @number users.', array('@number' => $num_users)), 'success');
76 }
77
78 /**
79 * Command callback. Generate a number of taxonomy.
80 */
81 function drush_generate_tax($num_vocab = NULL, $num_terms = NULL) {
82 if (drush_generate_is_number($num_vocab) == FALSE) {
83 drush_set_error('DEVEL_GENERATE_INVALID_INPUT', t('Invalid vocabulary ID.'));
84 }
85 if (drush_generate_is_number($num_terms) == FALSE) {
86 drush_set_error('DEVEL_GENERATE_INVALID_INPUT', t('Invalid number of terms.'));
87 }
88 drush_generate_include_devel();
89 devel_generate_taxonomy_data($num_vocab, $num_terms, '12', drush_get_option('kill'));
90 drush_log(t('Generated @num_vocab vocabulary, @num_terms terms', array('@num_vocab' => $num_vocab, '@num_terms' => $num_terms)), 'success');
91 }
92
93 /**
94 * Command callback. Generate a number of content.
95 */
96 function drush_generate_nodescontent($num_nodes = NULL, $num_comments = NULL) {
97 if (drush_generate_is_number($num_nodes) == FALSE) {
98 drush_set_error('DEVEL_GENERATE_INVALID_INPUT', t('Invalid number of nodes'));
99 }
100 if (!empty($num_comments) && drush_generate_is_number($num_comments) == FALSE) {
101 drush_set_error('DEVEL_GENERATE_INVALID_INPUT', t('Invalid number of comments.'));
102 }
103
104 // Let's load user 1, seems to be need for creating comments.
105 global $user;
106 $user_one = user_load(1);
107 $user = $user_one;
108 drupal_save_session(FALSE);
109
110 if (drush_get_option('kill')) {
111 $values['values']['kill_content'] = 1;
112 }
113 $values['values']['title_length'] = '8';
114 $values['values']['num_nodes'] = $num_nodes;
115 $values['values']['num_comments'] = $num_comments;
116 $values['values']['node_types'] = array('page' => 'page', 'article' => 'article');
117 drush_generate_include_devel();
118 devel_generate_content($values);
119 drush_log(t('Generated @num_nodes nodes, @num_comments comments per node', array('@num_nodes' => (int)$num_nodes, '@num_comments' => (int)$num_comments)), 'success');
120 }
121
122 //////////////////////////////////////////////////////////////////////////////
123 // Helper functions
124
125 // verify if param is a number
126 function drush_generate_is_number($number) {
127 if ($number == NULL) return FALSE;
128 if (!is_numeric($number)) return FALSE;
129 return TRUE;
130 }
131
132 // include devel_generate.inc
133 function drush_generate_include_devel() {
134 $path = drupal_get_path('module', 'devel_generate');
135 require_once($path .'/devel_generate.inc');
136 }

  ViewVC Help
Powered by ViewVC 1.1.2