Chris@0: #!/usr/bin/env php Chris@0: fields(array('uid', 'name', 'pass', 'mail', 'status', 'created', 'access')); Chris@0: for ($i = 0; $i < 6; $i++) { Chris@0: $name = "test user $i"; Chris@0: $pass = md5("test PassW0rd $i !(.)"); Chris@0: $mail = "test$i@example.com"; Chris@0: $now = mktime(0, 0, 0, 1, $i + 1, 2010); Chris@0: $query->values(array(db_next_id(), $name, user_hash_password($pass), $mail, 1, $now, $now)); Chris@0: } Chris@0: $query->execute(); Chris@0: Chris@0: // Create vocabularies and terms Chris@0: Chris@0: $terms = array(); Chris@0: Chris@0: // All possible combinations of these vocabulary properties. Chris@0: $hierarchy = array(0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2); Chris@0: $multiple = array(0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1); Chris@0: $required = array(0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1); Chris@0: Chris@0: $voc_id = 0; Chris@0: $term_id = 0; Chris@0: for ($i = 0; $i < 24; $i++) { Chris@0: $vocabulary = new stdClass; Chris@0: ++$voc_id; Chris@0: $vocabulary->name = "vocabulary $voc_id (i=$i)"; Chris@0: $vocabulary->machine_name = 'vocabulary_' . $voc_id . '_' . $i; Chris@0: $vocabulary->description = "description of ". $vocabulary->name; Chris@0: $vocabulary->multiple = $multiple[$i % 12]; Chris@0: $vocabulary->required = $required[$i % 12]; Chris@0: $vocabulary->relations = 1; Chris@0: $vocabulary->hierarchy = $hierarchy[$i % 12]; Chris@0: $vocabulary->weight = $i; Chris@0: taxonomy_vocabulary_save($vocabulary); Chris@0: $field = array( Chris@0: 'field_name' => 'taxonomy_'. $vocabulary->machine_name, Chris@0: 'module' => 'taxonomy', Chris@0: 'type' => 'taxonomy_term_reference', Chris@0: 'cardinality' => $vocabulary->multiple || $vocabulary->tags ? FIELD_CARDINALITY_UNLIMITED : 1, Chris@0: 'settings' => array( Chris@0: 'required' => $vocabulary->required ? TRUE : FALSE, Chris@0: 'allowed_values' => array( Chris@0: array( Chris@0: 'vocabulary' => $vocabulary->machine_name, Chris@0: 'parent' => 0, Chris@0: ), Chris@0: ), Chris@0: ), Chris@0: ); Chris@0: field_create_field($field); Chris@0: $node_types = $i > 11 ? array('page') : array_keys(node_type_get_types()); Chris@0: foreach ($node_types as $bundle) { Chris@0: $instance = array( Chris@0: 'label' => $vocabulary->name, Chris@0: 'field_name' => $field['field_name'], Chris@0: 'bundle' => $bundle, Chris@0: 'entity_type' => 'node', Chris@0: 'settings' => array(), Chris@0: 'description' => $vocabulary->help, Chris@0: 'required' => $vocabulary->required, Chris@0: 'widget' => array(), Chris@0: 'display' => array( Chris@0: 'default' => array( Chris@0: 'type' => 'taxonomy_term_reference_link', Chris@0: 'weight' => 10, Chris@0: ), Chris@0: 'teaser' => array( Chris@0: 'type' => 'taxonomy_term_reference_link', Chris@0: 'weight' => 10, Chris@0: ), Chris@0: ), Chris@0: ); Chris@0: if ($vocabulary->tags) { Chris@0: $instance['widget'] = array( Chris@0: 'type' => 'taxonomy_autocomplete', Chris@0: 'module' => 'taxonomy', Chris@0: 'settings' => array( Chris@0: 'size' => 60, Chris@0: 'autocomplete_path' => 'taxonomy/autocomplete', Chris@0: ), Chris@0: ); Chris@0: } Chris@0: else { Chris@0: $instance['widget'] = array( Chris@0: 'type' => 'options_select', Chris@0: 'settings' => array(), Chris@0: ); Chris@0: } Chris@0: field_create_instance($instance); Chris@0: } Chris@0: $parents = array(); Chris@0: // Vocabularies without hierarchy get one term, single parent vocabularies get Chris@0: // one parent and one child term. Multiple parent vocabularies get three Chris@0: // terms: t0, t1, t2 where t0 is a parent of both t1 and t2. Chris@0: for ($j = 0; $j < $vocabulary->hierarchy + 1; $j++) { Chris@0: ++$term_id; Chris@0: $term = entity_create('taxonomy_term', array( Chris@0: 'vocabulary_machine_name' => $vocabulary->machine_name, Chris@0: // For multiple parent vocabularies, omit the t0-t1 relation, otherwise Chris@0: // every parent in the vocabulary is a parent. Chris@0: 'parent' => $vocabulary->hierarchy == 2 && i == 1 ? array() : $parents, Chris@0: 'name' => "term $term_id of vocabulary $voc_id (j=$j)", Chris@0: 'description' => 'description of ' . $term->name, Chris@0: 'format' => 'filtered_html', Chris@0: 'weight' => $i * 3 + $j, Chris@0: )); Chris@0: taxonomy_term_save($term); Chris@0: $terms[] = $term->tid; Chris@0: $term_vocabs[$term->tid] = 'taxonomy_' . $vocabulary->machine_name; Chris@0: $parents[] = $term->tid; Chris@0: } Chris@0: } Chris@0: $node_id = 0; Chris@0: $revision_id = 0; Chris@0: module_load_include('inc', 'node', 'node.pages'); Chris@0: for ($i = 0; $i < 36; $i++) { Chris@0: $uid = intval($i / 8) + 3; Chris@0: $user = user_load($uid); Chris@0: $node = new stdClass(); Chris@0: $node->uid = $uid; Chris@0: $node->type = 'page'; Chris@0: if ($i < 12) { Chris@0: $node->type = 'page'; Chris@0: } Chris@0: elseif ($i < 24) { Chris@0: $node->type = 'story'; Chris@0: } Chris@0: elseif (module_exists('blog')) { Chris@0: $node->type = 'blog'; Chris@0: } Chris@0: $node->sticky = 0; Chris@0: ++$node_id; Chris@0: ++$revision_id; Chris@0: $node->title = "node title $node_id rev $revision_id (i=$i)"; Chris@0: $node->language = LANGUAGE_NONE; Chris@0: $body_text = str_repeat("node body ($node->type) - $i", 100); Chris@0: $node->body[$node->language][0]['value'] = $body_text; Chris@0: $node->body[$node->language][0]['summary'] = text_summary($body_text); Chris@0: $node->body[$node->language][0]['format'] = 'filtered_html'; Chris@0: $node->status = intval($i / 4) % 2; Chris@0: $node->revision = $i < 12; Chris@0: $node->promote = $i % 2; Chris@0: $node->created = $now + $i * 86400; Chris@0: $node->log = "added $i node"; Chris@0: // Make every term association different a little. For nodes with revisions, Chris@0: // make the initial revision have a different set of terms than the Chris@0: // newest revision. Chris@0: $items = array(); Chris@0: if ($node->revision) { Chris@0: $node_terms = array($terms[$i], $terms[47-$i]); Chris@0: } Chris@0: else { Chris@0: $node_terms = $terms; Chris@0: unset($node_terms[$i], $node_terms[47 - $i]); Chris@0: } Chris@0: foreach ($node_terms as $tid) { Chris@0: $field_name = $term_vocabs[$tid]; Chris@0: $node->{$field_name}[LANGUAGE_NONE][] = array('tid' => $tid); Chris@0: } Chris@0: $node->path = array('alias' => "content/$node->created"); Chris@0: node_save($node); Chris@0: if ($node->revision) { Chris@0: $user = user_load($uid + 3); Chris@0: ++$revision_id; Chris@0: $node->title .= " rev2 $revision_id"; Chris@0: $body_text = str_repeat("node revision body ($node->type) - $i", 100); Chris@0: $node->body[$node->language][0]['value'] = $body_text; Chris@0: $node->body[$node->language][0]['summary'] = text_summary($body_text); Chris@0: $node->body[$node->language][0]['format'] = 'filtered_html'; Chris@0: $node->log = "added $i revision"; Chris@0: $node_terms = $terms; Chris@0: unset($node_terms[$i], $node_terms[47 - $i]); Chris@0: foreach ($node_terms as $tid) { Chris@0: $field_name = $term_vocabs[$tid]; Chris@0: $node->{$field_name}[LANGUAGE_NONE][] = array('tid' => $tid); Chris@0: } Chris@0: node_save($node); Chris@0: } Chris@0: } Chris@0: Chris@0: // Create poll content Chris@0: for ($i = 0; $i < 12; $i++) { Chris@0: $uid = intval($i / 4) + 3; Chris@0: $user = user_load($uid); Chris@0: $node = new stdClass(); Chris@0: $node->uid = $uid; Chris@0: $node->type = 'poll'; Chris@0: $node->sticky = 0; Chris@0: $node->title = "poll title $i"; Chris@0: $node->language = LANGUAGE_NONE; Chris@0: $node->status = intval($i / 2) % 2; Chris@0: $node->revision = 1; Chris@0: $node->promote = $i % 2; Chris@0: $node->created = REQUEST_TIME + $i * 43200; Chris@0: $node->runtime = 0; Chris@0: $node->active = 1; Chris@0: $node->log = "added $i poll"; Chris@0: $node->path = array('alias' => "content/poll/$i"); Chris@0: Chris@0: $nbchoices = ($i % 4) + 2; Chris@0: for ($c = 0; $c < $nbchoices; $c++) { Chris@0: $node->choice[] = array('chtext' => "Choice $c for poll $i", 'chvotes' => 0, 'weight' => 0); Chris@0: } Chris@0: node_save($node); Chris@0: $path = array( Chris@0: 'alias' => "content/poll/$i/results", Chris@0: 'source' => "node/$node->nid/results", Chris@0: ); Chris@0: path_save($path); Chris@0: Chris@0: // Add some votes Chris@0: $node = node_load($node->nid); Chris@0: $choices = array_keys($node->choice); Chris@0: $original_user = $GLOBALS['user']; Chris@0: for ($v = 0; $v < ($i % 4); $v++) { Chris@0: drupal_static_reset('ip_address'); Chris@0: $_SERVER['REMOTE_ADDR'] = "127.0.$v.1"; Chris@0: $GLOBALS['user'] = drupal_anonymous_user();// We should have already allowed anon to vote. Chris@0: $c = $v % $nbchoices; Chris@0: $form_state = array(); Chris@0: $form_state['values']['choice'] = $choices[$c]; Chris@0: $form_state['values']['op'] = t('Vote'); Chris@0: drupal_form_submit('poll_view_voting', $form_state, $node); Chris@0: } Chris@0: } Chris@0: Chris@0: $uid = 6; Chris@0: $node_type = 'broken'; Chris@0: $user = user_load($uid); Chris@0: $node = new stdClass(); Chris@0: $node->uid = $uid; Chris@0: $node->type = 'article'; Chris@0: $body_text = str_repeat("node body ($node_type) - 37", 100); Chris@0: $node->sticky = 0; Chris@0: $node->title = "node title 24"; Chris@0: $node->language = LANGUAGE_NONE; Chris@0: $node->body[$node->language][0]['value'] = $body_text; Chris@0: $node->body[$node->language][0]['summary'] = text_summary($body_text); Chris@0: $node->body[$node->language][0]['format'] = 'filtered_html'; Chris@0: $node->status = 1; Chris@0: $node->revision = 0; Chris@0: $node->promote = 0; Chris@0: $node->created = 1263769200; Chris@0: $node->log = "added a broken node"; Chris@0: $node->path = array('alias' => "content/1263769200"); Chris@0: node_save($node); Chris@0: db_update('node') Chris@0: ->fields(array( Chris@0: 'type' => $node_type, Chris@0: )) Chris@0: ->condition('nid', $node->nid) Chris@0: ->execute(); Chris@0: db_update('field_data_body') Chris@0: ->fields(array( Chris@0: 'bundle' => $node_type, Chris@0: )) Chris@0: ->condition('entity_id', $node->nid) Chris@0: ->condition('entity_type', 'node') Chris@0: ->execute(); Chris@0: db_update('field_revision_body') Chris@0: ->fields(array( Chris@0: 'bundle' => $node_type, Chris@0: )) Chris@0: ->condition('entity_id', $node->nid) Chris@0: ->condition('entity_type', 'node') Chris@0: ->execute(); Chris@0: db_update('field_config_instance') Chris@0: ->fields(array( Chris@0: 'bundle' => $node_type, Chris@0: )) Chris@0: ->condition('bundle', 'article') Chris@0: ->execute();