You are here

public function NodeRevisionDelete::getCandidatesNodes in Node Revision Delete 8

Return the list of candidate nodes for node revision delete.

Parameters

string $content_type: Content type machine name.

Return value

array Array of nids.

Overrides NodeRevisionDeleteInterface::getCandidatesNodes

1 call to NodeRevisionDelete::getCandidatesNodes()
NodeRevisionDelete::getCandidatesRevisions in src/NodeRevisionDelete.php
Return the list of candidate revisions to be deleted.

File

src/NodeRevisionDelete.php, line 469

Class

NodeRevisionDelete
Class NodeRevisionDelete.

Namespace

Drupal\node_revision_delete

Code

public function getCandidatesNodes($content_type) {

  // @TODO check if the method can be improved.
  $result = [];

  // Getting the content type config.
  $content_type_config = $this
    ->getContentTypeConfigWithRelativeTime($content_type);
  if (!empty($content_type_config)) {
    $query = $this->connection
      ->select('node_field_data', 'n');
    $query
      ->join('node_revision', 'r', 'r.nid = n.nid');
    $query
      ->fields('n', [
      'nid',
    ]);
    $query
      ->addExpression('COUNT(*)', 'total');
    $query
      ->condition('type', $content_type);
    $query
      ->condition('revision_timestamp', $content_type_config['minimum_age_to_delete'], '<');
    $query
      ->condition('changed', $content_type_config['when_to_delete'], '<');
    $query
      ->groupBy('n.nid');
    $query
      ->having('COUNT(*) > ' . $content_type_config['minimum_revisions_to_keep']);

    // Allow other modules to alter candidates query.
    $query
      ->addTag('node_revision_delete_candidates');
    $query
      ->addTag('node_revision_delete_candidates_' . $content_type);
    $result = $query
      ->execute()
      ->fetchCol();
  }
  return $result;
}