5 * Generate content for a Drupal 7 database to test the upgrade process.
7 * Run this script at the root of an existing Drupal 7 installation.
9 * Steps to use this generation script:
11 * - Run this script from your Drupal ROOT directory.
12 * - Use the dump-database-d7.sh to generate the D7 file
13 * modules/simpletest/tests/upgrade/database.filled.php
18 define('DRUPAL_ROOT', getcwd());
19 $_SERVER['HTTP_HOST'] = 'default';
20 $_SERVER['PHP_SELF'] = '/index.php';
21 $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
22 $_SERVER['SERVER_SOFTWARE'] = NULL;
23 $_SERVER['REQUEST_METHOD'] = 'GET';
24 $_SERVER['QUERY_STRING'] = '';
25 $_SERVER['PHP_SELF'] = $_SERVER['REQUEST_URI'] = '/';
26 $_SERVER['HTTP_USER_AGENT'] = 'console';
27 $modules_to_enable = array('path', 'poll', 'taxonomy');
30 include_once './includes/bootstrap.inc';
31 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
33 // Enable requested modules
34 require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
35 include_once './modules/system/system.admin.inc';
36 $form = system_modules();
37 foreach ($modules_to_enable as $module) {
38 $form_state['values']['status'][$module] = TRUE;
40 $form_state['values']['disabled_modules'] = $form['disabled_modules'];
41 system_modules_submit(NULL, $form_state);
44 // Run cron after installing
48 $query = db_insert('users')->fields(array('uid', 'name', 'pass', 'mail', 'status', 'created', 'access'));
49 for ($i = 0; $i < 6; $i++) {
50 $name = "test user $i";
51 $pass = md5("test PassW0rd $i !(.)");
52 $mail = "test$i@example.com";
53 $now = mktime(0, 0, 0, 1, $i + 1, 2010);
54 $query->values(array(db_next_id(), $name, user_hash_password($pass), $mail, 1, $now, $now));
58 // Create vocabularies and terms
62 // All possible combinations of these vocabulary properties.
63 $hierarchy = array(0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2);
64 $multiple = array(0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1);
65 $required = array(0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1);
69 for ($i = 0; $i < 24; $i++) {
70 $vocabulary = new stdClass;
72 $vocabulary->name = "vocabulary $voc_id (i=$i)";
73 $vocabulary->machine_name = 'vocabulary_' . $voc_id . '_' . $i;
74 $vocabulary->description = "description of ". $vocabulary->name;
75 $vocabulary->multiple = $multiple[$i % 12];
76 $vocabulary->required = $required[$i % 12];
77 $vocabulary->relations = 1;
78 $vocabulary->hierarchy = $hierarchy[$i % 12];
79 $vocabulary->weight = $i;
80 taxonomy_vocabulary_save($vocabulary);
82 'field_name' => 'taxonomy_'. $vocabulary->machine_name,
83 'module' => 'taxonomy',
84 'type' => 'taxonomy_term_reference',
85 'cardinality' => $vocabulary->multiple || $vocabulary->tags ? FIELD_CARDINALITY_UNLIMITED : 1,
87 'required' => $vocabulary->required ? TRUE : FALSE,
88 'allowed_values' => array(
90 'vocabulary' => $vocabulary->machine_name,
96 field_create_field($field);
97 $node_types = $i > 11 ? array('page') : array_keys(node_type_get_types());
98 foreach ($node_types as $bundle) {
100 'label' => $vocabulary->name,
101 'field_name' => $field['field_name'],
103 'entity_type' => 'node',
104 'settings' => array(),
105 'description' => $vocabulary->help,
106 'required' => $vocabulary->required,
110 'type' => 'taxonomy_term_reference_link',
114 'type' => 'taxonomy_term_reference_link',
119 if ($vocabulary->tags) {
120 $instance['widget'] = array(
121 'type' => 'taxonomy_autocomplete',
122 'module' => 'taxonomy',
125 'autocomplete_path' => 'taxonomy/autocomplete',
130 $instance['widget'] = array(
131 'type' => 'options_select',
132 'settings' => array(),
135 field_create_instance($instance);
138 // Vocabularies without hierarchy get one term, single parent vocabularies get
139 // one parent and one child term. Multiple parent vocabularies get three
140 // terms: t0, t1, t2 where t0 is a parent of both t1 and t2.
141 for ($j = 0; $j < $vocabulary->hierarchy + 1; $j++) {
143 $term = entity_create('taxonomy_term', array(
144 'vocabulary_machine_name' => $vocabulary->machine_name,
145 // For multiple parent vocabularies, omit the t0-t1 relation, otherwise
146 // every parent in the vocabulary is a parent.
147 'parent' => $vocabulary->hierarchy == 2 && i == 1 ? array() : $parents,
148 'name' => "term $term_id of vocabulary $voc_id (j=$j)",
149 'description' => 'description of ' . $term->name,
150 'format' => 'filtered_html',
151 'weight' => $i * 3 + $j,
153 taxonomy_term_save($term);
154 $terms[] = $term->tid;
155 $term_vocabs[$term->tid] = 'taxonomy_' . $vocabulary->machine_name;
156 $parents[] = $term->tid;
161 module_load_include('inc', 'node', 'node.pages');
162 for ($i = 0; $i < 36; $i++) {
163 $uid = intval($i / 8) + 3;
164 $user = user_load($uid);
165 $node = new stdClass();
167 $node->type = 'page';
169 $node->type = 'page';
172 $node->type = 'story';
174 elseif (module_exists('blog')) {
175 $node->type = 'blog';
180 $node->title = "node title $node_id rev $revision_id (i=$i)";
181 $node->language = LANGUAGE_NONE;
182 $body_text = str_repeat("node body ($node->type) - $i", 100);
183 $node->body[$node->language][0]['value'] = $body_text;
184 $node->body[$node->language][0]['summary'] = text_summary($body_text);
185 $node->body[$node->language][0]['format'] = 'filtered_html';
186 $node->status = intval($i / 4) % 2;
187 $node->revision = $i < 12;
188 $node->promote = $i % 2;
189 $node->created = $now + $i * 86400;
190 $node->log = "added $i node";
191 // Make every term association different a little. For nodes with revisions,
192 // make the initial revision have a different set of terms than the
195 if ($node->revision) {
196 $node_terms = array($terms[$i], $terms[47-$i]);
199 $node_terms = $terms;
200 unset($node_terms[$i], $node_terms[47 - $i]);
202 foreach ($node_terms as $tid) {
203 $field_name = $term_vocabs[$tid];
204 $node->{$field_name}[LANGUAGE_NONE][] = array('tid' => $tid);
206 $node->path = array('alias' => "content/$node->created");
208 if ($node->revision) {
209 $user = user_load($uid + 3);
211 $node->title .= " rev2 $revision_id";
212 $body_text = str_repeat("node revision body ($node->type) - $i", 100);
213 $node->body[$node->language][0]['value'] = $body_text;
214 $node->body[$node->language][0]['summary'] = text_summary($body_text);
215 $node->body[$node->language][0]['format'] = 'filtered_html';
216 $node->log = "added $i revision";
217 $node_terms = $terms;
218 unset($node_terms[$i], $node_terms[47 - $i]);
219 foreach ($node_terms as $tid) {
220 $field_name = $term_vocabs[$tid];
221 $node->{$field_name}[LANGUAGE_NONE][] = array('tid' => $tid);
227 // Create poll content
228 for ($i = 0; $i < 12; $i++) {
229 $uid = intval($i / 4) + 3;
230 $user = user_load($uid);
231 $node = new stdClass();
233 $node->type = 'poll';
235 $node->title = "poll title $i";
236 $node->language = LANGUAGE_NONE;
237 $node->status = intval($i / 2) % 2;
239 $node->promote = $i % 2;
240 $node->created = REQUEST_TIME + $i * 43200;
243 $node->log = "added $i poll";
244 $node->path = array('alias' => "content/poll/$i");
246 $nbchoices = ($i % 4) + 2;
247 for ($c = 0; $c < $nbchoices; $c++) {
248 $node->choice[] = array('chtext' => "Choice $c for poll $i", 'chvotes' => 0, 'weight' => 0);
252 'alias' => "content/poll/$i/results",
253 'source' => "node/$node->nid/results",
258 $node = node_load($node->nid);
259 $choices = array_keys($node->choice);
260 $original_user = $GLOBALS['user'];
261 for ($v = 0; $v < ($i % 4); $v++) {
262 drupal_static_reset('ip_address');
263 $_SERVER['REMOTE_ADDR'] = "127.0.$v.1";
264 $GLOBALS['user'] = drupal_anonymous_user();// We should have already allowed anon to vote.
265 $c = $v % $nbchoices;
266 $form_state = array();
267 $form_state['values']['choice'] = $choices[$c];
268 $form_state['values']['op'] = t('Vote');
269 drupal_form_submit('poll_view_voting', $form_state, $node);
274 $node_type = 'broken';
275 $user = user_load($uid);
276 $node = new stdClass();
278 $node->type = 'article';
279 $body_text = str_repeat("node body ($node_type) - 37", 100);
281 $node->title = "node title 24";
282 $node->language = LANGUAGE_NONE;
283 $node->body[$node->language][0]['value'] = $body_text;
284 $node->body[$node->language][0]['summary'] = text_summary($body_text);
285 $node->body[$node->language][0]['format'] = 'filtered_html';
289 $node->created = 1263769200;
290 $node->log = "added a broken node";
291 $node->path = array('alias' => "content/1263769200");
295 'type' => $node_type,
297 ->condition('nid', $node->nid)
299 db_update('field_data_body')
301 'bundle' => $node_type,
303 ->condition('entity_id', $node->nid)
304 ->condition('entity_type', 'node')
306 db_update('field_revision_body')
308 'bundle' => $node_type,
310 ->condition('entity_id', $node->nid)
311 ->condition('entity_type', 'node')
313 db_update('field_config_instance')
315 'bundle' => $node_type,
317 ->condition('bundle', 'article')