function flatcomments_existing_one in Flatcomments 6.2
Same name and namespace in other branches
- 6 flatcomments_existing/flatcomments_existing.admin.inc \flatcomments_existing_one()
Flatten comments for single node. This is a batch operation.
1 string reference to 'flatcomments_existing_one'
- flatcomments_existing_form_submit_2 in flatcomments_existing/
flatcomments_existing.admin.inc - Form submit handler - second pass. Starts a batch of required operations.
File
- flatcomments_existing/
flatcomments_existing.admin.inc, line 113 - Administrative callbacks to provide the functionality of flattening previously existing comments.
Code
function flatcomments_existing_one($nid, &$context) {
// Collect all comment ID's for the given node (published or not), ordering
// by cid to get the comments in the order they were created (the same order
// as flat display uses).
$cids = db_query('SELECT cid FROM {comments} WHERE nid = %d ORDER BY cid', $nid);
// Iterate through the comments, and set each one to be start of a new thread,
// by clearing the parent ID, and setting the 'thread' vancode equal to the
// order in flat list (with no descendants). This is done as php loop rather than
// database query, to ensure the vancodes are consistent with comment module,
// and to avoid possible MySQL/PgSQL/whatever compatibility issues.
$order = 1;
while ($cid = db_fetch_array($cids)) {
$cid = $cid['cid'];
$thread = int2vancode($order++) . '/';
db_query("UPDATE {comments} SET pid = 0, thread = '%s' WHERE cid = %d", $thread, $cid);
}
}