Commit 39df3d2a authored by Gerhard Killesreiter's avatar Gerhard Killesreiter

Moved generate scripts out of my sandbox as per Moshe's suggestions.

parent 5d395b34
......@@ -20,4 +20,10 @@ Please contribute your own useful functions. Just edit and commit this module wh
get the urge. No need to submit a patch!
-moshe weitzman
weitzman@tejasa.com
\ No newline at end of file
weitzman@tejasa.com
NOTE
====
The subdirectory generate/ includes some scripts that can be used to help testing
on a Drupal site. See generate/README for details.
Authors are Moshe Weitzman, Dries Buytaert, Jonathan Chaffer, and Gerhard Killesreiter.
generate-taxonomy-terms.php
===========================
This simple script creates terms out of an array of names which you provide. unlike
the other scripts in this directory, this one is meant for live sites which need to bulk
import data into the term table. See the source code comments for config instructions
generate-taxonomy.php
=====================
With this script you can generate several taxonomy vocabularies and
terms assigned to them.
Put it in the root directory of your Drupal installation, log into your
Drupal as user #1 and then access the script. It will remove the
existing vocabularies and terms and generates 15 vocabularies and 50 terms.
These values can be changed at the bottom of the file.
generate-content.php
====================
The script generate-content.php can be used to generate content to
test a Drupal site.
Put it in the root directory of your Drupal installation, log into your
Drupal as user #1 and then access the script. It will remove the
existing content and generate 50 nodes and 500 comments. These values can
be changed at the bottom of the file. If vocabularies and terms exist
terms will get assigned to the new nodes. Therefore you should run
generate-taxonomy.php before this script.
prefix-database.php
===================
This script can be used to add a prefix to all tables in database.mysql.
To use it, copy it into your drupal root directory, make the database
directory writable by the www server and access the file through your browser.
You will find a database definitions file with a d_ prefix in the database
directory. You can change the prefix by editing prefix-database.php.
update-teaser.php
=================
Use this script to regenerate the teasers in the node table.
generate-users.php
==================
A small script that reads users from a csv formatted file and puts them into your database.
<?php
// $Id$
include_once "includes/common.inc";
function create_nodes($records, $users) {
$types = array("story", "blog", "forum", "page");
$users = array_merge($users, array('0'));
// Insert new data:
for ($i = 1; $i <= $records; $i++) {
$node->uid = $users[array_rand($users)];
$node->type = $types[array_rand($types)];
$node->title = "node #$i ($node->type)";
$node->body = create_content();
$node->status = 1;
$node->promote = rand(0, 1);
$node->comment = 2;
$node->created = time();
$node->changed = time();
// Save the node:
node_save($node);
// Setup a path:
db_query("INSERT INTO {path} (src, dst) VALUES ('%s', '%s')", "node/view/$i", "$i");
print "created node #$i with alias ". url($i) ."<br />";
}
}
function create_comments($records, $users, $nodes, $comments) {
$users = array_merge($users, array('0'));
// Insert new data:
for ($i = 1; $i <= $records; $i++) {
$comment->cid = db_next_id("comments_cid");
$comment->nid = array_rand($nodes);
switch ($i % 3) {
case 1:
$comment->pid = db_result(db_query("SELECT cid FROM {comments} WHERE pid = 0 AND nid = %d ORDER BY RAND() LIMIT 1", $comment->nid));
break;
case 2:
$comment->pid = db_result(db_query("SELECT cid FROM {comments} WHERE pid > 0 AND nid = %d ORDER BY RAND() LIMIT 1", $comment->nid));
break;
default:
$comment->pid = 0;
}
$comment->subject = "comment #$i";
$comment->comment = "body of comment #$i";
$comment->uid = $users[array_rand($users)];
db_query("INSERT INTO {comments} (cid, nid, pid, uid, subject, comment, status, thread, timestamp) VALUES (%d, %d, %d, %d, '%s', '%s', %d, %d, %d)", $comment->cid, $comment->nid, $comment->pid, $comment->uid, $comment->subject, $comment->comment, 0, 0, time());
print "created comment #$i<br />";
}
}
function create_content() {
$nparas = rand(1,12);
$type = rand(0,3);
$output = "";
switch($type % 3) {
case 1: // html
for ($i = 1; $i <= $nparas; $i++) {
$output .= create_para(rand(10,60),1);
}
break;
case 2: // brs only
for ($i = 1; $i <= $nparas; $i++) {
$output .= create_para(rand(10,60),2);
}
break;
default: // plain text
for ($i = 1; $i <= $nparas; $i++) {
$output .= create_para(rand(10,60)) ."\n";
}
}
return $output;
}
function create_para($words, $type = 0) {
$output = "";
switch ($type) {
case 1:
$output .= "<p>";
$output .= create_greeking($words);
$output = trim($output) ."</p>";
break;
case 2:
$output .= create_greeking($words);
$output = trim($output) ."<br />";
break;
default:
$output .= create_greeking($words);
$output = trim($output);
}
return $output;
}
function create_greeking($words) {
$dictionary = array("abbas", "abdo", "abico", "abigo", "abluo", "accumsan",
"acsi", "ad", "adipiscing", "aliquam", "aliquip", "amet", "antehabeo",
"appellatio", "aptent", "at", "augue", "autem", "bene", "blandit",
"brevitas", "caecus", "camur", "capto", "causa", "cogo", "comis",
"commodo", "commoveo", "consectetuer", "consequat", "conventio", "cui",
"damnum", "decet", "defui", "diam", "dignissim", "distineo", "dolor",
"dolore", "dolus", "duis", "ea", "eligo", "elit", "enim", "erat",
"eros", "esca", "esse", "et", "eu", "euismod", "eum", "ex", "exerci",
"exputo", "facilisi", "facilisis", "fere", "feugiat", "gemino",
"genitus", "gilvus", "gravis", "haero", "hendrerit", "hos", "huic",
"humo", "iaceo", "ibidem", "ideo", "ille", "illum", "immitto",
"importunus", "imputo", "in", "incassum", "inhibeo", "interdico",
"iriure", "iusto", "iustum", "jugis", "jumentum", "jus", "laoreet",
"lenis", "letalis", "lobortis", "loquor", "lucidus", "luctus", "ludus",
"luptatum", "macto", "magna", "mauris", "melior", "metuo", "meus",
"minim", "modo", "molior", "mos", "natu", "neo", "neque", "nibh",
"nimis", "nisl", "nobis", "nostrud", "nulla", "nunc", "nutus", "obruo",
"occuro", "odio", "olim", "oppeto", "os", "pagus", "pala", "paratus",
"patria", "paulatim", "pecus", "persto", "pertineo", "plaga", "pneum",
"populus", "praemitto", "praesent", "premo", "probo", "proprius",
"quadrum", "quae", "qui", "quia", "quibus", "quidem", "quidne", "quis",
"ratis", "refero", "refoveo", "roto", "rusticus", "saepius",
"sagaciter", "saluto", "scisco", "secundum", "sed", "si", "similis",
"singularis", "sino", "sit", "sudo", "suscipere", "suscipit", "tamen",
"tation", "te", "tego", "tincidunt", "torqueo", "tum", "turpis",
"typicus", "ulciscor", "ullamcorper", "usitas", "ut", "utinam",
"utrum", "uxor", "valde", "valetudo", "validus", "vel", "velit",
"veniam", "venio", "vereor", "vero", "verto", "vicis", "vindico",
"virtus", "voco", "volutpat", "vulpes", "vulputate", "wisi", "ymo",
"zelus");
$greeking = "";
while ($words > 0) {
$sentence_length = rand(3,10);
$greeking .= ucfirst($dictionary[array_rand($dictionary)]);
for ($i = 1; $i < $sentence_length; $i++) {
$greeking .= " " . $dictionary[array_rand($dictionary)];
}
$greeking .= ". ";
$words -= $sentence_length;
}
return $greeking;
}
function add_terms($nodes, $terms) {
if(count($terms) > 0){
foreach($nodes as $nid => $type) {
$tid = $terms[$type][@array_rand($terms[$type])];
if ($tid) {
db_query("INSERT INTO {term_node} (nid, tid) VALUES (%d, %d)", $nid, $tid);
}
}
}
}
function get_users() {
$users = array();
$result = db_query("SELECT uid FROM users");
while($user = db_fetch_object($result)){
$users[] = $user->uid;
}
return $users;
}
function get_nodes() {
$nodes = array();
$result = db_query("SELECT nid, type FROM node WHERE type IN ('story', 'blog', 'forum', 'page') AND comment = 2");
while($node = db_fetch_object($result)){
$nodes[$node->nid] = $node->type ;
}
return $nodes;
}
function get_comments() {
$comments = array();
$result = db_query("SELECT nid, cid FROM comments");
while($comment = db_fetch_object($result)){
$comments[$comment->nid][] = $comment->cid ;
}
return comments;
}
function get_terms() {
$terms = array();
$result = db_query("SELECT d.tid, v.vid, v.nodes FROM {vocabulary} v, {term_data} d WHERE v.vid = d.vid");
while($term = db_fetch_object($result)){
$types =explode(",", $term->nodes);
foreach($types as $type) {
$terms[$type][] = $term->tid;
}
}
return $terms;
}
db_query("DELETE FROM {comments}");
db_query("DELETE FROM {node}");
db_query("DELETE FROM {forum}");
db_query("DELETE FROM {page}");
db_query("DELETE FROM {path}");
db_query("UPDATE {sequences} SET id = '0' WHERE name = 'node_nid'");
db_query("UPDATE {sequences} SET id = '0' WHERE name = 'comments_cid'");
db_query("ALTER TABLE {node} AUTO_INCREMENT = 1");
db_query("ALTER TABLE {comments} AUTO_INCREMENT = 1");
// get user id
$users = get_users();
$terms = get_terms();
// create 100 pseudo-random nodes:
create_nodes(50, $users);
$nodes = get_nodes();
add_terms($nodes, $terms);
$comments = get_comments();
create_comments(500, $users, $nodes, $comments);
?>
<?php
// written by Moshe Weitzman - weitzman at tejasa.com - July 2003
// BEWARE! this script adds data to your database
// -------------------------
// CONFIGURATION
// Change the value below to TRUE when you want to run the script After running, immediately
// change back to FALSE in order to prevent accidentally executing this script twice.
$active = FALSE;
// Enter the vocabulary ID into which you want to insert terms
$vid = 88;
// create an array of term names. order doesn't
// matter since Drupal will present them alphabetically
$terms = array (
"Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Carolina","North Dakota","Ohio","Oklahoma","Oregon","Pennsylvania","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","West Virginia","Wisconsin","Wyoming","Washington D.C."
);
// -------------------------
// CODE
include_once("includes/common.inc");
if ($active) {
if (user_access("administer taxonomy")) {
foreach ($terms as $term) {
$edit = array ("vid" => $vid, "name" => $term );
$msg = taxonomy_save_term($edit);
print status($msg);
}
}
else {
print status("You have insufficent permission to administer taxonomya");
}
}
else {
print status("You have not activated term_loader. See $active variable at top of the source code");
}
?>
\ No newline at end of file
<?php
// $Id$
include_once "includes/common.inc";
function create_vocabularies($records) {
$types = array("story", "blog", "forum", "page");
// Insert new data:
for ($i = 1; $i <= $records; $i++) {
$voc->name = "vocabulary #$i";
$voc->description = "description of vocabulary #$i";
$voc->nodes = array($types[array_rand($types)]);
$voc->multiple = 1;
$voc->required = 0;
$voc->relations = 1;
$voc->hierarchy = 1;
$voc->weight = rand(0,10);
taxonomy_save_vocabulary(object2array($voc));
print "created vocabulary #$i<br />";
}
}
function create_terms($records, $vocs) {
// Insert new data:
for ($i = 1; $i <= $records; $i++) {
switch ($i % 2) {
case 1:
$term->vid = $vocs[array_rand($vocs)];
$term->parent = 0;
break;
case 2:
default:
$parent = db_fetch_object(db_query("SELECT t.tid, v.vid FROM {term_data} t, {vocabulary} v WHERE v.vid = t.vid ORDER BY RAND() LIMIT 1"));
$term->parent = $parent->tid;
$term->vid = $parent->vid;
break;
}
$term->name = "term #$i";
$term->description = "description of term #$i";
$term->weight = rand(0,10);
taxonomy_save_term(object2array($term));
print "created term #$i<br />";
}
}
function get_vocabularies() {
$vocs = array();
$result = db_query("SELECT vid FROM vocabulary");
while($voc = db_fetch_object($result)){
$vocs[] = $voc->vid;
}
return $vocs;
}
db_query("DELETE FROM {term_data}");
db_query("DELETE FROM {term_node}");
db_query("DELETE FROM {term_hierarchy}");
db_query("DELETE FROM {term_relation}");
db_query("DELETE FROM {term_synonym}");
db_query("DELETE FROM {vocabulary}");
db_query("UPDATE sequences SET id = '0' WHERE name = 'vocabulary_vid'");
db_query("UPDATE sequences SET id = '0' WHERE name = 'term_data_tid'");
create_vocabularies(15);
$vocs = get_vocabularies();
create_terms(50, $vocs);
?>
\ No newline at end of file
<?php
// Reads a csv formatted file and creates users.
// $Id$
include "includes/common.inc";
$handle = fopen("daten.csv", "r");
while ($data = fgetcsv ($handle, 1000, ";")) {
$array = array("name" => $data[0], "pass" => $data[1], "mail" => $data[2], "status" => 1, "rid" => _user_authenticated_id());
user_save($account, $array);
}
fclose ($handle);
?>
<?php
$prefix = "d_";
$file = file("database/database.mysql");
$fp = fopen("database/database-prefixed.mysql", "w");
foreach($file as $line){
$line = str_replace("CREATE TABLE ", "CREATE TABLE ". $prefix, $line);
$line = str_replace("INSERT INTO ", "INSERT INTO ". $prefix, $line);
$line = str_replace("REPLACE ", "REPLACE ". $prefix, $line);
fwrite($fp, $line);
}
fclose($fp);
?>
<?php
// $Id$
include "includes/common.inc";
$result = db_query("SELECT nid,body,teaser FROM node");
while ($node = db_fetch_object($result)) {
$teaser = node_teaser($node->body);
db_query("UPDATE node SET teaser = '%s' WHERE nid = %d", $teaser, $node->nid);
}
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment