You are here

private static function ViewAccessCheck::nodeRevisionIsValid in Node Accessibility 8

Checks to see if the node revision is a valid revision for the node.

Parameters

int $nid: The numeric node id.

int $vid: The numeric node revision id.

Return value

bool TRUE if valid, FALSE otherwise.

2 calls to ViewAccessCheck::nodeRevisionIsValid()
ViewAccessCheck::access in src/Access/ViewAccessCheck.php
A custom access check.
ViewAccessCheck::check_node_access in src/Access/ViewAccessCheck.php
A custom access check.

File

src/Access/ViewAccessCheck.php, line 114

Class

ViewAccessCheck
Determines access to for node add pages.

Namespace

Drupal\node_accessibility\Access

Code

private static function nodeRevisionIsValid($nid, $vid) {
  $node_type = NULL;
  try {
    $query = \Drupal::database()
      ->select('node', 'n');
    $query
      ->innerJoin('node_revision', 'nr', 'n.nid = nr.nid');
    $query
      ->addField('n', 'nid', 'nid');
    $query
      ->addField('nr', 'vid', 'vid');
    $query
      ->condition('n.nid', $nid);
    $query
      ->condition('nr.vid', $vid);
    $existing = $query
      ->execute()
      ->fetchObject();
    if ($existing && $existing->nid == $nid) {
      return TRUE;
    }
  } catch (Exception $e) {
    \Drupal::logger('node_accessibility')
      ->error("Failed to select from {node} table or {node_revision} table, exception: @exception.", [
      '@exception' => $e
        ->getMessage(),
    ]);
  } catch (Error $e) {
    \Drupal::logger('node_accessibility')
      ->error("Failed to select from {node} table or {node_revision} table, exception: @exception.", [
      '@exception' => $e
        ->getMessage(),
    ]);
  }
  return FALSE;
}