Commit 78c24e67 authored by Dries's avatar Dries
Browse files

- Bugfix: the book module incorrectly assumed that there is an active revision...

- Bugfix: the book module incorrectly assumed that there is an active revision if n.moderate = 0.  We can (and need) to rewrite this when the revision changes hit core.  In essence, we need an efficient query to retrieve the 'last puslished revision that is not in the moderation queue'.
parent 7307de5c
...@@ -356,7 +356,7 @@ function book_prev($node) { ...@@ -356,7 +356,7 @@ function book_prev($node) {
} }
// Previous on the same level: // 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, 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 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));
if ($direct_above) { if ($direct_above) {
// Get last leaf of $above. // Get last leaf of $above.
$path = book_location_down($direct_above); $path = book_location_down($direct_above);
...@@ -365,7 +365,7 @@ function book_prev($node) { ...@@ -365,7 +365,7 @@ function book_prev($node) {
} }
else { else {
// Direct parent: // 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, 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", $node->parent));
return $prev; return $prev;
} }
} }
...@@ -375,7 +375,7 @@ function book_prev($node) { ...@@ -375,7 +375,7 @@ function book_prev($node) {
*/ */
function book_next($node) { function book_next($node) {
// get first direct child // 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), 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 ORDER BY b.weight ASC, n.title ASC", $node->nid));
if ($child) { if ($child) {
return $child; return $child;
} }
...@@ -384,7 +384,7 @@ function book_next($node) { ...@@ -384,7 +384,7 @@ function book_next($node) {
array_push($path = book_location($node), $node); // Path to top-level node including this one. array_push($path = book_location($node), $node); // Path to top-level node including this one.
while (($leaf = array_pop($path)) && count($path)) { 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), 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 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));
if ($next) { if ($next) {
return $next; return $next;
} }
...@@ -592,7 +592,7 @@ function book_tree($parent = 0, $depth = 3, $unfold = array()) { ...@@ -592,7 +592,7 @@ function book_tree($parent = 0, $depth = 3, $unfold = array()) {
* Menu callback; prints a listing of all books. * Menu callback; prints a listing of all books.
*/ */
function book_render() { 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 WHERE '. node_access_where_sql() .' AND b.parent = 0 AND n.status = 1 AND n.moderate = 0 ORDER BY b.weight, n.title');
while ($page = db_fetch_object($result)) { while ($page = db_fetch_object($result)) {
// Load the node: // Load the node:
...@@ -618,7 +618,7 @@ function book_render() { ...@@ -618,7 +618,7 @@ function book_render() {
*/ */
function book_print($nid = 0, $depth = 1) { function book_print($nid = 0, $depth = 1) {
global $base_url; 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), 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 ORDER BY b.weight, n.title', $nid);
while ($page = db_fetch_object($result)) { while ($page = db_fetch_object($result)) {
// load the node: // load the node:
...@@ -648,7 +648,7 @@ function book_print($nid = 0, $depth = 1) { ...@@ -648,7 +648,7 @@ function book_print($nid = 0, $depth = 1) {
} }
function book_print_recurse($parent = '', $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), 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 ORDER BY b.weight, n.title");
while ($page = db_fetch_object($result)) { while ($page = db_fetch_object($result)) {
// Load the node: // Load the node:
......
...@@ -356,7 +356,7 @@ function book_prev($node) { ...@@ -356,7 +356,7 @@ function book_prev($node) {
} }
// Previous on the same level: // 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, 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 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));
if ($direct_above) { if ($direct_above) {
// Get last leaf of $above. // Get last leaf of $above.
$path = book_location_down($direct_above); $path = book_location_down($direct_above);
...@@ -365,7 +365,7 @@ function book_prev($node) { ...@@ -365,7 +365,7 @@ function book_prev($node) {
} }
else { else {
// Direct parent: // 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, 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", $node->parent));
return $prev; return $prev;
} }
} }
...@@ -375,7 +375,7 @@ function book_prev($node) { ...@@ -375,7 +375,7 @@ function book_prev($node) {
*/ */
function book_next($node) { function book_next($node) {
// get first direct child // 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), 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 ORDER BY b.weight ASC, n.title ASC", $node->nid));
if ($child) { if ($child) {
return $child; return $child;
} }
...@@ -384,7 +384,7 @@ function book_next($node) { ...@@ -384,7 +384,7 @@ function book_next($node) {
array_push($path = book_location($node), $node); // Path to top-level node including this one. array_push($path = book_location($node), $node); // Path to top-level node including this one.
while (($leaf = array_pop($path)) && count($path)) { 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), 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 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));
if ($next) { if ($next) {
return $next; return $next;
} }
...@@ -592,7 +592,7 @@ function book_tree($parent = 0, $depth = 3, $unfold = array()) { ...@@ -592,7 +592,7 @@ function book_tree($parent = 0, $depth = 3, $unfold = array()) {
* Menu callback; prints a listing of all books. * Menu callback; prints a listing of all books.
*/ */
function book_render() { 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 WHERE '. node_access_where_sql() .' AND b.parent = 0 AND n.status = 1 AND n.moderate = 0 ORDER BY b.weight, n.title');
while ($page = db_fetch_object($result)) { while ($page = db_fetch_object($result)) {
// Load the node: // Load the node:
...@@ -618,7 +618,7 @@ function book_render() { ...@@ -618,7 +618,7 @@ function book_render() {
*/ */
function book_print($nid = 0, $depth = 1) { function book_print($nid = 0, $depth = 1) {
global $base_url; 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), 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 ORDER BY b.weight, n.title', $nid);
while ($page = db_fetch_object($result)) { while ($page = db_fetch_object($result)) {
// load the node: // load the node:
...@@ -648,7 +648,7 @@ function book_print($nid = 0, $depth = 1) { ...@@ -648,7 +648,7 @@ function book_print($nid = 0, $depth = 1) {
} }
function book_print_recurse($parent = '', $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), 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 ORDER BY b.weight, n.title");
while ($page = db_fetch_object($result)) { while ($page = db_fetch_object($result)) {
// Load the node: // Load the node:
......
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