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. 28include_once './includes/bootstrap.inc'; 29drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); 30 31// Enable requested modules 32include_once './modules/system/system.admin.inc'; 33$form = system_modules(); 34foreach ($modules_to_enable as $module) { 35 $form_state['values']['status'][$module] = TRUE; 36} 37$form_state['values']['disabled_modules'] = $form['disabled_modules']; 38system_modules_submit(NULL, $form_state); 39unset($form_state); 40 41// Run cron after installing 42drupal_cron_run(); 43 44// Create six users 45for ($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; 65for ($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['nodes'] = $i > 11 ? array('page' => TRUE) : array(); 71 $vocabulary['multiple'] = $multiple[$i % 12]; 72 $vocabulary['required'] = $required[$i % 12]; 73 $vocabulary['relations'] = 1; 74 $vocabulary['hierarchy'] = $hierarchy[$i % 12]; 75 $vocabulary['weight'] = $i; 76 taxonomy_save_vocabulary($vocabulary); 77 $parents = array(); 78 // Vocabularies without hierarchy get one term, single parent vocabularies get 79 // one parent and one child term. Multiple parent vocabularies get three 80 // terms: t0, t1, t2 where t0 is a parent of both t1 and t2. 81 for ($j = 0; $j < $vocabulary['hierarchy'] + 1; $j++) { 82 $term = array(); 83 $term['vid'] = $vocabulary['vid']; 84 // For multiple parent vocabularies, omit the t0-t1 relation, otherwise 85 // every parent in the vocabulary is a parent. 86 $term['parent'] = $vocabulary['hierarchy'] == 2 && i == 1 ? array() : $parents; 87 ++$term_id; 88 $term['name'] = "term $term_id of vocabulary $voc_id (j=$j)"; 89 $term['description'] = 'description of ' . $term['name']; 90 $term['weight'] = $i * 3 + $j; 91 taxonomy_save_term($term); 92 $terms[] = $term['tid']; 93 $parents[] = $term['tid']; 94 } 95} 96 97$node_id = 0; 98$revision_id = 0; 99module_load_include('inc', 'node', 'node.pages'); 100for ($i = 0; $i < 24; $i++) { 101 $uid = intval($i / 8) + 3; 102 $user = user_load($uid); 103 $node = new stdClass(); 104 $node->uid = $uid; 105 $node->type = $i < 12 ? 'page' : 'story'; 106 $node->sticky = 0; 107 ++$node_id; 108 ++$revision_id; 109 $node->title = "node title $node_id rev $revision_id (i=$i)"; 110 $type = node_get_types('type', $node->type); 111 if ($type->has_body) { 112 $node->body = str_repeat("node body ($node->type) - $i", 100); 113 $node->teaser = node_teaser($node->body); 114 $node->filter = variable_get('filter_default_format', 1); 115 $node->format = FILTER_FORMAT_DEFAULT; 116 } 117 $node->status = intval($i / 4) % 2; 118 $node->language = ''; 119 $node->revision = $i < 12; 120 $node->promote = $i % 2; 121 $node->created = $now + $i * 86400; 122 $node->log = "added $i node"; 123 // Make every term association different a little. For nodes with revisions, 124 // make the initial revision have a different set of terms than the 125 // newest revision. 126 $node_terms = $terms; 127 unset($node_terms[$i], $node_terms[47 - $i]); 128 if ($node->revision) { 129 $node->taxonomy = array($i => $terms[$i], 47-$i => $terms[47 - $i]); 130 } 131 else { 132 $node->taxonomy = $node_terms; 133 } 134 node_save($node); 135 path_set_alias("node/$node->nid", "content/$node->created"); 136 if ($node->revision) { 137 $user = user_load($uid + 3); 138 ++$revision_id; 139 $node->title .= " rev2 $revision_id"; 140 $node->body = str_repeat("node revision body ($node->type) - $i", 100); 141 $node->log = "added $i revision"; 142 $node->taxonomy = $node_terms; 143 node_save($node); 144 } 145} 146 147// Create poll content 148for ($i = 0; $i < 12; $i++) { 149 $uid = intval($i / 4) + 3; 150 $user = user_load($uid); 151 $node = new stdClass(); 152 $node->uid = $uid; 153 $node->type = 'poll'; 154 $node->sticky = 0; 155 $node->title = "poll title $i"; 156 $type = node_get_types('type', $node->type); 157 if ($type->has_body) { 158 $node->body = str_repeat("node body ($node->type) - $i", 100); 159 $node->teaser = node_teaser($node->body); 160 $node->filter = variable_get('filter_default_format', 1); 161 $node->format = FILTER_FORMAT_DEFAULT; 162 } 163 $node->status = intval($i / 2) % 2; 164 $node->language = ''; 165 $node->revision = 1; 166 $node->promote = $i % 2; 167 $node->created = $now + $i * 43200; 168 $node->log = "added $i poll"; 169 170 $nbchoices = ($i % 4) + 2; 171 for ($c = 0; $c < $nbchoices; $c++) { 172 $node->choice[] = array('chtext' => "Choice $c for poll $i"); 173 } 174 node_save($node); 175 path_set_alias("node/$node->nid", "content/poll/$i"); 176 path_set_alias("node/$node->nid/results", "content/poll/$i/results"); 177 178 // Add some votes 179 for ($v = 0; $v < ($i % 4) + 5; $v++) { 180 $c = $v % $nbchoices; 181 $form_state = array(); 182 $form_state['values']['choice'] = $c; 183 $form_state['values']['op'] = t('Vote'); 184 drupal_execute('poll_view_voting', $form_state, $node); 185 } 186} 187 188$uid = 6; 189$user = user_load($uid); 190$node = new stdClass(); 191$node->uid = $uid; 192$node->type = 'broken'; 193$node->sticky = 0; 194$node->title = "node title 24"; 195$node->body = str_repeat("node body ($node->type) - 37", 100); 196$node->teaser = node_teaser($node->body); 197$node->filter = variable_get('filter_default_format', 1); 198$node->format = FILTER_FORMAT_DEFAULT; 199$node->status = 1; 200$node->language = ''; 201$node->revision = 0; 202$node->promote = 0; 203$node->created = 1263769200; 204$node->log = "added $i node"; 205node_save($node); 206path_set_alias("node/$node->nid", "content/1263769200"); 207