Commit 6f02738c authored by Dries's avatar Dries
Browse files

- Removed the "history"-field from the SQL table "users" and added
  this information to the "users"-field in both nodes and comments.
  This database/table change reduces the number of SQL queries and
  makes Drupal scale better where a lot of voting/moderation takes
  place.  Last but not least it can be considered a new and better
  foundation for future moderation metrics / algorithms.  In other
  words: it is plain better.

    --> oops, all voting/moderation results will be lost!
    --> requires database update, see "2.00-to-x.xx.sql"!

- Updated database/database.mysql
parent 0b13183e
......@@ -75,6 +75,7 @@ CREATE TABLE category (
expire int(3) DEFAULT '0' NOT NULL,
comment int(2) unsigned DEFAULT '0' NOT NULL,
submission int(2) unsigned DEFAULT '0' NOT NULL,
promote int(2) unsigned DEFAULT '0' NOT NULL,
UNIQUE name (name),
PRIMARY KEY (cid)
);
......@@ -112,6 +113,7 @@ CREATE TABLE comments (
score int(6) DEFAULT '0' NOT NULL,
votes int(6) DEFAULT '0' NOT NULL,
link varchar(16) DEFAULT '' NOT NULL,
users text NOT NULL,
PRIMARY KEY (cid),
KEY lid (lid)
);
......@@ -127,6 +129,18 @@ CREATE TABLE crons (
PRIMARY KEY (module)
);
#
# Table structure for table 'cvs'
#
DROP TABLE IF EXISTS cvs;
CREATE TABLE cvs (
user varchar(32) DEFAULT '' NOT NULL,
files text,
status int(2) DEFAULT '0' NOT NULL,
message text,
timestamp int(11) DEFAULT '0' NOT NULL
);
#
# Table structure for table 'diaries'
#
......@@ -139,6 +153,17 @@ CREATE TABLE diaries (
PRIMARY KEY (id)
);
#
# Table structure for table 'forum'
#
DROP TABLE IF EXISTS forum;
CREATE TABLE forum (
lid int(10) unsigned DEFAULT '0' NOT NULL auto_increment,
nid int(10) unsigned DEFAULT '0' NOT NULL,
body text NOT NULL,
PRIMARY KEY (lid)
);
#
# Table structure for table 'headlines'
#
......@@ -195,10 +220,8 @@ CREATE TABLE modules (
DROP TABLE IF EXISTS node;
CREATE TABLE node (
nid int(10) unsigned DEFAULT '0' NOT NULL auto_increment,
lid int(10) unsigned DEFAULT '0' NOT NULL,
pid int(10) unsigned DEFAULT '0' NOT NULL,
cid int(10) unsigned DEFAULT '0' NOT NULL,
tid int(10) unsigned DEFAULT '0' NOT NULL,
lid int(10) DEFAULT '0' NOT NULL,
pid int(10) DEFAULT '0' NOT NULL,
log text NOT NULL,
type varchar(16) DEFAULT '' NOT NULL,
title varchar(128) DEFAULT '' NOT NULL,
......@@ -206,12 +229,19 @@ CREATE TABLE node (
votes int(11) DEFAULT '0' NOT NULL,
author int(6) DEFAULT '0' NOT NULL,
status int(4) DEFAULT '1' NOT NULL,
comment int(2) DEFAULT '1' NOT NULL,
timestamp int(11) DEFAULT '0' NOT NULL,
cid int(10) unsigned DEFAULT '0' NOT NULL,
tid int(10) unsigned DEFAULT '0' NOT NULL,
comment int(2) DEFAULT '1' NOT NULL,
promote int(2) DEFAULT '1' NOT NULL,
moderate text NOT NULL,
users text NOT NULL,
KEY type (lid,type),
KEY author (author),
KEY title (title,type),
PRIMARY KEY (nid)
PRIMARY KEY (nid),
KEY promote (promote),
KEY status (status)
);
#
......@@ -249,6 +279,33 @@ CREATE TABLE story (
PRIMARY KEY (lid)
);
#
# Table structure for table 'testac'
#
DROP TABLE IF EXISTS testac;
CREATE TABLE testac (
object_id int(11),
object_title varchar(64)
);
#
# Table structure for table 'testad'
#
DROP TABLE IF EXISTS testad;
CREATE TABLE testad (
object_id int(11),
object_title varchar(64)
);
#
# Table structure for table 'testae'
#
DROP TABLE IF EXISTS testae;
CREATE TABLE testae (
object_id int(11),
object_title varchar(64)
);
#
# Table structure for table 'topic'
#
......@@ -257,6 +314,7 @@ CREATE TABLE topic (
tid int(10) unsigned DEFAULT '0' NOT NULL auto_increment,
pid int(10) unsigned DEFAULT '0' NOT NULL,
name varchar(32) DEFAULT '' NOT NULL,
moderate text NOT NULL,
UNIQUE name (name),
PRIMARY KEY (tid)
);
......@@ -283,7 +341,6 @@ CREATE TABLE users (
last_access int(10) unsigned,
last_host varchar(255),
status tinyint(4) DEFAULT '0' NOT NULL,
history text NOT NULL,
hash varchar(12) DEFAULT '' NOT NULL,
timezone varchar(8),
rating decimal(8,2),
......
......@@ -31,12 +31,12 @@ function comment_moderate($moderate) {
$none = $comment_votes[key($comment_votes)];
foreach ($moderate as $id=>$vote) {
if ($vote != $comment_votes[$none] && !user_get($user, "history", "c$id")) {
// update the comment's score:
$result = db_query("UPDATE comments SET score = score ". check_input($vote) .", votes = votes + 1 WHERE cid = '". check_input($id) ."'");
// update the user's history:
$user = user_set($user, "history", "c$id", $vote);
if ($vote != $comment_votes[$none]) {
$id = check_input($id); $vote = check_input($vote);
$comment = db_fetch_object(db_query("SELECT * FROM comments WHERE cid = '$id'"));
if ($comment && !field_get($comment, "users", $user->userid)) {
$result = db_query("UPDATE comments SET score = score $vote, votes = votes + 1, users = '". field_set($comment, "users", $user->userid, $vote) ."' WHERE cid = '$id'");
}
}
}
}
......@@ -162,7 +162,7 @@ function comment_moderation($comment) {
// preview comment:
$output .= " ";
}
else if ($user->id && $user->userid != $comment->userid && !user_get($user, "history", "c$comment->cid")) {
else if ($user->id && $user->userid != $comment->userid && !field_get($comment, "users", $user->userid)) {
// comment hasn't been moderated yet:
foreach ($comment_votes as $key=>$value) $options .= " <OPTION VALUE=\"$value\">$key</OPTION>\n";
$output .= "<SELECT NAME=\"moderate[$comment->cid]\">$options</SELECT>\n";
......
......@@ -199,6 +199,43 @@ function form_submit($value) {
return "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". check_textfield($value) ."\">\n";
}
function field_get($object, $variable, $field) {
$data = explode(";", $object->$variable);
for (reset($data); current($data); next($data)) {
$entry = explode(":", current($data));
if (reset($entry) == $field) $rval = end($entry);
}
return $rval;
}
function field_set($object, $variable, $name, $value) {
$field = $object->$variable;
if (!$value) {
// remove entry:
$data = explode(";", $field);
for (reset($data); current($data); next($data)) {
$entry = explode(":", current($data));
if ($entry[0] != $name) $rval .= "$entry[0]:$entry[1];";
}
}
else if (strstr($field, "$name:")) {
// found: update exsisting entry:
$data = explode(";", $field);
for (reset($data); current($data); next($data)) {
$entry = explode(":", current($data));
if ($entry[0] == $name) $entry[1] = $value;
$rval .= "$entry[0]:$entry[1];";
}
}
else {
// not found:
$rval = "$field$name:$value;";
}
return $rval;
}
$conf = conf_init();
include_once "includes/$conf.php";
......
......@@ -102,16 +102,14 @@ function theme_morelink($theme, $node) {
}
function theme_moderation_results($theme, $node) {
global $user;
if ($user->id && $node->nid && ($user->id == $node->author || user_get($user, "history", "n$node->nid"))) {
$result = db_query("SELECT * FROM users WHERE history LIKE '%n$node->nid%'");
while ($account = db_fetch_object($result)) {
$output .= format_username($account->userid) ." voted '". user_get($account, "history", "n$node->nid") ."'.<BR>";
foreach (explode(";", $node->users) as $vote) {
if ($vote) {
$data = explode(":", $vote);
$output .= format_username($data[0]) ." voted '$data[1]'.<BR>";
}
$theme->box(t("Moderation results"), ($output ? $output : t("This node has not been moderated yet.")));
}
$theme->box(t("Moderation results"), ($output ? $output : t("This node has not been moderated yet.")));
}
/*
......
......@@ -52,46 +52,9 @@ function user_save($account, $array) {
return user_load(($account->userid ? $account->userid : $array[userid]));
}
function user_get($account, $column, $field) {
$data = explode(";", $account->$column);
for (reset($data); current($data); next($data)) {
$entry = explode(":", current($data));
if (reset($entry) == $field) $rval = end($entry);
}
return $rval;
}
function user_set($account, $column, $name, $value) {
$field = $account->$column;
if (!$value) {
// remove entry:
$data = explode(";", $field);
for (reset($data); current($data); next($data)) {
$entry = explode(":", current($data));
if ($entry[0] != $name) $rval .= "$entry[0]:$entry[1];";
}
}
else if (strstr($field, "$name:")) {
// found: update exsisting entry:
$data = explode(";", $field);
for (reset($data); current($data); next($data)) {
$entry = explode(":", current($data));
if ($entry[0] == $name) $entry[1] = $value;
$rval .= "$entry[0]:$entry[1];";
}
}
else {
// not found:
$rval = "$field$name:$value;";
}
return user_save($account, array($column => $rval));
}
function user_access($account, $section = 0) {
global $user;
if ($section) return (user_get($account, "access", $section) || $account->id == 1);
if ($section) return (field_get($account, "access", $section) || $account->id == 1);
else return ($account->access || $account->id == 1);
}
......
......@@ -140,8 +140,7 @@ function account_delete($name) {
function account_edit_save($name, $edit) {
foreach ($edit as $key=>$value) if ($key != "access") $query .= "$key = '". addslashes($value) ."', ";
db_query("UPDATE users SET $query access = '' WHERE userid = '$name'");
if ($edit[access]) foreach ($edit[access] as $key=>$value) user_set(user_load($name), "access", $value, 1);
if ($edit[access]) foreach ($edit[access] as $key=>$value) db_query("UPDATE users SET access = '". field_set(user_load($name), "access", $value, 1) ."'");
watchdog("message", "account: modified user '$name'");
}
......
......@@ -18,14 +18,13 @@ function queue_score($id) {
function queue_vote($id, $vote) {
global $status, $user;
if (!user_get($user, "history", "n$id")) {
// Update submission's score- and votes-field:
db_query("UPDATE node SET score = score $vote, votes = votes + 1 WHERE nid = $id");
if ($node = node_get_object(nid, $id)) {
// Update user's history record:
$user = user_set($user, "history", "n$id", $vote);
if (!field_get($node, "users", $user->userid)) {
// Update submission's score- and votes-field:
db_query("UPDATE node SET score = score $vote, votes = votes + 1, users = '". field_set($node, "users", $user->userid, $vote) ."' WHERE nid = $id");
if ($node = node_get_object(nid, $id)) {
if (variable_get("post_threshold", 4, $node) <= $node->score) {
node_save(array(nid => $id, status => $status[posted]), array(status));
watchdog("message", "node: posted '$node->title' - moderation");
......@@ -50,7 +49,7 @@ function queue_overview() {
$content .= "<TABLE BORDER=\"0\" CELLSPACING=\"4\" CELLPADDING=\"4\">\n";
$content .= " <TR><TH>". t("Subject") ."</TH><TH>". t("Author") ."</TH><TH>". t("Type") ."</TH><TH>". t("Score") ."</TH></TR>\n";
while ($node = db_fetch_object($result)) {
if ($user->id == $node->author || user_get($user, "history", "n$node->nid")) $content .= " <TR><TD><A HREF=\"module.php?mod=queue&op=view&id=$node->nid\">". check_output($node->title) ."</A></TD><TD ALIGN=\"center\">". format_username($node->userid) ."</TD><TD ALIGN=\"center\">". check_output($node->type) ."</TD><TD ALIGN=\"center\">". queue_score($node->nid) ."</TD></TR>\n";
if ($user->id == $node->author || field_get($node, "users", $user->userid)) $content .= " <TR><TD><A HREF=\"module.php?mod=queue&op=view&id=$node->nid\">". check_output($node->title) ."</A></TD><TD ALIGN=\"center\">". format_username($node->userid) ."</TD><TD ALIGN=\"center\">". check_output($node->type) ."</TD><TD ALIGN=\"center\">". queue_score($node->nid) ."</TD></TR>\n";
else $content .= " <TR><TD><A HREF=\"module.php?mod=queue&op=view&id=$node->nid\">". check_output($node->title) ."</A></TD><TD ALIGN=\"center\">". format_username($node->userid) ."</TD><TD ALIGN=\"center\">". check_output($node->type) ."</TD><TD ALIGN=\"center\"><A HREF=\"module.php?mod=queue&op=view&id=$node->nid\">". t("vote") ."</A></TD></TR>\n";
}
$content .= "</TABLE>\n";
......@@ -66,7 +65,7 @@ function queue_node($id) {
$node = node_get_object(nid, $id);
if ($user->id == $node->author || user_get($user, "history", "n$node->nid")) {
if ($user->id == $node->author || field_get($node, "users", $user->userid)) {
header("Location: node.php?id=$node->nid");
}
else {
......
......@@ -136,3 +136,8 @@ ALTER TABLE node ADD moderate TEXT NOT NULL;
# 10/05/2001:
ALTER TABLE topic ADD moderate TEXT NOT NULL;
# 16/05/2001
ALTER TABLE node ADD users TEXT NOT NULL;
ALTER TABLE comments ADD users TEXT NOT NULL;
ALTER TABLE users DROP history;
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