function _node_revision_delete_do_delete in Node Revision Delete 7.3
Same name and namespace in other branches
- 7.2 node_revision_delete.module \_node_revision_delete_do_delete()
Private function to perform revision deletion.
Parameters
int $nid: The node whose oldest revisions will be deleted.
int $minimum_revisions_to_keep: Max amount of revisions to keep for this node.
bool $dry_run: TRUE to test run without deleting revisions but seeing the output results, FALSE for a real node revision delete.
Return value
object stdClass with list containing an array of deleted revisions and pending containing a boolean where TRUE means that there are more revisions to delete for this node.
2 calls to _node_revision_delete_do_delete()
- node_revision_delete_batch_process in ./
node_revision_delete.batch.inc - Process for one batch step, deleting a revision.
- node_revision_delete_cron in ./
node_revision_delete.module - Implements hook_cron().
File
- ./
node_revision_delete.helpers.inc, line 291 - Helper functions.
Code
function _node_revision_delete_do_delete($nid, $minimum_revisions_to_keep, $dry_run = FALSE) {
// Getting the number of revisions to remove in each cron run.
$max = variable_get('node_revision_delete_cron', 50);
// Get the minimum age for the nid.
$minimum_age_time = _node_revision_delete_determine_time('minimum_age_to_delete', NULL, $nid);
$node = node_load($nid);
// Retrieve all revisions.
$revisions = node_revision_list($node);
if (module_exists('workbench_moderation')) {
// Remove current revision.
if (!workbench_moderation_node_is_current($node)) {
unset($revisions[$node->workbench_moderation['current']->vid]);
}
}
// Remove published revision.
if (array_key_exists($node->vid, $revisions)) {
unset($revisions[$node->vid]);
}
// POPO to keep track of deleted revisions and whether there are more
// to be deleted on a next run.
$deleted_revisions = new stdClass();
$deleted_revisions->count = 0;
$deleted_revisions->pending = FALSE;
// Keep recent revisions.
if (count($revisions) > $minimum_revisions_to_keep) {
$revisions = array_slice($revisions, $minimum_revisions_to_keep);
}
else {
return $deleted_revisions;
}
// Reverse the list so we start deleting oldest revisions first.
$revisions = array_reverse($revisions);
foreach ($revisions as $revision) {
$revision_id = $revision->vid;
// Skip revisions that are too new.
if ($revision->timestamp > $minimum_age_time) {
continue;
}
if ($dry_run ? $dry_run : node_revision_delete($revision_id)) {
$deleted_revisions->count++;
// Stop deleting if we hit the limit per cron run.
if ($deleted_revisions->count == $max) {
$deleted_revisions->pending = TRUE;
break;
}
}
}
return $deleted_revisions;
}