You are here

public function NodeRevisionGenerate::getAvailableNodesForRevisions in Node Revision Delete 8

Get the available nodes to generate revisions.

Returns the ids of the available nodes to generate the revisions and the next date (Unix timestamp) of the revision to be generated for that node.

Parameters

array $bundles: An array with the selected content types to generate node revisions.

int $revisions_age: Interval in Unix timestamp format to add to the last revision date of the node.

Return value

array Returns the available nodes ids to generate the revisions and its next revision date.

Overrides NodeRevisionGenerateInterface::getAvailableNodesForRevisions

File

modules/node_revision_generate/src/NodeRevisionGenerate.php, line 57

Class

NodeRevisionGenerate
Class NodeRevisionGenerate.

Namespace

Drupal\node_revision_generate

Code

public function getAvailableNodesForRevisions(array $bundles, $revisions_age) {

  // Variable with the placeholders arguments needed for the expression.
  $interval_time = [
    ':interval' => $revisions_age,
    ':current_time' => $this->time
      ->getRequestTime(),
  ];
  $query = $this->connection
    ->select('node_field_data', 'node');

  // Get/check the last revision (vid).
  $query
    ->leftJoin('node_revision', 'revision', 'node.vid = revision.vid');

  // Get the node id to generate revisions.
  $query
    ->addField('node', 'nid');

  // Get the node id to generate revisions.
  $query
    ->addField('revision', 'revision_timestamp');

  // Get nodes with title to avoid some error on save it.
  $query
    ->isNotNull('node.title');

  // Get nodes of selected content types (bundles).
  $query
    ->condition('node.type', $bundles, 'IN');

  // Get only the published nodes.
  $query
    ->condition('node.status', 1);

  // Check the next date to generate the revision be <= current date.
  $query
    ->where('revision.revision_timestamp + :interval <= :current_time', $interval_time);

  // Return the available nodes ids and its next revision date, as array.
  return $query
    ->execute()
    ->fetchAll();
}