generate-d6-content.sh

Same filename in other branches
  1. 9 core/scripts/generate-d6-content.sh
  2. 8.9.x core/scripts/generate-d6-content.sh
  3. 10 core/scripts/generate-d6-content.sh
  4. 11.x core/scripts/generate-d6-content.sh
#!/usr/bin/env php
<?php

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

// Define settings.
$cmd = 'index.php';
$_SERVER['HTTP_HOST']       = 'default';
$_SERVER['PHP_SELF']        = '/index.php';
$_SERVER['REMOTE_ADDR']     = '127.0.0.1';
$_SERVER['SERVER_SOFTWARE'] = NULL;
$_SERVER['REQUEST_METHOD']  = 'GET';
$_SERVER['QUERY_STRING']    = '';
$_SERVER['PHP_SELF']        = $_SERVER['REQUEST_URI'] = '/';
$_SERVER['HTTP_USER_AGENT'] = 'console';
$modules_to_enable          = array('path', 'poll');

// Bootstrap Drupal.
include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

// Enable requested modules
include_once './modules/system/system.admin.inc';
$form = system_modules();
foreach ($modules_to_enable as $module) {
  $form_state['values']['status'][$module] = TRUE;
}
$form_state['values']['disabled_modules'] = $form['disabled_modules'];
system_modules_submit(NULL, $form_state);
unset($form_state);

// Run cron after installing
drupal_cron_run();

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


// Create vocabularies and terms

$terms = array();

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

$voc_id = 0;
$term_id = 0;
for ($i = 0; $i < 24; $i++) {
  $vocabulary = array();
  ++$voc_id;
  $vocabulary['name'] = "vocabulary $voc_id (i=$i)";
  $vocabulary['description'] = "description of ". $vocabulary['name'];
  $vocabulary['help'] = "help for ". $vocabulary['name'];
  $vocabulary['nodes'] = $i > 11 ? array('page' => TRUE) : array();
  $vocabulary['multiple'] = $multiple[$i % 12];
  $vocabulary['required'] = $required[$i % 12];
  $vocabulary['relations'] = 1;
  $vocabulary['hierarchy'] = $hierarchy[$i % 12];
  $vocabulary['weight'] = $i;
  taxonomy_save_vocabulary($vocabulary);
  $parents = array();
  // Vocabularies without hierarchy get one term, single parent vocabularies get
  // one parent and one child term. Multiple parent vocabularies get three
  // terms: t0, t1, t2 where t0 is a parent of both t1 and t2.
  for ($j = 0; $j < $vocabulary['hierarchy'] + 1; $j++) {
    $term = array();
    $term['vid'] = $vocabulary['vid'];
    // For multiple parent vocabularies, omit the t0-t1 relation, otherwise
    // every parent in the vocabulary is a parent.
    $term['parent'] = $vocabulary['hierarchy'] == 2 && i == 1 ? array() : $parents;
    ++$term_id;
    $term['name'] = "term $term_id of vocabulary $voc_id (j=$j)";
    $term['description'] = 'description of ' . $term['name'];
    $term['weight'] = $i * 3 + $j;
    taxonomy_save_term($term);
    $terms[] = $term['tid'];
    $parents[] = $term['tid'];
  }
}

$node_id = 0;
$revision_id = 0;
module_load_include('inc', 'node', 'node.pages');
for ($i = 0; $i < 24; $i++) {
  $uid = intval($i / 8) + 3;
  $user = user_load($uid);
  $node = new stdClass();
  $node->uid = $uid;
  $node->type = $i < 12 ? 'page' : 'story';
  $node->sticky = 0;
  ++$node_id;
  ++$revision_id;
  $node->title = "node title $node_id rev $revision_id (i=$i)";
  $type = node_get_types('type', $node->type);
  if ($type->has_body) {
    $node->body = str_repeat("node body ($node->type) - $i", 100);
    $node->teaser = node_teaser($node->body);
    $node->filter = variable_get('filter_default_format', 1);
    $node->format = FILTER_FORMAT_DEFAULT;
  }
  $node->status = intval($i / 4) % 2;
  $node->language = '';
  $node->revision = $i < 12;
  $node->promote = $i % 2;
  $node->created = $now + $i * 86400;
  $node->log = "added $i node";
  // Make every term association different a little. For nodes with revisions,
  // make the initial revision have a different set of terms than the
  // newest revision.
  $node_terms = $terms;
  unset($node_terms[$i], $node_terms[47 - $i]);
  if ($node->revision) {
    $node->taxonomy = array($i => $terms[$i], 47-$i => $terms[47 - $i]);
  }
  else {
    $node->taxonomy = $node_terms;
  }
  node_save($node);
  path_set_alias("node/$node->nid", "content/$node->created");
  if ($node->revision) {
    $user = user_load($uid + 3);
    ++$revision_id;
    $node->title .= " rev2 $revision_id";
    $node->body = str_repeat("node revision body ($node->type) - $i", 100);
    $node->log = "added $i revision";
    $node->taxonomy = $node_terms;
    node_save($node);
  }
}

// Create poll content
for ($i = 0; $i < 12; $i++) {
  $uid = intval($i / 4) + 3;
  $user = user_load($uid);
  $node = new stdClass();
  $node->uid = $uid;
  $node->type = 'poll';
  $node->sticky = 0;
  $node->title = "poll title $i";
  $type = node_get_types('type', $node->type);
  if ($type->has_body) {
    $node->body = str_repeat("node body ($node->type) - $i", 100);
    $node->teaser = node_teaser($node->body);
    $node->filter = variable_get('filter_default_format', 1);
    $node->format = FILTER_FORMAT_DEFAULT;
  }
  $node->status = intval($i / 2) % 2;
  $node->language = '';
  $node->revision = 1;
  $node->promote = $i % 2;
  $node->created = $now + $i * 43200;
  $node->log = "added $i poll";

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

  // Add some votes
  for ($v = 0; $v < ($i % 4) + 5; $v++) {
    $c = $v % $nbchoices;
    $form_state = array();
    $form_state['values']['choice'] = $c;
    $form_state['values']['op'] = t('Vote');
    drupal_execute('poll_view_voting', $form_state, $node);
  }
}

$uid = 6;
$user = user_load($uid);
$node = new stdClass();
$node->uid = $uid;
$node->type = 'broken';
$node->sticky = 0;
$node->title = "node title 24";
$node->body = str_repeat("node body ($node->type) - 37", 100);
$node->teaser = node_teaser($node->body);
$node->filter = variable_get('filter_default_format', 1);
$node->format = FILTER_FORMAT_DEFAULT;
$node->status = 1;
$node->language = '';
$node->revision = 0;
$node->promote = 0;
$node->created = 1263769200;
$node->log = "added $i node";
node_save($node);
path_set_alias("node/$node->nid", "content/1263769200");

File

scripts/generate-d6-content.sh

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.