diff --git a/includes/comment.inc b/includes/comment.inc index 84d46ae..ed029b1 100644 --- a/includes/comment.inc +++ b/includes/comment.inc @@ -571,18 +571,66 @@ function project_issue_update_by_comment($comment_data, $op) { // Update the issue data to reflect the new final states. db_query("UPDATE {project_issues} SET pid = %d, category = '%s', component = '%s', priority = %d, rid = %d, assigned = %d, sid = %d, priority_weight = %d WHERE nid = %d", $comment_data->pid, $comment_data->category, $comment_data->component, $comment_data->priority, $comment_data->rid, $comment_data->assigned, $comment_data->sid, $priority_weight, $comment_data->nid); - // Update the issue title. - $node = node_load($comment_data->nid, NULL, TRUE); // Don't use cached since we changed data above. - $node->title = $comment_data->title; - - // This also updates the changed date of the issue. - node_save($node); + // Update the issue title, in case it changed. + // Don't use cached since we changed data above. + $node = node_load($comment_data->nid, NULL, TRUE); + if ($node->title !== $comment_data->title) { + // Node module's node_save() and _node_save_revision() would set the node + // revision author to the current user (the one who wrote an issue comment), + // change the node revision created/changed date as well as other node + // revision properties. + // However, for this node update, only the title of the issue node should be + // changed. All other properties of the existing node and node revision + // should remain unchanged, since the comment author did not edit the node, + // only wrote a comment. + // Therefore, we need to a custom implementation of node_save() that only + // updates the title, but still informs other modules about the change, and + // clears caches accordingly. + $node->title = $comment_data->title; + _project_issue_node_save($node); + + // Clear the static node_load() cache. + node_load(NULL, NULL, TRUE); + } // Return the object of comment data we used to update the issue. return $comment_data; } /** + * Save a node object into the database. + * + * This node_save() replacement only works for existing nodes and updates the + * node title in {node} and {node_revision} only. Other properties remain + * unchanged. + * + * @see project_issue_update_by_comment() + * @see node_save() + */ +function _project_issue_node_save(&$node) { + // Let modules modify the node before it is saved to the database. + node_invoke_nodeapi($node, 'presave'); + + // Update {node}.title. + db_query("UPDATE {node} SET title = '%s' WHERE nid = %d", array($node->nid)); + + // Update {node_revision}.title. + db_query("UPDATE {node_revisions} SET title = '%s' WHERE vid = %d", array($node->vid)); + + $op = 'update'; + + // Call the node specific callback (if any). + node_invoke($node, $op); + node_invoke_nodeapi($node, $op); + + // Update the node access table for this node. + node_access_acquire_grants($node); + + // Clear the page and block caches. + cache_clear_all(); +} + +/** * Adjusts the filepath of issue followups so files are saved to * the correct issues directory. *