generate-d6-content.sh 6.7 KB

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