Index: database/database.mysql
===================================================================
RCS file: /cvs/drupal/drupal/database/database.mysql,v
retrieving revision 1.163
diff -u -F^f -r1.163 database.mysql
--- database/database.mysql 7 Dec 2004 16:55:38 -0000 1.163
+++ database/database.mysql 14 Dec 2004 22:25:32 -0000
@@ -392,8 +392,8 @@
CREATE TABLE node (
nid int(10) unsigned NOT NULL auto_increment,
+ vid int(10) unsigned NOT NULL default '1',
type varchar(16) NOT NULL default '',
- title varchar(128) NOT NULL default '',
uid int(10) NOT NULL default '0',
status int(4) NOT NULL default '1',
created int(11) NOT NULL default '0',
@@ -401,16 +401,12 @@
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),
@@ -430,6 +426,23 @@
grant_update tinyint(1) unsigned NOT NULL default '0',
grant_delete tinyint(1) unsigned NOT NULL default '0',
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,
+ teaser longtext NOT NULL,
+ timestamp int(11) NOT NULL default '0',
+ format int(4) NOT NULL default '0',
+ PRIMARY KEY (nid,vid),
+ KEY uid (uid)
) TYPE=MyISAM;
--
Index: database/database.pgsql
===================================================================
RCS file: /cvs/drupal/drupal/database/database.pgsql,v
retrieving revision 1.99
diff -u -F^f -r1.99 database.pgsql
--- database/database.pgsql 12 Dec 2004 08:38:23 -0000 1.99
+++ database/database.pgsql 14 Dec 2004 22:25:32 -0000
@@ -66,7 +66,6 @@
nid integer NOT NULL default '0',
parent integer NOT NULL default '0',
weight smallint NOT NULL default '0',
- format smallint default '0',
log text default '',
PRIMARY KEY (nid)
);
@@ -394,23 +393,18 @@
CREATE TABLE node (
nid SERIAL,
type varchar(16) NOT NULL default '',
- title varchar(128) NOT NULL default '',
uid integer NOT NULL default '0',
status integer NOT NULL default '1',
created integer NOT NULL default '0',
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 '',
changed integer NOT NULL default '0',
- 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);
-CREATE INDEX node_title_idx ON node(title,type);
CREATE INDEX node_status_idx ON node(status);
CREATE INDEX node_uid_idx ON node(uid);
CREATE INDEX node_moderate_idx ON node (moderate);
@@ -432,6 +426,23 @@
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 '',
+ format smallint NOT NULL default '0',
+ timestamp integer NOT NULL default '0',
+ PRIMARY KEY (nid,vid)
+);
+
+CREATE INDEX node_revisions_uid_idx ON node_revisions(uid);
--
-- Table structure for table 'node_counter'
@@ -455,7 +466,6 @@
CREATE TABLE page (
nid integer NOT NULL default '0',
link varchar(128) NOT NULL default '',
- format smallint NOT NULL default '0',
description varchar(128) NOT NULL default '',
PRIMARY KEY (nid)
);
Index: database/updates.inc
===================================================================
RCS file: /cvs/drupal/drupal/database/updates.inc,v
retrieving revision 1.78
diff -u -F^f -r1.78 updates.inc
--- database/updates.inc 7 Dec 2004 16:55:38 -0000 1.78
+++ database/updates.inc 14 Dec 2004 22:25:32 -0000
@@ -90,7 +90,8 @@
"2004-11-07" => "update_111",
"2004-11-15" => "update_112",
"2004-11-28" => "update_113",
- "2004-12-05" => "update_114"
+ "2004-12-05" => "update_114",
+ "2004-12-13" => "update_115"
);
function update_32() {
@@ -2064,6 +2065,78 @@ function update_114() {
$ret[] = update_sql("ALTER TABLE {node} DROP users");
return $ret;
+}
+
+function update_115() {
+ $ret = array();
+ $revs = array();
+
+ $result = db_query("SELECT title, body, teaser, changed, format, nid, revisions FROM {node}");
+ while ($row = db_fetch_array($result)) {
+ if (strlen($row['revisions']) > 0) {
+ $revs[$row['nid']] = unserialize($row['revisions']);
+ }
+ else {
+ $revs[$row['nid']] = array();
+ $revision=array();
+ $revision['node']->title = $row['title'];
+ $revision['node']->uid = $row['uid'];
+ $revision['node']->body = $row['body'];
+ $revision['node']->teaser = $row['teaser'];
+ $revision['node']->changed = $row['changed'];
+ $revision['node']->format = $row['format'];
+ $revs[$row['nid']][] = $revision;
+ }
+ }
+
+ if ($GLOBALS['db_type'] == 'mysql') {
+ $ret[] = update_sql("ALTER TABLE {node} DROP INDEX node_title_type");
+ $ret[] = update_sql("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,
+ teaser longtext NOT NULL,
+ timestamp int(11) NOT NULL default '0',
+ format int(4) NOT NULL default '0',
+ PRIMARY KEY (nid,vid),
+ KEY uid (uid)
+ )");
+ $ret[] = update_sql("ALTER TABLE {node} ADD vid int(10) unsigned NOT NULL default '1'");
+ }
+ else {
+ $ret[] = update_sql("ALTER TABLE {node} DROP INDEX node_title_idx");
+ $ret[] = update_sql("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 '',
+ timestamp integer NOT NULL default '0',
+ format smallint NOT NULL default '0',
+ PRIMARY KEY (nid,vid)
+ )");
+ $ret[] = update_sql("ALTER TABLE {node} ADD vid integer NOT NULL default '1'");
+ $ret[] = update_sql("CREATE INDEX node_revisions_uid_idx ON node_revisions(uid)");
+ }
+
+ foreach ($revs as $nid => $revisions) {
+ $vid = 0;
+ foreach ($revisions as $revision) {
+ db_query("INSERT INTO {node_revisions} (nid, vid, uid, title, body, teaser, timestamp, format) VALUES (%d, %d, %d, '%s', '%s', '%s', %d, %d)", $nid, ++$vid, $revision['node']->uid, $revision['node']->title, $revision['node']->body, $revision['node']->teaser, $revision['node']->changed, $revision['node']->format);
+ }
+ db_query("UPDATE {node} SET vid = %d WHERE nid = %d", $vid, $nid);
+ }
+ $ret[] = update_sql("ALTER TABLE {node} DROP revisions");
+ $ret[] = update_sql("ALTER TABLE {node} DROP title");
+ $ret[] = update_sql("ALTER TABLE {node} DROP teaser");
+ $ret[] = update_sql("ALTER TABLE {node} DROP body");
+ $ret[] = update_sql("ALTER TABLE {node} DROP format");
+
+ return $ret;
+
}
function update_sql($sql) {
Index: includes/database.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database.inc,v
retrieving revision 1.33
diff -u -F^f -r1.33 database.inc
--- includes/database.inc 29 Nov 2004 13:10:43 -0000 1.33
+++ includes/database.inc 14 Dec 2004 22:25:32 -0000
@@ -175,4 +175,4 @@ function db_queryd($query) {
// Initialize the default database.
db_set_active();
-?>
\ No newline at end of file
+?>
Index: includes/database.mysql.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database.mysql.inc,v
retrieving revision 1.27
diff -u -F^f -r1.27 database.mysql.inc
--- includes/database.mysql.inc 29 Nov 2004 13:10:43 -0000 1.27
+++ includes/database.mysql.inc 14 Dec 2004 22:25:32 -0000
@@ -236,6 +236,49 @@ function db_escape_string($text) {
}
/**
+ * Begins a transaction/lock
+ *
+ * Use this when you need to update multiple tables in such a way that
+ * either all of the updates go through or none do at all. This is
+ * especially useful for the improved revisions system.
+ *
+ * In order to accomodate older versions of MySQL that don't support
+ * table types that have transactions, rollback is not used, and we
+ * must specify which tables are going to be
+ *
+ * So, your code will look something like this:
+ * db_begin_transaction(array('table1', 'table2'));
+ * // Check if conditions are okay for this update
+ * if ($conditions_ok) {
+ * // run queries
+ * }
+ * db_commit_transaction();
+ *
+ * You code should ALWAYS call both db_begin_transaction() and
+ * db_commit_transaction() and ALWAYS call them in the same order
+ *
+ * @param $tables array of tables to lock
+ * @return a DB_Result object or a DB_Error
+ */
+function db_begin_transaction($tables) {
+ foreach ($tables as $num => $table) {
+ $tables[$num]= $table .' WRITE';
+ }
+ return db_query('LOCK TABLES '. implode(', ', $tables));
+}
+
+/**
+ * Commits a transaction/lock
+ *
+ * See db_begin_transaction() for usage details
+ *
+ * @return a DB_Result object or a DB_Error
+ */
+function db_commit_transaction() {
+ return db_query('UNLOCK TABLES');
+}
+
+/**
* @} End of "ingroup database".
*/
Index: includes/database.pgsql.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database.pgsql.inc,v
retrieving revision 1.5
diff -u -F^f -r1.5 database.pgsql.inc
--- includes/database.pgsql.inc 29 Nov 2004 13:10:43 -0000 1.5
+++ includes/database.pgsql.inc 14 Dec 2004 22:25:32 -0000
@@ -231,6 +231,45 @@ function db_escape_string($text) {
}
/**
+ * Begins a transaction/lock
+ *
+ * Use this when you need to update multiple tables in such a way that
+ * either all of the updates go through or none do at all. This is
+ * especially useful for the improved revisions system.
+ *
+ * In order to accomodate older versions of MySQL that don't support
+ * table types that have transactions, rollback is not used, and we
+ * must specify which tables are going to be
+ *
+ * So, your code will look something like this:
+ * db_begin_transaction(array('table1', 'table2'));
+ * // Check if conditions are okay for this update
+ * if ($conditions_ok) {
+ * // run queries
+ * }
+ * db_commit_transaction();
+ *
+ * You code should ALWAYS call both db_begin_transaction() and
+ * db_commit_transaction() and ALWAYS call them in the same order
+ *
+ * @param $tables array of tables to lock
+ * @return a DB_Result object or a DB_Error
+ */
+function db_begin_transaction($tables) {
+ return db_query('START TRANSACTION');
+}
+
+/**
+ * Commits a transaction/lock
+ *
+ * See db_begin_transaction() for usage details
+ *
+ * @return a DB_Result object or a DB_Error
+ */
+function db_commit_transaction() {
+ return db_query('COMMIT');
+}
+/**
* @} End of "ingroup database".
*/
Index: modules/blog.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/blog.module,v
retrieving revision 1.207
diff -u -F^f -r1.207 blog.module
--- modules/blog.module 7 Dec 2004 16:55:38 -0000 1.207
+++ modules/blog.module 14 Dec 2004 22:25:32 -0000
@@ -102,7 +102,7 @@ function blog_feed_user($uid = 0) {
$account = $user;
}
- $result = db_query_range('SELECT n.nid, n.title, n.teaser, n.created, u.name, u.uid FROM {node} n '. node_access_join_sql() .' INNER JOIN {users} u ON n.uid = u.uid WHERE '. node_access_where_sql() ." AND n.type = 'blog' AND u.uid = %d AND n.status = 1 ORDER BY n.created DESC", $uid, 0, 15);
+ $result = db_query_range('SELECT n.nid, r.title, r.teaser, n.created, u.name, u.uid FROM {node} n '. node_access_join_sql() .' INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid INNER JOIN {users} u ON n.uid = u.uid WHERE '. node_access_where_sql() ." AND n.type = 'blog' AND u.uid = %d AND n.status = 1 ORDER BY n.created DESC", $uid, 0, 15);
$channel['title'] = $account->name ."'s blog";
$channel['link'] = url("blog/$uid", NULL, NULL, TRUE);
$channel['description'] = $term->description;
@@ -113,7 +113,7 @@ function blog_feed_user($uid = 0) {
* Displays an RSS feed containing recent blog entries of all users.
*/
function blog_feed_last() {
- $result = db_query_range('SELECT n.nid, n.title, n.teaser, n.created, u.name, u.uid FROM {node} n '. node_access_join_sql() .' INNER JOIN {users} u ON n.uid = u.uid WHERE '. node_access_where_sql() ." AND n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC", 0, 15);
+ $result = db_query_range('SELECT n.nid, r.title, r.teaser, n.created, u.name, u.uid FROM {node} n '. node_access_join_sql() .' INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid INNER JOIN {users} u ON n.uid = u.uid WHERE '. node_access_where_sql() ." AND n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC", 0, 15);
$channel['title'] = variable_get('site_name', 'drupal') .' blogs';
$channel['link'] = url('blog', NULL, NULL, TRUE);
$channel['description'] = $term->description;
@@ -304,7 +304,7 @@ function blog_block($op = 'list', $delta
}
else if ($op == 'view') {
if (user_access('access content')) {
- $block['content'] = node_title_list(db_query_range('SELECT DISTINCT(n.nid), n.title, n.created FROM {node} n '. node_access_join_sql() ." WHERE n.type = 'blog' AND n.status = 1 AND ". node_access_where_sql() .' ORDER BY n.created DESC', 0, 10));
+ $block['content'] = node_title_list(db_query_range('SELECT DISTINCT(n.nid), r.title, n.created FROM {node} n '. node_access_join_sql() ." INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid WHERE n.type = 'blog' AND n.status = 1 AND ". node_access_where_sql() .' ORDER BY n.created DESC', 0, 10));
$block['content'] .= '
'. l(t('more'), 'blog', array('title' => t('Read the latest blog entries.'))) .'
';
$block['subject'] = t('Recent blog posts');
}
Index: modules/blogapi.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/blogapi.module,v
retrieving revision 1.34
diff -u -F^f -r1.34 blogapi.module
--- modules/blogapi.module 23 Nov 2004 22:20:41 -0000 1.34
+++ modules/blogapi.module 14 Dec 2004 22:25:32 -0000
@@ -361,7 +361,7 @@ function blogapi_get_recent_posts($req_p
return blogapi_error($user);
}
- $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 = 'blog' AND n.uid = %d ORDER BY n.created DESC", $user->uid, 0, $params[3]);
+ $result = db_query_range('SELECT n.nid, r.title,'. ($bodies ? ' r.body,' : '') ." n.created, u.name FROM {node} n, {users} u INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid WHERE n.uid=u.uid AND n.type = 'blog' AND n.uid = %d ORDER BY n.created DESC", $user->uid, 0, $params[3]);
while ($blog = db_fetch_object($result)) {
$xmlrpcval = _blogapi_get_post($blog, $bodies);
$blogs[] = $xmlrpcval;
Index: modules/book.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/book.module,v
retrieving revision 1.273
diff -u -F^f -r1.273 book.module
--- modules/book.module 11 Dec 2004 14:13:24 -0000 1.273
+++ modules/book.module 14 Dec 2004 22:25:32 -0000
@@ -115,7 +115,7 @@ function book_menu($may_cache) {
// We don't want to cache these menu items because they could change whenever
// a book page or outline node is edited.
if (arg(0) == 'admin' && arg(1) == 'node' && arg(2) == 'book') {
- $result = db_query('SELECT n.nid, n.title FROM {node} n '. node_access_join_sql() .' INNER JOIN {book} b ON n.nid = b.nid WHERE '. node_access_where_sql() .' AND b.parent = 0 ORDER BY b.weight, n.title');
+ $result = db_query('SELECT n.nid, r.title FROM {node} n '. node_access_join_sql() .' INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid INNER JOIN {book} b ON n.nid = b.nid WHERE '. node_access_where_sql() .' AND b.parent = 0 ORDER BY b.weight, r.title');
while ($book = db_fetch_object($result)) {
$items[] = array('path' => 'admin/node/book/'. $book->nid, 'title' => t('"%title" book', array('%title' => $book->title)));
}
@@ -140,7 +140,7 @@ function book_block($op = 'list', $delta
else if ($op == 'view') {
// Only display this block when the user is browsing a book:
if (arg(0) == 'node' && is_numeric(arg(1))) {
- $result = db_query('SELECT n.nid, n.title, b.parent FROM {node} n '. node_access_join_sql() .' INNER JOIN {book} b ON n.nid = b.nid WHERE '. node_access_where_sql() .' AND n.nid = %d', arg(1));
+ $result = db_query('SELECT n.nid, r.title, b.parent FROM {node} n '. node_access_join_sql() .' INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid INNER JOIN {book} b ON n.nid = b.nid WHERE '. node_access_where_sql() .' AND n.nid = %d', arg(1));
if (db_num_rows($result) > 0) {
$node = db_fetch_object($result);
@@ -328,7 +328,7 @@ function book_revision_load($page, $cond
* Return the path (call stack) to a certain book page.
*/
function book_location($node, $nodes = array()) {
- $parent = db_fetch_object(db_query('SELECT n.nid, n.title, b.parent, b.weight FROM {node} n '. node_access_join_sql() .' INNER JOIN {book} b ON n.nid = b.nid WHERE '. node_access_where_sql() .' AND n.nid = %d', $node->parent));
+ $parent = db_fetch_object(db_query('SELECT n.nid, r.title, b.parent, b.weight FROM {node} n '. node_access_join_sql() .' INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid INNER JOIN {book} b ON n.nid = b.nid WHERE '. node_access_where_sql() .' AND n.nid = %d', $node->parent));
if ($parent->title) {
$nodes = book_location($parent, $nodes);
array_push($nodes, $parent);
@@ -337,7 +337,7 @@ function book_location($node, $nodes = a
}
function book_location_down($node, $nodes = array()) {
- $last_direct_child = db_fetch_object(db_query('SELECT n.nid, n.title, b.parent, b.weight FROM {node} n '. node_access_join_sql() .' INNER JOIN {book} b ON n.nid = b.nid WHERE '. node_access_where_sql() .' AND b.parent = %d ORDER BY b.weight DESC, n.title DESC', $node->nid));
+ $last_direct_child = db_fetch_object(db_query('SELECT n.nid, r.title, b.parent, b.weight FROM {node} n '. node_access_join_sql() .' INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid INNER JOIN {book} b ON n.nid = b.nid WHERE '. node_access_where_sql() .' AND b.parent = %d ORDER BY b.weight DESC, r.title DESC', $node->nid));
if ($last_direct_child) {
array_push($nodes, $last_direct_child);
$nodes = book_location_down($last_direct_child, $nodes);
@@ -355,7 +355,7 @@ function book_prev($node) {
}
// Previous on the same level:
- $direct_above = db_fetch_object(db_query('SELECT n.nid, n.title FROM {node} n '. node_access_join_sql() .' INNER JOIN {book} b ON n.nid = b.nid WHERE '. node_access_where_sql() ." AND b.parent = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '') AND (b.weight < %d OR (b.weight = %d AND n.title < '%s')) ORDER BY b.weight DESC, n.title DESC", $node->parent, $node->weight, $node->weight, $node->title));
+ $direct_above = db_fetch_object(db_query('SELECT n.nid, r.title FROM {node} n '. node_access_join_sql() .' INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid INNER JOIN {book} b ON n.nid = b.nid WHERE '. node_access_where_sql() ." AND b.parent = %d AND n.status = 1 AND (n.moderate = 0 OR n.vid != 1) AND (b.weight < %d OR (b.weight = %d AND r.title < '%s')) ORDER BY b.weight DESC, r.title DESC", $node->parent, $node->weight, $node->weight, $node->title));
if ($direct_above) {
// Get last leaf of $above.
$path = book_location_down($direct_above);
@@ -364,7 +364,7 @@ function book_prev($node) {
}
else {
// Direct parent:
- $prev = db_fetch_object(db_query('SELECT n.nid, n.title FROM {node} n '. node_access_join_sql() .' INNER JOIN {book} b ON n.nid = b.nid WHERE '. node_access_where_sql() ." AND n.nid = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '')", $node->parent));
+ $prev = db_fetch_object(db_query('SELECT n.nid, r.title FROM {node} n '. node_access_join_sql() .' INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid INNER JOIN {book} b ON n.nid = b.nid WHERE '. node_access_where_sql() ." AND n.nid = %d AND n.status = 1 AND (n.moderate = 0 OR n.vid != 1)", $node->parent));
return $prev;
}
}
@@ -374,7 +374,7 @@ function book_prev($node) {
*/
function book_next($node) {
// get first direct child
- $child = db_fetch_object(db_query("SELECT DISTINCT(n.nid), n.title, b.weight FROM {node} n ". node_access_join_sql() ." INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND ". node_access_where_sql() ." AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight ASC, n.title ASC", $node->nid));
+ $child = db_fetch_object(db_query("SELECT DISTINCT(n.nid), r.title, b.weight FROM {node} n ". node_access_join_sql() ." INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND ". node_access_where_sql() ." AND (n.moderate = 0 OR n.vid != 1) ORDER BY b.weight ASC, r.title ASC", $node->nid));
if ($child) {
return $child;
}
@@ -383,7 +383,7 @@ function book_next($node) {
array_push($path = book_location($node), $node); // Path to top-level node including this one.
while (($leaf = array_pop($path)) && count($path)) {
- $next = db_fetch_object(db_query("SELECT DISTINCT(n.nid), n.title, b.weight FROM {node} n ". node_access_join_sql() ." INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND ". node_access_where_sql() ." AND (n.moderate = 0 OR n.revisions != '') AND (b.weight > %d OR (b.weight = %d AND n.title > '%s')) ORDER BY b.weight ASC, n.title ASC", $leaf->parent, $leaf->weight, $leaf->weight, $leaf->title));
+ $next = db_fetch_object(db_query("SELECT DISTINCT(n.nid), r.title, b.weight FROM {node} n ". node_access_join_sql() ." INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND ". node_access_where_sql() ." AND (n.moderate = 0 OR n.vid != 1) AND (b.weight > %d OR (b.weight = %d AND r.title > '%s')) ORDER BY b.weight ASC, r.title ASC", $leaf->parent, $leaf->weight, $leaf->weight, $leaf->title));
if ($next) {
return $next;
}
@@ -521,7 +521,7 @@ function book_toc_recurse($nid, $indent,
}
function book_toc($exclude = 0) {
- $result = db_query('SELECT DISTINCT(n.nid), n.title, b.parent, b.weight FROM {node} n '. node_access_join_sql() .' INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND '. node_access_where_sql() .' ORDER BY b.weight, n.title');
+ $result = db_query('SELECT DISTINCT(n.nid), r.title, b.parent, b.weight FROM {node} n '. node_access_join_sql() .' INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND '. node_access_where_sql() .' ORDER BY b.weight, r.title');
while ($node = db_fetch_object($result)) {
if (!$children[$node->parent]) {
@@ -574,7 +574,7 @@ function book_tree_recurse($nid, $depth,
}
function book_tree($parent = 0, $depth = 3, $unfold = array()) {
- $result = db_query('SELECT DISTINCT(n.nid), n.title, b.parent, b.weight FROM {node} n '. node_access_join_sql() .' INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND '. node_access_where_sql() .' AND n.moderate = 0 ORDER BY b.weight, n.title');
+ $result = db_query('SELECT DISTINCT(n.nid), r.title, b.parent, b.weight FROM {node} n '. node_access_join_sql() .' INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND '. node_access_where_sql() .' AND n.moderate = 0 ORDER BY b.weight, r.title');
while ($node = db_fetch_object($result)) {
$list = $children[$node->parent] ? $children[$node->parent] : array();
@@ -591,7 +591,7 @@ function book_tree($parent = 0, $depth =
* Menu callback; prints a listing of all books.
*/
function book_render() {
- $result = db_query('SELECT n.nid FROM {node} n '. node_access_join_sql() .' INNER JOIN {book} b ON n.nid = b.nid WHERE '. node_access_where_sql() .' AND b.parent = 0 AND n.status = 1 AND (n.moderate = 0 OR n.revisions IS NOT NULL) ORDER BY b.weight, n.title');
+ $result = db_query('SELECT n.nid FROM {node} n '. node_access_join_sql() .' INNER JOIN {book} b ON n.nid = b.nid INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid WHERE '. node_access_where_sql() .' AND b.parent = 0 AND n.status = 1 AND (n.moderate = 0 OR n.vid != 1) ORDER BY b.weight, r.title');
while ($page = db_fetch_object($result)) {
// Load the node:
@@ -617,7 +617,7 @@ function book_render() {
*/
function book_print($nid = 0, $depth = 1) {
global $base_url;
- $result = db_query('SELECT DISTINCT(n.nid), n.title, b.weight FROM {node} n '. node_access_join_sql() .' INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND '. node_access_where_sql() .' AND n.nid = %d AND (n.moderate = 0 OR n.revisions IS NOT NULL) ORDER BY b.weight, n.title', $nid);
+ $result = db_query('SELECT DISTINCT(n.nid), r.title, b.weight FROM {node} n '. node_access_join_sql() .' INNER JOIN {book} b ON n.nid = b.nid INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid WHERE n.status = 1 AND '. node_access_where_sql() .' AND n.nid = %d AND (n.moderate = 0 OR n.vid != 1) ORDER BY b.weight, r.title', $nid);
while ($page = db_fetch_object($result)) {
// load the node:
@@ -647,7 +647,7 @@ function book_print($nid = 0, $depth = 1
}
function book_print_recurse($parent = '', $depth = 1) {
- $result = db_query("SELECT DISTINCT(n.nid), n.title, b.weight FROM {node} n ". node_access_join_sql() ." INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND ". node_access_where_sql() ." AND b.parent = '$parent' AND (n.moderate = 0 OR n.revisions IS NOT NULL) ORDER BY b.weight, n.title");
+ $result = db_query("SELECT DISTINCT(n.nid), r.title, b.weight FROM {node} n ". node_access_join_sql() ." INNER JOIN {book} b ON n.nid = b.nid INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid WHERE n.status = 1 AND ". node_access_where_sql() ." AND b.parent = '$parent' AND (n.moderate = 0 OR n.vid != 1) ORDER BY b.weight, r.title");
while ($page = db_fetch_object($result)) {
// Load the node:
@@ -681,7 +681,7 @@ function book_admin_view_line($node, $de
}
function book_admin_view_book($nid, $depth = 1) {
- $result = db_query('SELECT n.nid FROM {node} n '. node_access_join_sql() .' INNER JOIN {book} b ON n.nid = b.nid WHERE '. node_access_where_sql() .' AND b.parent = %d ORDER BY b.weight, n.title', $nid);
+ $result = db_query('SELECT n.nid FROM {node} n '. node_access_join_sql() .' INNER JOIN {book} b ON n.nid = b.nid INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid WHERE '. node_access_where_sql() .' AND b.parent = %d ORDER BY b.weight, r.title', $nid);
while ($node = db_fetch_object($result)) {
$node = node_load(array('nid' => $node->nid));
@@ -720,7 +720,7 @@ function book_admin_save($nid, $edit = a
// Check to see whether the title needs updating:
$title = db_result(db_query('SELECT title FROM {node} WHERE nid = %d', $nid));
if ($title != $value['title']) {
- db_query("UPDATE {node} SET title = '%s' WHERE nid = %d", $value['title'], $nid);
+ db_query("UPDATE {node_revisions} SET title = '%s' WHERE nid = %d", $value['title'], $nid);
}
// Check to see whether the weight needs updating:
@@ -741,7 +741,7 @@ function book_admin_save($nid, $edit = a
* Menu callback; displays a listing of all orphaned book pages.
*/
function book_admin_orphan() {
- $result = db_query('SELECT n.nid, n.title, n.status, b.parent FROM {node} n '. node_access_join_sql() .' INNER JOIN {book} b ON n.nid = b.nid WHERE '. node_access_where_sql());
+ $result = db_query('SELECT n.nid, r.title, n.status, b.parent FROM {node} n '. node_access_join_sql() .' INNER JOIN {book} b ON n.nid = b.nid INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid WHERE '. node_access_where_sql());
while ($page = db_fetch_object($result)) {
$pages[$page->nid] = $page;
Index: modules/forum.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/forum.module,v
retrieving revision 1.217
diff -u -F^f -r1.217 forum.module
--- modules/forum.module 24 Nov 2004 22:56:21 -0000 1.217
+++ modules/forum.module 14 Dec 2004 22:25:32 -0000
@@ -135,9 +135,9 @@ function forum_block($op = 'list', $delt
case 'view':
if (user_access('access content')) {
- $content = node_title_list(db_query_range("SELECT DISTINCT(n.nid), n.title, l.last_comment_timestamp, l.comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid ". node_access_join_sql() ." WHERE n.status = 1 AND n.type='forum' AND ". node_access_where_sql() ." ORDER BY l.last_comment_timestamp DESC", 0, variable_get('forum_block_num', '5')), t('Active forum topics:'));
+ $content = node_title_list(db_query_range("SELECT DISTINCT(n.nid), r.title, l.last_comment_timestamp, l.comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid ". node_access_join_sql() ." INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid WHERE n.status = 1 AND n.type='forum' AND ". node_access_where_sql() ." ORDER BY l.last_comment_timestamp DESC", 0, variable_get('forum_block_num', '5')), t('Active forum topics:'));
- $content .= node_title_list(db_query_range("SELECT DISTINCT(n.nid), n.title, l.comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid ". node_access_join_sql() ." WHERE n.type = 'forum' AND n.status = 1 AND ". node_access_where_sql() ." ORDER BY n.nid DESC", 0, variable_get('forum_block_num', '5')), t('New forum topics:'));
+ $content .= node_title_list(db_query_range("SELECT DISTINCT(n.nid), r.title, l.comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid ". node_access_join_sql() ." INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid WHERE n.type = 'forum' AND n.status = 1 AND ". node_access_where_sql() ." ORDER BY n.nid DESC", 0, variable_get('forum_block_num', '5')), t('New forum topics:'));
if ($content) {
$content .= ''. l(t('more'), 'forum', array('title' => t('Read the latest forum topics.'))) .'
';
@@ -162,7 +162,7 @@ function forum_link($type, $node = 0, $m
if (!$main && $type == 'node' && $node->type == 'forum') {
// get previous and next topic
- $result = db_query("SELECT DISTINCT(n.nid), n.title, n.sticky, l.comment_count, l.last_comment_timestamp FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid " . node_access_join_sql() . " INNER JOIN {term_node} r ON n.nid = r.nid AND r.tid = %d WHERE n.status = 1 AND n.type='forum' AND " . node_access_where_sql() . ' ORDER BY n.sticky DESC, '. _forum_get_topic_order_sql(variable_get('forum_order', 1)), $node->tid);
+ $result = db_query("SELECT DISTINCT(n.nid), rv.title, n.sticky, l.comment_count, l.last_comment_timestamp FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid ". node_access_join_sql() ." INNER JOIN {node_revisions} rv ON rv.nid = n.nid AND rv.vid = n.vid INNER JOIN {term_node} r ON n.nid = r.nid AND r.tid = %d WHERE n.status = 1 AND n.type='forum' AND " . node_access_where_sql() . ' ORDER BY n.sticky DESC, '. _forum_get_topic_order_sql(variable_get('forum_order', 1)), $node->tid);
while ($topic = db_fetch_object($result)) {
if ($stop == 1) {
@@ -404,7 +404,7 @@ function forum_get_topics($tid, $sortby,
$forum_topic_list_header = array(
array('data' => ' '),
- array('data' => t('Topic'), 'field' => 'n.title'),
+ array('data' => t('Topic'), 'field' => 'r.title'),
array('data' => t('Replies'), 'field' => 'l.comment_count'),
array('data' => t('Created'), 'field' => 'n.created'),
array('data' => t('Last reply'), 'field' => 'l.last_comment_timestamp'),
@@ -420,7 +420,7 @@ function forum_get_topics($tid, $sortby,
$term = taxonomy_get_term($tid);
$check_tid = $tid ? "'". db_escape_string($tid) ."'" : 'NULL';
- $sql = "SELECT DISTINCT(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_access_join_sql() .", {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 = $check_tid AND n.uid = u.uid AND n.nid = f.nid AND ". node_access_where_sql();
+ $sql = "SELECT DISTINCT(n.nid), f.tid, rv.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_access_join_sql() .", {node_comment_statistics} l, {users} cu, {term_node} r, {users} u, {forum} f INNER JOIN {node_revisions} rv ON r.nid = n.nid AND r.vid = n.vid WHERE n.status = 1 AND l.last_comment_uid = cu.uid AND n.nid = l.nid AND n.nid = r.nid AND r.tid = $check_tid AND n.uid = u.uid AND n.nid = f.nid AND ". node_access_where_sql();
$sql .= tablesort_sql($forum_topic_list_header, 'n.sticky DESC,');
$sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM {node} n ". node_access_join_sql() ." INNER JOIN {term_node} r ON n.nid = r.nid AND r.tid = $check_tid WHERE n.status = 1 AND n.type = 'forum' AND ". node_access_where_sql();
Index: modules/node.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/node.module,v
retrieving revision 1.430
diff -u -F^f -r1.430 node.module
--- modules/node.module 11 Dec 2004 14:13:24 -0000 1.430
+++ modules/node.module 14 Dec 2004 22:25:33 -0000
@@ -383,13 +383,13 @@ function node_load($conditions, $revisio
}
// Retrieve the node.
- $node = db_fetch_object(db_query('SELECT n.*, u.uid, u.name, u.picture, u.data FROM {node} n INNER JOIN {users} u ON u.uid = n.uid WHERE '. implode(' AND ', $cond)));
- $node = drupal_unpack($node);
-
- // Unserialize the revisions and user data fields.
- if ($node->revisions) {
- $node->revisions = unserialize($node->revisions);
+ if (-1 < $revision) {
+ $node = db_fetch_object(db_query('SELECT n.*, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.format, u.uid, u.name, u.picture, u.data FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = %d WHERE '. implode(' AND ', $cond),array($revision)));
+ }
+ else {
+ $node = db_fetch_object(db_query('SELECT n.*, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.format, u.uid, u.name, u.picture, u.data FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid WHERE '. implode(' AND ', $cond)));
}
+ $node = drupal_unpack($node);
// Call the node specific callback (if any) and piggy-back the
// results to the node or overwrite some values.
@@ -421,65 +421,80 @@ function node_load($conditions, $revisio
* Save a node object into the database.
*/
function node_save($node) {
+ global $user;
+
// Fetch fields to save to node table:
$fields = node_invoke_nodeapi($node, 'fields');
-
- // Serialize the revisions field:
- if ($node->revisions) {
- $node->revisions = serialize($node->revisions);
- }
+ $newnode = false;
// Apply filters to some default node fields:
if (empty($node->nid)) {
// Insert a new node.
+ $newnode = true;
// Set some required fields:
if (!$node->created) {
$node->created = time();
}
- if (!$node->changed) {
- $node->changed = time();
- }
$node->nid = db_next_id('{node}_nid');
+ $node->vid = 1;
+ }
- // Prepare the query:
- foreach ($node as $key => $value) {
- if (in_array($key, $fields)) {
- $k[] = db_escape_string($key);
- $v[] = $value;
- $s[] = "'%s'";
- }
- }
+ if (!$node->changed) {
+ $node->changed = time();
+ }
- $keysfmt = implode(', ', $s);
- // We need to quote the placeholders for the values.
- $valsfmt = "'". implode("', '", $s) ."'";
+ //Split off revisions data to another structure
+ $revisions = array('nid' => $node->nid, 'vid' => $node->vid,
+ 'title' => $node->title, 'body' => $node->body,
+ 'teaser' => $node->teaser, 'changed' => $node->changed,
+ 'uid' => $user->uid, 'format' => $node->format);
- // Insert the node into the database:
- db_query("INSERT INTO {node} (". implode(", ", $k) .") VALUES(". implode(", ", $s) .")", $v);
+ unset($node->title);
+ unset($node->body);
+ unset($node->teaser);
+ unset($node->format);
- // Call the node specific callback (if any):
- node_invoke($node, 'insert');
- node_invoke_nodeapi($node, 'insert');
+ // Prepare the query:
+ foreach ($node as $key => $value) {
+ if (in_array($key, $fields)) {
+ $k[] = db_escape_string($key);
+ $v[] = $value;
+ $s[] = "'%s'";
+ }
}
- else {
- // Update an existing node.
- // Set some required fields:
- $node->changed = time();
+ //Generate the node table query
+ $nodequery = "REPLACE INTO {node} (". implode(", ", $k) .") VALUES(". implode(", ", $s) .")";
- // Prepare the query:
- foreach ($node as $key => $value) {
- if (in_array($key, $fields)) {
- $q[] = db_escape_string($key) ." = '%s'";
- $v[] = $value;
- }
+ foreach ($revisions as $key => $value) {
+ if (in_array($key, $fields)) {
+ $rk[] = check_query($key);
+ $rv[] = $value;
+ $rs[] = "'%s'";
}
+ }
+
+ //Generate the node_revisions table query
+ $revquery = "REPLACE INTO {node_revisions} (". implode(", ", $rk) .") VALUES(". implode(", ", $rs) .")";
+
+ // Insert the node into the database:
+ db_begin_transaction(array('node', 'node_revisions', 'watchdog', 'sessions'));
+ db_query($nodequery, $v);
+ db_query($revquery, $rv);
+ db_commit_transaction();
- // Update the node in the database:
- db_query("UPDATE {node} SET ". implode(', ', $q) ." WHERE nid = '$node->nid'", $v);
+ //Restore the node structure to it's previous state
+ $node->title = $revisions['title'];
+ $node->body = $revisions['body'];
+ $node->teaser = $revisions['teaser'];
- // Call the node specific callback (if any):
+ // Call the node specific callback (if any):
+ if ($newnode) {
+ node_invoke($node, 'insert');
+ node_invoke_nodeapi($node, 'insert');
+ }
+ else {
node_invoke($node, 'update');
node_invoke_nodeapi($node, 'update');
}
@@ -695,7 +710,7 @@ function node_menu($may_cache) {
'weight' => 1,
'type' => MENU_LOCAL_TASK);
- if ($node->revisions) {
+ if ($node->vid > 1) {
$items[] = array('path' => 'node/'. arg(1) .'/revisions', 'title' => t('revisions'),
'callback' => 'node_page',
'access' => user_access('administer nodes'),
@@ -767,7 +782,7 @@ function node_admin_nodes() {
$output .= "$form
";
// Render operations form:
- $result = pager_query('SELECT n.*, u.name, u.uid FROM {node} n INNER JOIN {users} u ON n.uid = u.uid '. $filters[$filter][1], 50);
+ $result = pager_query('SELECT n.*, r.title, r.body, r.teaser, r.format, r.timestamp, u.name, u.uid FROM {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid INNER JOIN {users} u ON n.uid = u.uid '. $filters[$filter][1], 50);
// Make sure the update controls are disabled if we don't have any rows to select from.
$disabled = !db_num_rows($result);
@@ -854,11 +869,14 @@ function node_revision_overview($nid) {
drupal_set_title($node->title);
- if ($node->revisions) {
+ if ($node->vid > 1) {
$header = array(t('Older revisions'), array('colspan' => '3', 'data' => t('Operations')));
- foreach ($node->revisions as $key => $revision) {
- $rows[] = array(t('revision #%r revised by %u on %d', array('%r' => $key, '%u' => format_name(user_load(array('uid' => $revision['uid']))), '%d' => format_date($revision['timestamp'], 'small'))) . ($revision['history'] ? '
'. $revision['history'] .'' : ''), l(t('view'), "node/$node->nid", array(), "revision=$key"), l(t('rollback'), "node/$node->nid/rollback-revision/$key"), l(t('delete'), "node/$node->nid/delete-revision/$key"));
+ $revision_list = node_revision_list($node);
+
+ foreach ($revision_list as $key) {
+ $revision = node_load(array('nid' => $node->nid), $key);
+ $rows[] = array(t('revision #%r revised by %u on %d', array('%r' => $key, '%u' => format_name(user_load(array('uid' => $revision->uid))), '%d' => format_date($revision->revision_timestamp, 'small'))) . ($revision->title ? '
'. $revision->title .'' : ''), l(t('view'), "node/$node->nid", array(), "revision=$key"), l(t('rollback'), "node/$node->nid/rollback-revision/$key"), l(t('delete'), "node/$node->nid/delete-revision/$key"));
}
$output .= theme('table', $header, $rows);
}
@@ -872,22 +890,21 @@ function node_revision_overview($nid) {
* Return the revision with the specified revision number.
*/
function node_revision_load($node, $revision) {
- return $node->revisions[$revision]['node'];
+ return node_load(array('nid' => $node->nid), $revision);
}
/**
* Create and return a new revision of the given node.
*/
function node_revision_create($node) {
- global $user;
-
- // "Revision" is the name of the field used to indicate that we have to
- // create a new revision of a node.
- if ($node->nid && $node->revision) {
- $prev = node_load(array('nid' => $node->nid));
- $node->revisions = $prev->revisions;
- unset($prev->revisions);
- $node->revisions[] = array('uid' => $user->uid, 'timestamp' => time(), 'node' => $prev, 'history' => $node->history);
+ if ($node->nid) {
+ $newnode = node_load(array('nid' => $node->nid));
+ if ($node->revision) {
+ $node->vid = ++$newnode->vid;
+ }
+ else {
+ $node->vid = $newnode->vid;
+ }
}
return $node;
@@ -900,26 +917,13 @@ function node_revision_rollback($nid, $r
global $user;
if (user_access('administer nodes')) {
- $node = node_load(array('nid' => $nid));
- // Extract the specified revision:
- $rev = $node->revisions[$revision]['node'];
+ $orignode = node_load(array('nid' => $nid));
+ $node = node_load(array('nid' => $nid), $revision);
- // Inherit all the past revisions:
- $rev->revisions = $node->revisions;
+ $node->vid = ++$orignode->vid;
- // Save the original/current node:
- $rev->revisions[] = array('uid' => $user->uid, 'timestamp' => time(), 'node' => $node);
-
- // Remove the specified revision:
- unset($rev->revisions[$revision]);
-
- // Save the node:
- foreach ($node as $key => $value) {
- $filter[] = $key;
- }
-
- node_save($rev, $filter);
+ node_save($node);
drupal_set_message(t('Rolled back to revision %revision of %title', array('%revision' => "#$revision", '%title' => "$node->title")));
drupal_goto('node/'. $nid .'/revisions');
@@ -931,11 +935,19 @@ function node_revision_rollback($nid, $r
*/
function node_revision_delete($nid, $revision) {
if (user_access('administer nodes')) {
+ //Start a transaction so that the current node and node count
+ //don't change between the time we load it from the database and
+ //delete the node
+ db_begin_transaction(array('node', 'node_revisions', 'watchdog', 'sessions'));
$node = node_load(array('nid' => $nid));
-
- unset($node->revisions[$revision]);
-
- node_save($node, array('nid', 'revisions'));
+ $revlist = node_revisionsision_list($node);
+
+ //Don't delete the last revision of the node or the current revision
+ if ((count($revlist) > 0) && ($revision != $node->vid)) {
+ db_query("DELETE FROM {node_revisions} WHERE nid = %d AND vid = %d", array($nid, $revision));
+ }
+
+ db_commit_transaction();
drupal_set_message(t('Deleted revision %revision of %title', array('%revision' => "#$revision", '%title' => "$node->title")));
drupal_goto('node/'. $nid . (count($node->revisions) ? '/revisions' : ''));
@@ -946,12 +958,12 @@ function node_revision_delete($nid, $rev
* Return a list of all the existing revision numbers.
*/
function node_revision_list($node) {
- if (is_array($node->revisions)) {
- return array_keys($node->revisions);
- }
- else {
- return array();
+ $revs = array();
+ $result = db_query('SELECT vid FROM {node_revisions} r WHERE nid = %d AND vid != %d ORDER BY vid ASC', $node->nid, $node->vid);
+ while ($row = db_fetch_array($result)) {
+ $revs[] = $row['vid'];
}
+ return $revs;
}
/**
@@ -972,7 +984,12 @@ function node_admin() {
$output = search_form(url('admin/node/search'), $_POST['edit']['keys'], 'node') . search_data($_POST['edit']['keys'], 'node');
break;
case 'delete':
- $output = node_delete(array('nid' => arg(3)));
+ if (is_array($edit)) {
+ $output = node_delete($edit);
+ }
+ else {
+ $output = node_delete(array("nid"=>arg(3)));
+ }
break;
case t('Delete'):
$output = node_delete($edit);
@@ -1116,7 +1133,6 @@ function node_validate($node) {
$node->promote = variable_get("node_promote_$node->type", 1);
$node->moderate = variable_get("node_moderate_$node->type", 0);
$node->sticky = variable_get("node_sticky_$node->type", 0);
- $node->revision = variable_get("node_revision_$node->type", 0);
unset($node->created);
}
@@ -1425,8 +1441,12 @@ function node_delete($edit) {
if (node_access('delete', $node)) {
if ($edit['confirm']) {
- // Delete the specified node:
+ // Delete the specified node:
+ // We don't need to lock this in a transaction because once the
+ // entry in node disappears, the entry in node_revisions won't be
+ // accessable
db_query('DELETE FROM {node} WHERE nid = %d', $node->nid);
+ db_query('DELETE FROM {node_revisions} WHERE nid = %d', $node->nid);
// Call the node-specific callback (if any):
node_invoke($node, 'delete');
@@ -1445,7 +1465,7 @@ function node_delete($edit) {
$output .= form_item(t('Confirm deletion'), $node->title);
$output .= form_hidden('nid', $node->nid);
$output .= form_hidden('confirm', 1);
- $output .= form_submit(t('Delete'));
+ $output .= form_submit(t('Delete'), 'delete');
$output = form($output);
}
}
@@ -1594,7 +1614,7 @@ function node_nodeapi(&$node, $op, $arg
$output[t('revision')] = form_checkbox('', "node_revision_$node->type", 1, variable_get("node_revision_$node->type", 0));
return $output;
case 'fields':
- return array('nid', 'uid', 'type', 'title', 'teaser', 'body', 'revisions', 'status', 'promote', 'moderate', 'sticky', 'created', 'changed', 'format');
+ return array('nid', 'uid', 'type', 'title', 'teaser', 'body', 'vid', 'status', 'promote', 'moderate', 'sticky', 'created', 'changed', 'format');
}
}
Index: modules/poll.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/poll.module,v
retrieving revision 1.151
diff -u -F^f -r1.151 poll.module
--- modules/poll.module 24 Nov 2004 22:56:21 -0000 1.151
+++ modules/poll.module 14 Dec 2004 22:25:33 -0000
@@ -264,7 +264,7 @@ function poll_node_name($node) {
function poll_page() {
// List all polls
- $result = pager_query("SELECT DISTINCT(n.nid), n.title, p.active, n.created, SUM(c.chvotes) AS votes FROM {node} n ". node_access_join_sql() ." INNER JOIN {poll} p ON n.nid=p.nid INNER JOIN {poll_choices} c ON n.nid=c.nid WHERE type = 'poll' AND status = 1 AND ". node_access_where_sql() ." AND moderate = 0 GROUP BY n.nid, n.title, p.active, n.created ORDER BY n.created DESC", 15);
+ $result = pager_query("SELECT DISTINCT(n.nid), r.title, p.active, n.created, SUM(c.chvotes) AS votes FROM {node} n ". node_access_join_sql() ." INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid INNER JOIN {poll} p ON n.nid=p.nid INNER JOIN {poll_choices} c ON n.nid=c.nid WHERE type = 'poll' AND status = 1 AND ". node_access_where_sql() ." AND moderate = 0 GROUP BY n.nid, r.title, p.active, n.created ORDER BY n.created DESC", 15);
$output = '';
while ($node = db_fetch_object($result)) {
$output .= '- '. l($node->title, "node/$node->nid") .' - '. format_plural($node->votes, '1 vote', '%count votes') .' - '. ($node->active ? t('open') : t('closed')) .'
';
Index: modules/queue.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/queue.module,v
retrieving revision 1.120
diff -u -F^f -r1.120 queue.module
--- modules/queue.module 7 Dec 2004 16:55:38 -0000 1.120
+++ modules/queue.module 14 Dec 2004 22:25:33 -0000
@@ -82,7 +82,7 @@ function queue_vote($node, $vote) {
drupal_set_message(t('The post is promoted.'));
}
else if (variable_get('queue_threshold_dump', -2) >= $node->score) {
- if ($node->revisions) {
+ if ($node->vid > 1) {
node_revision_rollback($node, end(node_revision_list($node)));
watchdog('special', t('Moderation: declined %title (rollback).', array('%title' => "$node->title")));
drupal_set_message(t('The post has been declined and the previous version has been restored.'));
@@ -96,7 +96,7 @@ function queue_vote($node, $vote) {
}
}
else if (variable_get('queue_threshold_expire', 8) <= $node->votes) {
- if ($node->revisions) {
+ if ($node->vid > 1) {
node_revision_rollback($node, end(node_revision_list($node)));
watchdog('special', t('Moderation: expired %title (rollback).', array('%title' => "$node->title")));
drupal_set_message(t('The post has expired and the previous version has been restored.'));
Index: modules/statistics.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/statistics.module,v
retrieving revision 1.179
diff -u -F^f -r1.179 statistics.module
--- modules/statistics.module 29 Nov 2004 09:31:28 -0000 1.179
+++ modules/statistics.module 14 Dec 2004 22:25:33 -0000
@@ -379,11 +379,11 @@ function statistics_cron() {
* number of rows to be returned.
*
* @return
- * A query result containing n.nid, n.title, u.uid, u.name of the selected node(s)
+ * A query result containing n.nid, r.title, u.uid, u.name of the selected node(s)
* or FALSE if the query could not be executed correctly.
*/
function statistics_title_list($dbfield, $dbrows) {
- return db_query_range("SELECT s.nid, n.title, u.uid, u.name FROM {node_counter} s INNER JOIN {node} n ON s.nid = n.nid INNER JOIN {users} u ON n.uid = u.uid WHERE %s <> '0' AND n.status = 1 ORDER BY %s DESC", 's.'. $dbfield, 's.'. $dbfield, 0, $dbrows);
+ return db_query_range("SELECT s.nid, r.title, u.uid, u.name FROM {node_counter} s INNER JOIN {node} n ON s.nid = n.nid INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid INNER JOIN {users} u ON n.uid = u.uid WHERE %s <> '0' AND n.status = 1 ORDER BY %s DESC", 's.'. $dbfield, 's.'. $dbfield, 0, $dbrows);
}
/**
Index: modules/taxonomy.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy.module,v
retrieving revision 1.160
diff -u -F^f -r1.160 taxonomy.module
--- modules/taxonomy.module 29 Nov 2004 12:52:44 -0000 1.160
+++ modules/taxonomy.module 14 Dec 2004 22:25:33 -0000
@@ -438,7 +438,7 @@ function taxonomy_node_form($type, $node
function taxonomy_node_has_term($nid, $tid) {
$term_name = db_result(db_query('SELECT name FROM {term_data} WHERE tid = %d', $tid));
- return db_result(db_query("SELECT COUNT(n.nid) FROM {node} n WHERE n.nid = %d AND ((n.title LIKE '%%%s%%') OR (n.body LIKE '%%%s%%'))", $nid, $term_name, $term_name));
+ return db_result(db_query("SELECT COUNT(n.nid) FROM {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid WHERE n.nid = %d AND ((r.title LIKE '%%%s%%') OR (r.body LIKE '%%%s%%'))", $nid, $term_name, $term_name));
}
/**
Index: modules/tracker.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/tracker.module,v
retrieving revision 1.103
diff -u -F^f -r1.103 tracker.module
--- modules/tracker.module 23 Nov 2004 22:20:41 -0000 1.103
+++ modules/tracker.module 14 Dec 2004 22:25:33 -0000
@@ -69,10 +69,10 @@ function tracker_page($uid = 0) {
$output .= '';
if ($uid) {
- $result = pager_query('SELECT DISTINCT n.nid, n.title, n.type, n.changed, n.uid, u.name, l.last_comment_timestamp AS last_post, l.comment_count FROM {node} n '. node_access_join_sql() .' INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid AND c.status = 0 WHERE n.status = 1 AND '. node_access_where_sql() .' AND (n.uid = %d OR c.uid = %d) ORDER BY last_post DESC', 25, 0, 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n '. node_access_join_sql() .' LEFT JOIN {comments} c ON n.nid = c.nid AND c.status = 0 WHERE n.status = 1 AND '. node_access_where_sql() .' AND (n.uid = %d OR c.uid = %d)', $uid, $uid);
+ $result = pager_query('SELECT DISTINCT(n.nid), r.title, n.type, n.changed, n.uid, u.name, l.last_comment_timestamp AS last_post, l.comment_count FROM {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid '. node_access_join_sql() .' INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid AND c.status = 0 WHERE n.status = 1 AND '. node_access_where_sql() .' AND (n.uid = %d OR c.uid = %d) ORDER BY last_post DESC', 25, 0, 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n '. node_access_join_sql() .' LEFT JOIN {comments} c ON n.nid = c.nid AND c.status = 0 WHERE n.status = 1 AND '. node_access_where_sql() .' AND (n.uid = %d OR c.uid = %d)', $uid, $uid);
}
else {
- $result = pager_query('SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, l.last_comment_timestamp AS last_post, l.comment_count FROM {node} n '. node_access_join_sql() .' INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.status = 1 AND '. node_access_where_sql() .' ORDER BY last_post DESC', 25, 0, 'SELECT COUNT(n.nid) FROM {node} n '. node_access_join_sql() .' WHERE n.status = 1 AND '. node_access_where_sql());
+ $result = pager_query('SELECT DISTINCT(n.nid), r.title, n.type, n.changed, n.uid, u.name, l.last_comment_timestamp AS last_post, l.comment_count FROM {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid '. node_access_join_sql() .' INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.status = 1 AND '. node_access_where_sql() .' ORDER BY last_post DESC', 25, 0, 'SELECT COUNT(n.nid) FROM {node} n '. node_access_join_sql() .' WHERE n.status = 1 AND '. node_access_where_sql());
}
while ($node = db_fetch_object($result)) {