annotate core/scripts/generate-d6-content.sh @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 #!/usr/bin/env php
Chris@0 2 <?php
Chris@0 3
Chris@0 4 /**
Chris@0 5 * Generate content for a Drupal 6 database to test the upgrade process.
Chris@0 6 *
Chris@0 7 * Run this script at the root of an existing Drupal 6 installation.
Chris@0 8 * Steps to use this generation script:
Chris@0 9 * - Install drupal 6.
Chris@0 10 * - Run this script from your Drupal ROOT directory.
Chris@0 11 * - Use the dump-database-d6.sh to generate the D7 file
Chris@0 12 * modules/simpletest/tests/upgrade/database.filled.php
Chris@0 13 */
Chris@0 14
Chris@0 15 // Define settings.
Chris@0 16 $cmd = 'index.php';
Chris@0 17 $_SERVER['HTTP_HOST'] = 'default';
Chris@0 18 $_SERVER['PHP_SELF'] = '/index.php';
Chris@0 19 $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
Chris@0 20 $_SERVER['SERVER_SOFTWARE'] = NULL;
Chris@0 21 $_SERVER['REQUEST_METHOD'] = 'GET';
Chris@0 22 $_SERVER['QUERY_STRING'] = '';
Chris@0 23 $_SERVER['PHP_SELF'] = $_SERVER['REQUEST_URI'] = '/';
Chris@0 24 $_SERVER['HTTP_USER_AGENT'] = 'console';
Chris@0 25 $modules_to_enable = array('path', 'poll');
Chris@0 26
Chris@0 27 // Bootstrap Drupal.
Chris@0 28 include_once './includes/bootstrap.inc';
Chris@0 29 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
Chris@0 30
Chris@0 31 // Enable requested modules
Chris@0 32 include_once './modules/system/system.admin.inc';
Chris@0 33 $form = system_modules();
Chris@0 34 foreach ($modules_to_enable as $module) {
Chris@0 35 $form_state['values']['status'][$module] = TRUE;
Chris@0 36 }
Chris@0 37 $form_state['values']['disabled_modules'] = $form['disabled_modules'];
Chris@0 38 system_modules_submit(NULL, $form_state);
Chris@0 39 unset($form_state);
Chris@0 40
Chris@0 41 // Run cron after installing
Chris@0 42 drupal_cron_run();
Chris@0 43
Chris@0 44 // Create six users
Chris@0 45 for ($i = 0; $i < 6; $i++) {
Chris@0 46 $name = "test user $i";
Chris@0 47 $pass = md5("test PassW0rd $i !(.)");
Chris@0 48 $mail = "test$i@example.com";
Chris@0 49 $now = mktime(0, 0, 0, 1, $i + 1, 2010);
Chris@0 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);
Chris@0 51 }
Chris@0 52
Chris@0 53
Chris@0 54 // Create vocabularies and terms
Chris@0 55
Chris@0 56 $terms = array();
Chris@0 57
Chris@0 58 // All possible combinations of these vocabulary properties.
Chris@0 59 $hierarchy = array(0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2);
Chris@0 60 $multiple = array(0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1);
Chris@0 61 $required = array(0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1);
Chris@0 62
Chris@0 63 $voc_id = 0;
Chris@0 64 $term_id = 0;
Chris@0 65 for ($i = 0; $i < 24; $i++) {
Chris@0 66 $vocabulary = array();
Chris@0 67 ++$voc_id;
Chris@0 68 $vocabulary['name'] = "vocabulary $voc_id (i=$i)";
Chris@0 69 $vocabulary['description'] = "description of ". $vocabulary['name'];
Chris@0 70 $vocabulary['nodes'] = $i > 11 ? array('page' => TRUE) : array();
Chris@0 71 $vocabulary['multiple'] = $multiple[$i % 12];
Chris@0 72 $vocabulary['required'] = $required[$i % 12];
Chris@0 73 $vocabulary['relations'] = 1;
Chris@0 74 $vocabulary['hierarchy'] = $hierarchy[$i % 12];
Chris@0 75 $vocabulary['weight'] = $i;
Chris@0 76 taxonomy_save_vocabulary($vocabulary);
Chris@0 77 $parents = array();
Chris@0 78 // Vocabularies without hierarchy get one term, single parent vocabularies get
Chris@0 79 // one parent and one child term. Multiple parent vocabularies get three
Chris@0 80 // terms: t0, t1, t2 where t0 is a parent of both t1 and t2.
Chris@0 81 for ($j = 0; $j < $vocabulary['hierarchy'] + 1; $j++) {
Chris@0 82 $term = array();
Chris@0 83 $term['vid'] = $vocabulary['vid'];
Chris@0 84 // For multiple parent vocabularies, omit the t0-t1 relation, otherwise
Chris@0 85 // every parent in the vocabulary is a parent.
Chris@0 86 $term['parent'] = $vocabulary['hierarchy'] == 2 && i == 1 ? array() : $parents;
Chris@0 87 ++$term_id;
Chris@0 88 $term['name'] = "term $term_id of vocabulary $voc_id (j=$j)";
Chris@0 89 $term['description'] = 'description of ' . $term['name'];
Chris@0 90 $term['weight'] = $i * 3 + $j;
Chris@0 91 taxonomy_save_term($term);
Chris@0 92 $terms[] = $term['tid'];
Chris@0 93 $parents[] = $term['tid'];
Chris@0 94 }
Chris@0 95 }
Chris@0 96
Chris@0 97 $node_id = 0;
Chris@0 98 $revision_id = 0;
Chris@0 99 module_load_include('inc', 'node', 'node.pages');
Chris@0 100 for ($i = 0; $i < 24; $i++) {
Chris@0 101 $uid = intval($i / 8) + 3;
Chris@0 102 $user = user_load($uid);
Chris@0 103 $node = new stdClass();
Chris@0 104 $node->uid = $uid;
Chris@0 105 $node->type = $i < 12 ? 'page' : 'story';
Chris@0 106 $node->sticky = 0;
Chris@0 107 ++$node_id;
Chris@0 108 ++$revision_id;
Chris@0 109 $node->title = "node title $node_id rev $revision_id (i=$i)";
Chris@0 110 $type = node_get_types('type', $node->type);
Chris@0 111 if ($type->has_body) {
Chris@0 112 $node->body = str_repeat("node body ($node->type) - $i", 100);
Chris@0 113 $node->teaser = node_teaser($node->body);
Chris@0 114 $node->filter = variable_get('filter_default_format', 1);
Chris@0 115 $node->format = FILTER_FORMAT_DEFAULT;
Chris@0 116 }
Chris@0 117 $node->status = intval($i / 4) % 2;
Chris@0 118 $node->language = '';
Chris@0 119 $node->revision = $i < 12;
Chris@0 120 $node->promote = $i % 2;
Chris@0 121 $node->created = $now + $i * 86400;
Chris@0 122 $node->log = "added $i node";
Chris@0 123 // Make every term association different a little. For nodes with revisions,
Chris@0 124 // make the initial revision have a different set of terms than the
Chris@0 125 // newest revision.
Chris@0 126 $node_terms = $terms;
Chris@0 127 unset($node_terms[$i], $node_terms[47 - $i]);
Chris@0 128 if ($node->revision) {
Chris@0 129 $node->taxonomy = array($i => $terms[$i], 47-$i => $terms[47 - $i]);
Chris@0 130 }
Chris@0 131 else {
Chris@0 132 $node->taxonomy = $node_terms;
Chris@0 133 }
Chris@0 134 node_save($node);
Chris@0 135 path_set_alias("node/$node->nid", "content/$node->created");
Chris@0 136 if ($node->revision) {
Chris@0 137 $user = user_load($uid + 3);
Chris@0 138 ++$revision_id;
Chris@0 139 $node->title .= " rev2 $revision_id";
Chris@0 140 $node->body = str_repeat("node revision body ($node->type) - $i", 100);
Chris@0 141 $node->log = "added $i revision";
Chris@0 142 $node->taxonomy = $node_terms;
Chris@0 143 node_save($node);
Chris@0 144 }
Chris@0 145 }
Chris@0 146
Chris@0 147 // Create poll content
Chris@0 148 for ($i = 0; $i < 12; $i++) {
Chris@0 149 $uid = intval($i / 4) + 3;
Chris@0 150 $user = user_load($uid);
Chris@0 151 $node = new stdClass();
Chris@0 152 $node->uid = $uid;
Chris@0 153 $node->type = 'poll';
Chris@0 154 $node->sticky = 0;
Chris@0 155 $node->title = "poll title $i";
Chris@0 156 $type = node_get_types('type', $node->type);
Chris@0 157 if ($type->has_body) {
Chris@0 158 $node->body = str_repeat("node body ($node->type) - $i", 100);
Chris@0 159 $node->teaser = node_teaser($node->body);
Chris@0 160 $node->filter = variable_get('filter_default_format', 1);
Chris@0 161 $node->format = FILTER_FORMAT_DEFAULT;
Chris@0 162 }
Chris@0 163 $node->status = intval($i / 2) % 2;
Chris@0 164 $node->language = '';
Chris@0 165 $node->revision = 1;
Chris@0 166 $node->promote = $i % 2;
Chris@0 167 $node->created = $now + $i * 43200;
Chris@0 168 $node->log = "added $i poll";
Chris@0 169
Chris@0 170 $nbchoices = ($i % 4) + 2;
Chris@0 171 for ($c = 0; $c < $nbchoices; $c++) {
Chris@0 172 $node->choice[] = array('chtext' => "Choice $c for poll $i");
Chris@0 173 }
Chris@0 174 node_save($node);
Chris@0 175 path_set_alias("node/$node->nid", "content/poll/$i");
Chris@0 176 path_set_alias("node/$node->nid/results", "content/poll/$i/results");
Chris@0 177
Chris@0 178 // Add some votes
Chris@0 179 for ($v = 0; $v < ($i % 4) + 5; $v++) {
Chris@0 180 $c = $v % $nbchoices;
Chris@0 181 $form_state = array();
Chris@0 182 $form_state['values']['choice'] = $c;
Chris@0 183 $form_state['values']['op'] = t('Vote');
Chris@0 184 drupal_execute('poll_view_voting', $form_state, $node);
Chris@0 185 }
Chris@0 186 }
Chris@0 187
Chris@0 188 $uid = 6;
Chris@0 189 $user = user_load($uid);
Chris@0 190 $node = new stdClass();
Chris@0 191 $node->uid = $uid;
Chris@0 192 $node->type = 'broken';
Chris@0 193 $node->sticky = 0;
Chris@0 194 $node->title = "node title 24";
Chris@0 195 $node->body = str_repeat("node body ($node->type) - 37", 100);
Chris@0 196 $node->teaser = node_teaser($node->body);
Chris@0 197 $node->filter = variable_get('filter_default_format', 1);
Chris@0 198 $node->format = FILTER_FORMAT_DEFAULT;
Chris@0 199 $node->status = 1;
Chris@0 200 $node->language = '';
Chris@0 201 $node->revision = 0;
Chris@0 202 $node->promote = 0;
Chris@0 203 $node->created = 1263769200;
Chris@0 204 $node->log = "added $i node";
Chris@0 205 node_save($node);
Chris@0 206 path_set_alias("node/$node->nid", "content/1263769200");