diff options
author | Dries Buytaert <dries@buytaert.net> | 2009-09-25 14:24:34 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2009-09-25 14:24:34 +0000 |
commit | d734f2f25d4866dc56c65766a8e196eac8a63047 (patch) | |
tree | 7dae4e3b2a1148f11b57b32908f5e5fdfff65c0d /modules/node/node.module | |
parent | 8b0b496a1c93b685c6e9dd25b6e4b008fb91cf51 (diff) | |
download | brdo-d734f2f25d4866dc56c65766a8e196eac8a63047.tar.gz brdo-d734f2f25d4866dc56c65766a8e196eac8a63047.tar.bz2 |
- Patch #581392 by sun, catch | mr.baileys: Fixed Add an API function for deleting revisions.
Diffstat (limited to 'modules/node/node.module')
-rw-r--r-- | modules/node/node.module | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/modules/node/node.module b/modules/node/node.module index 9a216d2b3..3c2d7610d 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -780,10 +780,11 @@ function node_load_multiple($nids = array(), $conditions = array(), $reset = FAL * @return * A fully-populated node object. */ -function node_load($nid, $vid = array(), $reset = FALSE) { - $vid = isset($vid) ? array('vid' => $vid) : NULL; - $node = node_load_multiple(array($nid), $vid, $reset); - return $node ? $node[$nid] : FALSE; +function node_load($nid = NULL, $vid = NULL, $reset = FALSE) { + $nids = (isset($nid) ? array($nid) : array()); + $conditions = (isset($vid) ? array('vid' => $vid) : array()); + $node = node_load_multiple($nids, $conditions, $reset); + return $node ? reset($node) : FALSE; } /** @@ -1011,6 +1012,31 @@ function node_delete_multiple($nids) { } /** + * Delete a node revision. + * + * @param $revision_id + * The revision ID to delete. + */ +function node_revision_delete($revision_id) { + if ($revision = node_load(NULL, $revision_id)) { + // Prevent deleting the current revision. + $node = node_load($revision->nid); + if ($revision_id == $node->vid) { + return FALSE; + } + + db_delete('node_revision') + ->condition('nid', $revision->nid) + ->condition('vid', $revision->vid) + ->execute(); + module_invoke_all('node_revision_delete', $revision); + field_attach_delete_revision('node', $revision); + return TRUE; + } + return FALSE; +} + +/** * Generate an array for rendering the given node. * * @param $node @@ -1484,13 +1510,12 @@ function node_user_cancel($edit, $account, $method) { ->condition('uid', $account->uid) ->execute() ->fetchCol(); - foreach ($nodes as $nid) { - node_delete($nid); - } + node_delete_multiple($nodes); // Delete old revisions. - db_delete('node_revision') - ->condition('uid', $account->uid) - ->execute(); + $revisions = db_query('SELECT vid FROM {node_revision} WHERE uid = :uid', array(':uid' => $account->uid))->fetchCol(); + foreach ($revisions as $revision) { + node_revision_delete($revision); + } // Clean history. db_delete('history') ->condition('uid', $account->uid) |