function node_revision_delete_candidates in Node Revision Delete 7.2
Helper function to return the list of candidate nids.
Parameters
string $content_type: A content type machine name.
int $max_revisions: Match nodes with a total amount of revisions higher than this number.
Return value
array Array of nids.
3 calls to node_revision_delete_candidates()
- node_revision_delete_batch_process in ./
node_revision_delete.batch.inc - Callback to delete revisions using Batch API.
- node_revision_delete_cron in ./
node_revision_delete.module - Implements hook_cron().
- node_revision_delete_form in ./
node_revision_delete.admin.inc - Page callback: Form constructor for Node Revision Delete administration form.
File
- ./
node_revision_delete.module, line 244 - Node Revision Delete Module.
Code
function node_revision_delete_candidates($content_type, $max_revisions) {
$query = db_select('node', 'n');
$query
->join('node_revision', 'r', 'r.nid = n.nid');
$query
->condition('n.type', $content_type);
$query
->fields('n', [
'nid',
]);
$query
->addExpression('COUNT(*)', 'total');
$query
->groupBy('r.nid');
$query
->having('COUNT(*) > :max_revisions', [
':max_revisions' => $max_revisions,
]);
$query
->orderBy('total', 'DESC');
// Allow other modules to alter candidates query.
$query
->addTag('node_revision_delete_candidates');
$query
->addTag("node_revision_delete_candidates_{$content_type}");
return $query
->execute()
->fetchCol();
}