Project

General

Profile

Paste
Download (6.71 KB) Statistics
| Branch: | Revision:

root / drupal7 / scripts / generate-d6-content.sh @ b0dc3a2e

1
#!/usr/bin/env php
2
<?php
3

    
4
/**
5
 * Generate content for a Drupal 6 database to test the upgrade process.
6
 *
7
 * Run this script at the root of an existing Drupal 6 installation.
8
 * Steps to use this generation script:
9
 * - Install drupal 6.
10
 * - Run this script from your Drupal ROOT directory.
11
 * - Use the dump-database-d6.sh to generate the D7 file
12
 *   modules/simpletest/tests/upgrade/database.filled.php
13
 */
14

    
15
// Define settings.
16
$cmd = 'index.php';
17
$_SERVER['HTTP_HOST']       = 'default';
18
$_SERVER['PHP_SELF']        = '/index.php';
19
$_SERVER['REMOTE_ADDR']     = '127.0.0.1';
20
$_SERVER['SERVER_SOFTWARE'] = NULL;
21
$_SERVER['REQUEST_METHOD']  = 'GET';
22
$_SERVER['QUERY_STRING']    = '';
23
$_SERVER['PHP_SELF']        = $_SERVER['REQUEST_URI'] = '/';
24
$_SERVER['HTTP_USER_AGENT'] = 'console';
25
$modules_to_enable          = array('path', 'poll');
26

    
27
// Bootstrap Drupal.
28
include_once './includes/bootstrap.inc';
29
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
30

    
31
// Enable requested modules
32
include_once './modules/system/system.admin.inc';
33
$form = system_modules();
34
foreach ($modules_to_enable as $module) {
35
  $form_state['values']['status'][$module] = TRUE;
36
}
37
$form_state['values']['disabled_modules'] = $form['disabled_modules'];
38
system_modules_submit(NULL, $form_state);
39
unset($form_state);
40

    
41
// Run cron after installing
42
drupal_cron_run();
43

    
44
// Create six users
45
for ($i = 0; $i < 6; $i++) {
46
  $name = "test user $i";
47
  $pass = md5("test PassW0rd $i !(.)");
48
  $mail = "test$i@example.com";
49
  $now = mktime(0, 0, 0, 1, $i + 1, 2010);
50
  db_query("INSERT INTO {users} (name, pass, mail, status, created, access) VALUES ('%s', '%s', '%s', %d, %d, %d)", $name, $pass, $mail, 1, $now, $now);
51
}
52

    
53

    
54
// Create vocabularies and terms
55

    
56
$terms = array();
57

    
58
// All possible combinations of these vocabulary properties.
59
$hierarchy = array(0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2);
60
$multiple  = array(0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1);
61
$required  = array(0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1);
62

    
63
$voc_id = 0;
64
$term_id = 0;
65
for ($i = 0; $i < 24; $i++) {
66
  $vocabulary = array();
67
  ++$voc_id;
68
  $vocabulary['name'] = "vocabulary $voc_id (i=$i)";
69
  $vocabulary['description'] = "description of ". $vocabulary['name'];
70
  $vocabulary['help'] = "help for ". $vocabulary['name'];
71
  $vocabulary['nodes'] = $i > 11 ? array('page' => TRUE) : array();
72
  $vocabulary['multiple'] = $multiple[$i % 12];
73
  $vocabulary['required'] = $required[$i % 12];
74
  $vocabulary['relations'] = 1;
75
  $vocabulary['hierarchy'] = $hierarchy[$i % 12];
76
  $vocabulary['weight'] = $i;
77
  taxonomy_save_vocabulary($vocabulary);
78
  $parents = array();
79
  // Vocabularies without hierarchy get one term, single parent vocabularies get
80
  // one parent and one child term. Multiple parent vocabularies get three
81
  // terms: t0, t1, t2 where t0 is a parent of both t1 and t2.
82
  for ($j = 0; $j < $vocabulary['hierarchy'] + 1; $j++) {
83
    $term = array();
84
    $term['vid'] = $vocabulary['vid'];
85
    // For multiple parent vocabularies, omit the t0-t1 relation, otherwise
86
    // every parent in the vocabulary is a parent.
87
    $term['parent'] = $vocabulary['hierarchy'] == 2 && i == 1 ? array() : $parents;
88
    ++$term_id;
89
    $term['name'] = "term $term_id of vocabulary $voc_id (j=$j)";
90
    $term['description'] = 'description of ' . $term['name'];
91
    $term['weight'] = $i * 3 + $j;
92
    taxonomy_save_term($term);
93
    $terms[] = $term['tid'];
94
    $parents[] = $term['tid'];
95
  }
96
}
97

    
98
$node_id = 0;
99
$revision_id = 0;
100
module_load_include('inc', 'node', 'node.pages');
101
for ($i = 0; $i < 24; $i++) {
102
  $uid = intval($i / 8) + 3;
103
  $user = user_load($uid);
104
  $node = new stdClass();
105
  $node->uid = $uid;
106
  $node->type = $i < 12 ? 'page' : 'story';
107
  $node->sticky = 0;
108
  ++$node_id;
109
  ++$revision_id;
110
  $node->title = "node title $node_id rev $revision_id (i=$i)";
111
  $type = node_get_types('type', $node->type);
112
  if ($type->has_body) {
113
    $node->body = str_repeat("node body ($node->type) - $i", 100);
114
    $node->teaser = node_teaser($node->body);
115
    $node->filter = variable_get('filter_default_format', 1);
116
    $node->format = FILTER_FORMAT_DEFAULT;
117
  }
118
  $node->status = intval($i / 4) % 2;
119
  $node->language = '';
120
  $node->revision = $i < 12;
121
  $node->promote = $i % 2;
122
  $node->created = $now + $i * 86400;
123
  $node->log = "added $i node";
124
  // Make every term association different a little. For nodes with revisions,
125
  // make the initial revision have a different set of terms than the
126
  // newest revision.
127
  $node_terms = $terms;
128
  unset($node_terms[$i], $node_terms[47 - $i]);
129
  if ($node->revision) {
130
    $node->taxonomy = array($i => $terms[$i], 47-$i => $terms[47 - $i]);
131
  }
132
  else {
133
    $node->taxonomy = $node_terms;
134
  }
135
  node_save($node);
136
  path_set_alias("node/$node->nid", "content/$node->created");
137
  if ($node->revision) {
138
    $user = user_load($uid + 3);
139
    ++$revision_id;
140
    $node->title .= " rev2 $revision_id";
141
    $node->body = str_repeat("node revision body ($node->type) - $i", 100);
142
    $node->log = "added $i revision";
143
    $node->taxonomy = $node_terms;
144
    node_save($node);
145
  }
146
}
147

    
148
// Create poll content
149
for ($i = 0; $i < 12; $i++) {
150
  $uid = intval($i / 4) + 3;
151
  $user = user_load($uid);
152
  $node = new stdClass();
153
  $node->uid = $uid;
154
  $node->type = 'poll';
155
  $node->sticky = 0;
156
  $node->title = "poll title $i";
157
  $type = node_get_types('type', $node->type);
158
  if ($type->has_body) {
159
    $node->body = str_repeat("node body ($node->type) - $i", 100);
160
    $node->teaser = node_teaser($node->body);
161
    $node->filter = variable_get('filter_default_format', 1);
162
    $node->format = FILTER_FORMAT_DEFAULT;
163
  }
164
  $node->status = intval($i / 2) % 2;
165
  $node->language = '';
166
  $node->revision = 1;
167
  $node->promote = $i % 2;
168
  $node->created = $now + $i * 43200;
169
  $node->log = "added $i poll";
170

    
171
  $nbchoices = ($i % 4) + 2;
172
  for ($c = 0; $c < $nbchoices; $c++) {
173
    $node->choice[] = array('chtext' => "Choice $c for poll $i");
174
  }
175
  node_save($node);
176
  path_set_alias("node/$node->nid", "content/poll/$i");
177
  path_set_alias("node/$node->nid/results", "content/poll/$i/results");
178

    
179
  // Add some votes
180
  for ($v = 0; $v < ($i % 4) + 5; $v++) {
181
    $c = $v % $nbchoices;
182
    $form_state = array();
183
    $form_state['values']['choice'] = $c;
184
    $form_state['values']['op'] = t('Vote');
185
    drupal_execute('poll_view_voting', $form_state, $node);
186
  }
187
}
188

    
189
$uid = 6;
190
$user = user_load($uid);
191
$node = new stdClass();
192
$node->uid = $uid;
193
$node->type = 'broken';
194
$node->sticky = 0;
195
$node->title = "node title 24";
196
$node->body = str_repeat("node body ($node->type) - 37", 100);
197
$node->teaser = node_teaser($node->body);
198
$node->filter = variable_get('filter_default_format', 1);
199
$node->format = FILTER_FORMAT_DEFAULT;
200
$node->status = 1;
201
$node->language = '';
202
$node->revision = 0;
203
$node->promote = 0;
204
$node->created = 1263769200;
205
$node->log = "added $i node";
206
node_save($node);
207
path_set_alias("node/$node->nid", "content/1263769200");