Commit d9d6a6e0 authored by Dries's avatar Dries

- Patch #7582 by Gerhard: improved node revisions!

All node revisions were stored in a serialized field in the node table and retrieved for _each_ page view although they are rarely needed. We created a separate revisions table which would be in principle identical to the node table, only that it could have several old copies of the same node.  This also allows us to revision-related information, and to provide log entries to non-book pages when a new revision is being created.

TODO:

1. Provide upgrade instructions for node module maintainers!
2. Upgrade modules that implement node types.
3. Provide an upgarde path for revisions.  Dependency on the upgrade system.
parent 7e5d0c94
......@@ -136,11 +136,12 @@ CREATE TABLE blocks (
--
CREATE TABLE book (
vid int(10) unsigned NOT NULL default '0',
nid int(10) unsigned NOT NULL default '0',
parent int(10) NOT NULL default '0',
weight tinyint(3) NOT NULL default '0',
log longtext,
PRIMARY KEY (nid),
PRIMARY KEY (vid),
KEY nid (nid),
KEY parent (parent)
) TYPE=MyISAM;
......@@ -243,12 +244,14 @@ CREATE TABLE directory (
CREATE TABLE files (
fid int(10) unsigned NOT NULL default '0',
nid int(10) unsigned NOT NULL default '0',
vid int(10) unsigned NOT NULL default '0',
filename varchar(255) NOT NULL default '',
filepath varchar(255) NOT NULL default '',
filemime varchar(255) NOT NULL default '',
filesize int(10) unsigned NOT NULL default '0',
list tinyint(1) unsigned NOT NULL default '0',
PRIMARY KEY (fid)
KEY vid (vid),
KEY fid (fid)
) TYPE=MyISAM;
--
......@@ -403,6 +406,7 @@ CREATE TABLE moderation_votes (
CREATE TABLE node (
nid int(10) unsigned NOT NULL auto_increment,
vid int(10) unsigned NOT NULL default '0',
type varchar(32) NOT NULL default '',
title varchar(128) NOT NULL default '',
uid int(10) NOT NULL default '0',
......@@ -412,16 +416,13 @@ CREATE TABLE node (
comment int(2) NOT NULL default '0',
promote int(2) NOT NULL default '0',
moderate int(2) NOT NULL default '0',
teaser longtext NOT NULL,
body longtext NOT NULL,
revisions longtext NOT NULL,
sticky int(2) NOT NULL default '0',
format int(4) NOT NULL default '0',
PRIMARY KEY (nid),
KEY node_type (type(4)),
KEY node_title_type (title,type(4)),
KEY status (status),
KEY uid (uid),
KEY vid (vid),
KEY node_moderate (moderate),
KEY node_promote_status (promote, status),
KEY node_created (created),
......@@ -443,6 +444,24 @@ CREATE TABLE node_access (
PRIMARY KEY (nid,gid,realm)
) TYPE=MyISAM;
--
-- Table structure for table 'node_revisions'
--
CREATE TABLE node_revisions (
nid int(10) unsigned NOT NULL,
vid int(10) unsigned NOT NULL,
uid int(10) NOT NULL default '0',
title varchar(128) NOT NULL default '',
body longtext NOT NULL default '',
teaser longtext NOT NULL default '',
log longtext NOT NULL default '',
timestamp int(11) NOT NULL default '0',
format int(4) NOT NULL default '0',
PRIMARY KEY (nid,vid),
KEY uid (uid)
) TYPE=MyISAM;
--
-- Table structure for table 'profile_fields'
--
......
......@@ -131,12 +131,13 @@ CREATE TABLE blocks (
--
CREATE TABLE book (
vid integer NOT NULL default '0',
nid integer NOT NULL default '0',
parent integer NOT NULL default '0',
weight smallint NOT NULL default '0',
log text default '',
PRIMARY KEY (nid)
PRIMARY KEY (vid)
);
CREATE INDEX book_vid_idx ON book(vid);
CREATE INDEX book_nid_idx ON book(nid);
CREATE INDEX book_parent ON book(parent);
......@@ -239,13 +240,15 @@ CREATE TABLE directory (
CREATE TABLE files (
fid SERIAL,
nid integer NOT NULL default '0',
vid integer NOT NULL default '0',
filename varchar(255) NOT NULL default '',
filepath varchar(255) NOT NULL default '',
filemime varchar(255) NOT NULL default '',
filesize integer NOT NULL default '0',
list smallint NOT NULL default '0',
PRIMARY KEY (fid)
list smallint NOT NULL default '0'
);
CREATE INDEX files_fid_idx ON files(fid);
CREATE INDEX files_vid_idx ON files(vid);
--
-- Table structure for table 'filter_formats'
......@@ -403,6 +406,7 @@ CREATE TABLE moderation_votes (
CREATE TABLE node (
nid SERIAL,
vid integer NOT NULL default '0',
type varchar(32) NOT NULL default '',
title varchar(128) NOT NULL default '',
uid integer NOT NULL default '0',
......@@ -412,11 +416,7 @@ CREATE TABLE node (
comment integer NOT NULL default '0',
promote integer NOT NULL default '0',
moderate integer NOT NULL default '0',
teaser text NOT NULL default '',
body text NOT NULL default '',
revisions text NOT NULL default '',
sticky integer NOT NULL default '0',
format smallint NOT NULL default '0',
PRIMARY KEY (nid)
);
CREATE INDEX node_type_idx ON node(type);
......@@ -427,6 +427,7 @@ CREATE INDEX node_moderate_idx ON node (moderate);
CREATE INDEX node_promote_status_idx ON node (promote, status);
CREATE INDEX node_created ON node(created);
CREATE INDEX node_changed ON node(changed);
CREATE INDEX node_vid_idx ON node(vid);
--
-- Table structure for table `node_access`
......@@ -442,6 +443,24 @@ CREATE TABLE node_access (
PRIMARY KEY (nid,gid,realm)
);
--
-- Table structure for table 'node_revisions'
--
CREATE TABLE node_revisions (
nid integer NOT NULL default '0',
vid integer NOT NULL default '0',
uid integer NOT NULL default '0',
title varchar(128) NOT NULL default '',
body text NOT NULL default '',
teaser text NOT NULL default '',
log text NOT NULL default '',
timestamp integer NOT NULL default '0',
format int NOT NULL default '0',
PRIMARY KEY (nid,vid)
);
CREATE INDEX node_revisions_uid_idx ON node_revisions(uid);
CREATE SEQUENCE node_revisions_vid_seq INCREMENT 1 START 1;
--
-- Table structure for table 'node_counter'
......
......@@ -43,7 +43,8 @@
"2005-07-29" => "update_142",
"2005-07-30" => "update_143",
"2005-08-08" => "update_144",
"2005-08-15" => "update_145"
"2005-08-15" => "update_145",
"2005-08-25" => "update_146"
);
function update_110() {
......@@ -705,6 +706,78 @@ function update_145() {
return $ret;
}
function update_146() {
$ret = array();
if ($GLOBALS['db_type'] == 'mysql') {
$ret[] = update_sql("CREATE TABLE {node_revisions}
SELECT nid, nid AS vid, uid, type, title, body, teaser, changed AS timestamp, format
FROM {node}");
$ret[] = update_sql("ALTER TABLE {node_revisions} CHANGE nid nid int(10) unsigned NOT NULL default '0'");
$ret[] = update_sql("ALTER TABLE {node_revisions} ADD log longtext");
$ret[] = update_sql("ALTER TABLE {node} ADD vid int(10) unsigned NOT NULL default '0'");
$ret[] = update_sql("ALTER TABLE {files} ADD vid int(10) unsigned NOT NULL default '0'");
$ret[] = update_sql("ALTER TABLE {book} ADD vid int(10) unsigned NOT NULL default '0'");
$ret[] = update_sql("ALTER TABLE {forum} ADD vid int(10) unsigned NOT NULL default '0'");
$ret[] = update_sql("ALTER TABLE {book} DROP PRIMARY KEY");
$ret[] = update_sql("ALTER TABLE {forum} DROP PRIMARY KEY");
$ret[] = update_sql("ALTER TABLE {files} DROP PRIMARY KEY");
$ret[] = update_sql("UPDATE {node} SET vid = nid");
$ret[] = update_sql("UPDATE {forum} SET vid = nid");
$ret[] = update_sql("UPDATE {book} SET vid = nid");
$ret[] = update_sql("UPDATE {files} SET vid = nid");
$ret[] = update_sql("ALTER TABLE {book} ADD PRIMARY KEY vid (vid)");
$ret[] = update_sql("ALTER TABLE {forum} ADD PRIMARY KEY vid (vid)");
$ret[] = update_sql("ALTER TABLE {node_revisions} ADD PRIMARY KEY vid (vid)");
$ret[] = update_sql("ALTER TABLE {node_revisions} ADD KEY nid (nid)");
$ret[] = update_sql("ALTER TABLE {node_revisions} ADD KEY uid (uid)");
$ret[] = update_sql("CREATE TABLE {old_revisions} SELECT nid, type, revisions FROM {node} WHERE revisions != ''");
$ret[] = update_sql("ALTER TABLE {book} ADD KEY nid (nid)");
$ret[] = update_sql("ALTER TABLE {forum} ADD KEY nid (nid)");
$ret[] = update_sql("ALTER TABLE {files} ADD KEY fid (fid)");
$ret[] = update_sql("ALTER TABLE {files} ADD KEY vid (vid)");
$vid = db_next_id('{node}_nid');
$ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{node_revisions}_vid', $vid)");
}
else { // pgsql
$ret[] = update_sql("CREATE TABLE {node_revisions} AS
SELECT nid, nid AS vid, uid, type, title, body, teaser, changed AS timestamp, format
FROM {node}");
$ret[] = update_sql("UPDATE {node} SET vid = nid");
$ret[] = update_sql("UPDATE {forum} SET vid = nid");
$ret[] = update_sql("UPDATE {book} SET vid = nid");
$ret[] = update_sql("UPDATE {files} SET vid = nid");
$ret[] = update_sql("CREATE TABLE {old_revisions} AS SELECT nid, type, revisions FROM {node} WHERE revisions != ''");
}
// Move logs too.
$result = db_query("SELECT nid, log FROM {book} WHERE log != ''");
while ($row = db_fetch_object($result)) {
db_query("UPDATE {node_revisions} SET log = '%s' WHERE vid = %d", $row->log, $row->nid);
}
if ($GLOBALS['db_type'] == 'mysql') {
$ret[] = update_sql("ALTER TABLE {book} DROP log");
$ret[] = update_sql("ALTER TABLE {node} DROP teaser");
$ret[] = update_sql("ALTER TABLE {node} DROP body");
$ret[] = update_sql("ALTER TABLE {node} DROP format");
$ret[] = update_sql("ALTER TABLE {node} DROP revisions");
}
else { // pgsql
}
return $ret;
}
function update_sql($sql) {
$edit = $_POST["edit"];
$result = db_query($sql);
......
......@@ -218,9 +218,9 @@ function blogapi_blogger_new_post($appkey, $blogid, $username, $password, $conte
return blogapi_error(t('You do not have permission to create the type of post you wanted to create.'));
}
$nid = node_save($node);
if ($nid) {
watchdog('content', t('%type: added %title using blog API.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), "node/$nid"));
node_save(&$node);
if ($node->nid) {
watchdog('content', t('%type: added %title using blog API.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid"));
return $nid;
}
......@@ -276,9 +276,9 @@ function blogapi_blogger_edit_post($appkey, $postid, $username, $password, $cont
foreach ($terms as $term) {
$node->taxonomy[] = $term->tid;
}
$nid = node_save($node);
if ($nid) {
watchdog('content', t('%type: updated %title using blog API.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), "node/$nid"));
node_save(&$node);
if ($node->nid) {
watchdog('content', t('%type: updated %title using blog API.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid"));
return true;
}
......@@ -325,7 +325,12 @@ function blogapi_blogger_get_recent_posts($appkey, $blogid, $username, $password
}
$type = _blogapi_blogid($blogid);
$result = db_query_range('SELECT n.nid, n.title,'. ($bodies ? ' n.body,' : '') ." n.created, u.name FROM {node} n, {users} u WHERE n.uid=u.uid AND n.type = '%s' AND n.uid = %d ORDER BY n.created DESC", $type, $user->uid, 0, $number_of_posts);
if ($bodies) {
$result = db_query_range("SELECT n.nid, n.title, r.body, n.created, u.name FROM {node} n, {node_revisions} r, {users} u WHERE n.uid = u.uid AND n.vid = r.vid AND n.type = '%s' AND n.uid = %d ORDER BY n.created DESC", $type, $user->uid, 0, $number_of_posts);
}
else {
$result = db_query_range("SELECT n.nid, n.title, n.created, u.name FROM {node} n, {users} u WHERE n.uid = u.uid AND n.type = '%s' AND n.uid = %d ORDER BY n.created DESC", $type, $user->uid, 0, $number_of_posts);
}
while ($blog = db_fetch_object($result)) {
$blogs[] = _blogapi_get_post($blog, $bodies);
}
......
......@@ -218,9 +218,9 @@ function blogapi_blogger_new_post($appkey, $blogid, $username, $password, $conte
return blogapi_error(t('You do not have permission to create the type of post you wanted to create.'));
}
$nid = node_save($node);
if ($nid) {
watchdog('content', t('%type: added %title using blog API.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), "node/$nid"));
node_save(&$node);
if ($node->nid) {
watchdog('content', t('%type: added %title using blog API.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid"));
return $nid;
}
......@@ -276,9 +276,9 @@ function blogapi_blogger_edit_post($appkey, $postid, $username, $password, $cont
foreach ($terms as $term) {
$node->taxonomy[] = $term->tid;
}
$nid = node_save($node);
if ($nid) {
watchdog('content', t('%type: updated %title using blog API.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), "node/$nid"));
node_save(&$node);
if ($node->nid) {
watchdog('content', t('%type: updated %title using blog API.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid"));
return true;
}
......@@ -325,7 +325,12 @@ function blogapi_blogger_get_recent_posts($appkey, $blogid, $username, $password
}
$type = _blogapi_blogid($blogid);
$result = db_query_range('SELECT n.nid, n.title,'. ($bodies ? ' n.body,' : '') ." n.created, u.name FROM {node} n, {users} u WHERE n.uid=u.uid AND n.type = '%s' AND n.uid = %d ORDER BY n.created DESC", $type, $user->uid, 0, $number_of_posts);
if ($bodies) {
$result = db_query_range("SELECT n.nid, n.title, r.body, n.created, u.name FROM {node} n, {node_revisions} r, {users} u WHERE n.uid = u.uid AND n.vid = r.vid AND n.type = '%s' AND n.uid = %d ORDER BY n.created DESC", $type, $user->uid, 0, $number_of_posts);
}
else {
$result = db_query_range("SELECT n.nid, n.title, n.created, u.name FROM {node} n, {users} u WHERE n.uid = u.uid AND n.type = '%s' AND n.uid = %d ORDER BY n.created DESC", $type, $user->uid, 0, $number_of_posts);
}
while ($blog = db_fetch_object($result)) {
$blogs[] = _blogapi_get_post($blog, $bodies);
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -793,7 +793,7 @@ function comment_render($node, $cid = 0) {
$output .= '<form method="post" action="'. url('comment') ."\"><div>\n";
$output .= form_hidden('nid', $nid);
$result = db_query('SELECT c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.picture, u.data, c.score, c.users FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = %d GROUP BY c.cid, c.pid, c.nid, c.subject, c.comment, c.timestamp, c.name, c.mail, u.picture, c.homepage, u.uid, u.name, u.picture, u.data, c.score, c.users', $cid, COMMENT_PUBLISHED);
$result = db_query('SELECT c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.picture, u.data, c.score, c.users FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = %d GROUP BY c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, u.picture, c.homepage, u.uid, u.name, u.picture, u.data, c.score, c.users', $cid, COMMENT_PUBLISHED);
if ($comment = db_fetch_object($result)) {
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
......
......@@ -793,7 +793,7 @@ function comment_render($node, $cid = 0) {
$output .= '<form method="post" action="'. url('comment') ."\"><div>\n";
$output .= form_hidden('nid', $nid);
$result = db_query('SELECT c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.picture, u.data, c.score, c.users FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = %d GROUP BY c.cid, c.pid, c.nid, c.subject, c.comment, c.timestamp, c.name, c.mail, u.picture, c.homepage, u.uid, u.name, u.picture, u.data, c.score, c.users', $cid, COMMENT_PUBLISHED);
$result = db_query('SELECT c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.picture, u.data, c.score, c.users FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = %d GROUP BY c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, u.picture, c.homepage, u.uid, u.name, u.picture, u.data, c.score, c.users', $cid, COMMENT_PUBLISHED);
if ($comment = db_fetch_object($result)) {
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
......
......@@ -335,7 +335,7 @@ function forum_admin_configure() {
* Implementation of hook_load().
*/
function forum_load($node) {
$forum = db_fetch_object(db_query('SELECT * FROM {forum} WHERE nid = %d', $node->nid));
$forum = db_fetch_object(db_query('SELECT * FROM {forum} WHERE vid = %d', $node->vid));
return $forum;
}
......@@ -546,7 +546,12 @@ function forum_validate(&$node) {
* Implementation of hook_update().
*/
function forum_update($node) {
db_query('UPDATE {forum} SET tid = %d WHERE nid = %d', $node->tid, $node->nid);
if ($node->is_new || $node->revision) {
db_query("INSERT INTO {forum} (nid, vid, tid) VALUES (%d, %d, %d)", $node->nid, $node->vid, $node->tid);
}
else {
db_query('UPDATE {forum} SET tid = %d WHERE vid = %d', $node->tid, $node->vid);
}
}
/**
......@@ -579,7 +584,7 @@ function forum_form(&$node) {
* Implementation of hook_insert().
*/
function forum_insert($node) {
db_query('INSERT INTO {forum} (nid, tid) VALUES (%d, %d)', $node->nid, $node->tid);
db_query('INSERT INTO {forum} (nid, vid, tid) VALUES (%d, %d, %d)', $node->nid, $node->vid, $node->tid);
}
/**
......@@ -704,7 +709,7 @@ function forum_get_topics($tid, $sortby, $forum_per_page) {
$term = taxonomy_get_term($tid);
$sql = db_rewrite_sql("SELECT n.nid, f.tid, n.title, n.sticky, u.name, u.uid, n.created AS timestamp, n.comment AS comment_mode, l.last_comment_timestamp, IF(l.last_comment_uid, cu.name, l.last_comment_name) AS last_comment_name, l.last_comment_uid, l.comment_count AS num_comments FROM {node} n, {node_comment_statistics} l, {users} cu, {term_node} r, {users} u, {forum} f WHERE n.status = 1 AND l.last_comment_uid = cu.uid AND n.nid = l.nid AND n.nid = r.nid AND r.tid = %d AND n.uid = u.uid AND n.nid = f.nid");
$sql = db_rewrite_sql("SELECT n.nid, f.tid, n.title, n.sticky, u.name, u.uid, n.created AS timestamp, n.comment AS comment_mode, l.last_comment_timestamp, IF(l.last_comment_uid, cu.name, l.last_comment_name) AS last_comment_name, l.last_comment_uid, l.comment_count AS num_comments FROM {node} n, {node_comment_statistics} l, {users} cu, {term_node} r, {users} u, {forum} f WHERE n.status = 1 AND l.last_comment_uid = cu.uid AND n.nid = l.nid AND n.nid = r.nid AND r.tid = %d AND n.uid = u.uid AND n.vid = f.vid");
$sql .= tablesort_sql($forum_topic_list_header, 'n.sticky DESC,');
$sql_count = db_rewrite_sql("SELECT COUNT(n.nid) FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid AND r.tid = %d WHERE n.status = 1 AND n.type = 'forum'");
......
......@@ -335,7 +335,7 @@ function forum_admin_configure() {
* Implementation of hook_load().
*/
function forum_load($node) {
$forum = db_fetch_object(db_query('SELECT * FROM {forum} WHERE nid = %d', $node->nid));
$forum = db_fetch_object(db_query('SELECT * FROM {forum} WHERE vid = %d', $node->vid));
return $forum;
}
......@@ -546,7 +546,12 @@ function forum_validate(&$node) {
* Implementation of hook_update().
*/
function forum_update($node) {
db_query('UPDATE {forum} SET tid = %d WHERE nid = %d', $node->tid, $node->nid);
if ($node->is_new || $node->revision) {
db_query("INSERT INTO {forum} (nid, vid, tid) VALUES (%d, %d, %d)", $node->nid, $node->vid, $node->tid);
}
else {
db_query('UPDATE {forum} SET tid = %d WHERE vid = %d', $node->tid, $node->vid);
}
}
/**
......@@ -579,7 +584,7 @@ function forum_form(&$node) {
* Implementation of hook_insert().
*/
function forum_insert($node) {
db_query('INSERT INTO {forum} (nid, tid) VALUES (%d, %d)', $node->nid, $node->tid);
db_query('INSERT INTO {forum} (nid, vid, tid) VALUES (%d, %d, %d)', $node->nid, $node->vid, $node->tid);
}
/**
......@@ -704,7 +709,7 @@ function forum_get_topics($tid, $sortby, $forum_per_page) {
$term = taxonomy_get_term($tid);
$sql = db_rewrite_sql("SELECT n.nid, f.tid, n.title, n.sticky, u.name, u.uid, n.created AS timestamp, n.comment AS comment_mode, l.last_comment_timestamp, IF(l.last_comment_uid, cu.name, l.last_comment_name) AS last_comment_name, l.last_comment_uid, l.comment_count AS num_comments FROM {node} n, {node_comment_statistics} l, {users} cu, {term_node} r, {users} u, {forum} f WHERE n.status = 1 AND l.last_comment_uid = cu.uid AND n.nid = l.nid AND n.nid = r.nid AND r.tid = %d AND n.uid = u.uid AND n.nid = f.nid");
$sql = db_rewrite_sql("SELECT n.nid, f.tid, n.title, n.sticky, u.name, u.uid, n.created AS timestamp, n.comment AS comment_mode, l.last_comment_timestamp, IF(l.last_comment_uid, cu.name, l.last_comment_name) AS last_comment_name, l.last_comment_uid, l.comment_count AS num_comments FROM {node} n, {node_comment_statistics} l, {users} cu, {term_node} r, {users} u, {forum} f WHERE n.status = 1 AND l.last_comment_uid = cu.uid AND n.nid = l.nid AND n.nid = r.nid AND r.tid = %d AND n.uid = u.uid AND n.vid = f.vid");
$sql .= tablesort_sql($forum_topic_list_header, 'n.sticky DESC,');
$sql_count = db_rewrite_sql("SELECT COUNT(n.nid) FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid AND r.tid = %d WHERE n.status = 1 AND n.type = 'forum'");
......
This diff is collapsed.
This diff is collapsed.
......@@ -74,6 +74,8 @@ function page_form(&$node) {
$output .= form_textarea(t('Body'), 'body', $node->body, 60, 20, '', NULL, TRUE);
$output .= filter_form('format', $node->format);
$output .= form_textarea(t('Log message'), 'log', $node->log, 60, 5, t('An explanation of the additions or updates being made to help other authors understand your motivations.'));
return $output;
}
......
......@@ -74,6 +74,8 @@ function page_form(&$node) {
$output .= form_textarea(t('Body'), 'body', $node->body, 60, 20, '', NULL, TRUE);
$output .= filter_form('format', $node->format);
$output .= form_textarea(t('Log message'), 'log', $node->log, 60, 5, t('An explanation of the additions or updates being made to help other authors understand your motivations.'));
return $output;
}
......
......@@ -314,7 +314,7 @@ function upload_nodeapi(&$node, $op, $arg) {
* The ammount of disk space used by the user in bytes.
*/
function upload_space_used($uid) {
return db_result(db_query('SELECT SUM(f.filesize) FROM {files} f INNER JOIN {node} n ON f.nid = n.nid WHERE uid = %d', $uid));
return db_result(db_query('SELECT SUM(f.filesize) FROM {files} f INNER JOIN {node_revisions} n ON f.vid = n.vid WHERE uid = %d', $uid));
}
/**
......@@ -324,7 +324,7 @@ function upload_space_used($uid) {
* The ammount of disk space used by uploaded files in bytes.
*/
function upload_total_space_used() {
return db_result(db_query('SELECT SUM(f.filesize) FROM {files} f INNER JOIN {node} n ON f.nid = n.nid'));
return db_result(db_query('SELECT SUM(f.filesize) FROM {files} f INNER JOIN {node_revisions} n ON f.vid = n.vid'));
}
function upload_save($node) {
......@@ -336,18 +336,33 @@ function upload_save($node) {
// Insert new files:
if ($file = file_save_upload($file, $file->filename)) {
$fid = db_next_id('{files}_fid');
db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize, list) VALUES (%d, %d, '%s', '%s', '%s', %d, %d)",
$fid, $node->nid, $file->filename, $file->filepath, $file->filemime, $file->filesize, $node->list[$key]);
db_query("INSERT INTO {files} (fid, nid, vid, filename, filepath, filemime, filesize, list) VALUES (%d, %d, %d, '%s', '%s', '%s', %d, %d)",
$fid, $node->nid, $node->vid, $file->filename, $file->filepath, $file->filemime, $file->filesize, $node->list[$key]);
}
}
else {
// Remove or update existing files:
if ($node->remove[$key]) {
}
// Remove or update existing files:
foreach ((array)$node->remove as $key => $value) {
if ($node->remove[$key]) {
db_query('DELETE FROM {files} WHERE fid = %d AND vid = %d', $key, $node->vid);
// We only delete a file if it isn't used anymore by any revision.
$count = db_result(db_query('SELECT COUNT(fid) FROM {files} WHERE fid = %d', $key));
if (!($count > 0)) {
file_delete($file->filepath);
db_query("DELETE FROM {files} WHERE fid = %d", $key);
}
if ($file->list != $node->list[$key]) {
db_query("UPDATE {files} SET list = %d WHERE fid = %d", $node->list[$key], $key);
}
}
foreach ((array)$node->list as $key => $value) {
if (!$node->remove[$key]) {
db_query('UPDATE {files} SET list = %d WHERE fid = %d AND vid = %d', $node->list[$key], $key, $node->vid);
}
}
if ($node->old_vid) {
foreach ((array)$node->remove as $key => $remove) {
if (!$remove) {
$file = db_fetch_object(db_query('SELECT * FROM {files} WHERE vid = %d AND fid = %d', $node->old_vid, $key));
db_query("INSERT INTO {files} (fid, nid, vid, filename, filepath, filemime, filesize, list) VALUES (%d, %d, %d, '%s', '%s', '%s', %d, %d)",
$key, $node->nid, $node->vid, $file->filename, $file->filepath, $file->filemime, $file->filesize, $file->list);
}
}
}
......@@ -392,8 +407,8 @@ function upload_form($node) {
function upload_load($node) {
$files = array();
if ($node->nid) {
$result = db_query("SELECT * FROM {files} WHERE nid = %d", $node->nid);
if ($node->vid) {
$result = db_query("SELECT * FROM {files} WHERE vid = %d", $node->vid);
while ($file = db_fetch_object($result)) {
$files[$file->fid] = $file;
}
......
......@@ -314,7 +314,7 @@ function upload_nodeapi(&$node, $op, $arg) {
* The ammount of disk space used by the user in bytes.
*/
function upload_space_used($uid) {
return db_result(db_query('SELECT SUM(f.filesize) FROM {files} f INNER JOIN {node} n ON f.nid = n.nid WHERE uid = %d', $uid));
return db_result(db_query('SELECT SUM(f.filesize) FROM {files} f INNER JOIN {node_revisions} n ON f.vid = n.vid WHERE uid = %d', $uid));
}
/**
......@@ -324,7 +324,7 @@ function upload_space_used($uid) {
* The ammount of disk space used by uploaded files in bytes.
*/
function upload_total_space_used() {
return db_result(db_query('SELECT SUM(f.filesize) FROM {files} f INNER JOIN {node} n ON f.nid = n.nid'));
return db_result(db_query('SELECT SUM(f.filesize) FROM {files} f INNER JOIN {node_revisions} n ON f.vid = n.vid'));
}
function upload_save($node) {
......@@ -336,18 +336,33 @@ function upload_save($node) {
// Insert new files:
if ($file = file_save_upload($file, $file->filename)) {
$fid = db_next_id('{files}_fid');
db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize, list) VALUES (%d, %d, '%s', '%s', '%s', %d, %d)",
$fid, $node->nid, $file->filename, $file->filepath, $file->filemime, $file->filesize, $node->list[$key]);
db_query("INSERT INTO {files} (fid, nid, vid, filename, filepath, filemime, filesize, list) VALUES (%d, %d, %d, '%s', '%s', '%s', %d, %d)",
$fid, $node->nid, $node->vid, $file->filename, $file->filepath, $file->filemime, $file->filesize, $node->list[$key]);
}
}
else {
// Remove or update existing files:
if ($node->remove[$key]) {
}
// Remove or update existing files:
foreach ((array)$node->remove as $key => $value) {
if ($node->remove[$key]) {
db_query('DELETE FROM {files} WHERE fid = %d AND vid = %d', $key, $node->vid);
// We only delete a file if it isn't used anymore by any revision.
$count = db_result(db_query('SELECT COUNT(fid) FROM {files} WHERE fid = %d', $key));
if (!($count > 0)) {
file_delete($file->filepath);
db_query("DELETE FROM {files} WHERE fid = %d", $key);
}
if ($file->list != $node->list[$key]) {
db_query("UPDATE {files} SET list = %d WHERE fid = %d", $node->list[$key], $key);
}
}
foreach ((array)$node->list as $key => $value) {
if (!$node->remove[$key]) {
db_query('UPDATE {files} SET list = %d WHERE fid = %d AND vid = %d', $node->list[$key], $key, $node->vid);
}
}
if ($node->old_vid) {
foreach ((array)$node->remove as $key => $remove) {
if (!$remove) {
$file = db_fetch_object(db_query('SELECT * FROM {files} WHERE vid = %d AND fid = %d', $node->old_vid, $key));
db_query("INSERT INTO {files} (fid, nid, vid, filename, filepath, filemime, filesize, list) VALUES (%d, %d, %d, '%s', '%s', '%s', %d, %d)",
$key, $node->nid, $node->vid, $file->filename, $file->filepath, $file->filemime, $file->filesize, $file->list);
}
}
}
......@@ -392,8 +407,8 @@ function upload_form($node) {
function upload_load($node) {
$files = array();
if ($node->nid) {
$result = db_query("SELECT * FROM {files} WHERE nid = %d", $node->nid);
if ($node->vid) {
$result = db_query("SELECT * FROM {files} WHERE vid = %d", $node->vid);
while ($file = db_fetch_object($result)) {
$files[$file->fid] = $file;
}
......
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