You are here

function _node_revision_delete_candidates in Node Revision Delete 7.3

Return the list of candidate nodes for node revision delete.

Parameters

string $content_type: Content type machine name.

int $minimum_revisions_to_keep: Minimum number of revisions to keep.

int $minimum_age_to_delete: Minimum age of revisions to be deleted.

int $when_to_delete: Minimum inactivity age to wait for delete a revision.

Return value

array Array of nids.

4 calls to _node_revision_delete_candidates()
drush_node_revision_delete in ./node_revision_delete.drush.inc
Implements drush_COMMANDFILE_COMMANDNAME().
node_revision_delete_admin_settings_form in ./node_revision_delete.admin.inc
Form constructor for Node Revision Delete administration form.
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 73
Helper functions.

Code

function _node_revision_delete_candidates($content_type, $minimum_revisions_to_keep, $minimum_age_to_delete, $when_to_delete) {

  // Get the time value for minimum age to delete.
  $minimum_age_time = _node_revision_delete_determine_time('minimum_age_to_delete', $content_type);

  // Get the time value for when to delete.
  $when_delete_time = _node_revision_delete_determine_time('when_to_delete', $content_type);

  // Get candidates based on node type, node age, and number of revisions to
  // keep. This determines which nodes have more than one revision based on the
  // variables. Also limit candidates by the minimum age variable.
  $result = db_query('SELECT nr.nid, nr.vid
    FROM {node_revision} nr
    INNER JOIN {node} n ON n.nid = nr.nid and n.vid <> nr.vid
    WHERE nr.timestamp < :minimum_age_time
        AND n.changed < :when_delete_time
        AND n.type = :content_type
    ORDER BY nid ASC', array(
    ':minimum_age_time' => $minimum_age_time,
    ':content_type' => $content_type,
    ':when_delete_time' => $when_delete_time,
  ));
  $candidates = array();
  foreach ($result as $row) {
    $candidates[] = (array) $row;
  }
  return $candidates;
}