Commit e2e00e91 authored by alexpott's avatar alexpott

Issue #2405163 by chx: NodeRevisionAccessCheck is database dependent

parent 6cf1d801
......@@ -10,10 +10,9 @@ services:
- { name: backend_overridable }
access_check.node.revision:
class: Drupal\node\Access\NodeRevisionAccessCheck
arguments: ['@entity.manager', '@database']
arguments: ['@entity.manager']
tags:
- { name: access_check, applies_to: _access_node_revision }
- { name: backend_overridable }
access_check.node.add:
class: Drupal\node\Access\NodeAddAccessCheck
arguments: ['@entity.manager']
......
......@@ -8,7 +8,6 @@
namespace Drupal\node\Access;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Session\AccountInterface;
......@@ -23,7 +22,7 @@ class NodeRevisionAccessCheck implements AccessInterface {
/**
* The node storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
* @var \Drupal\node\NodeStorageInterface
*/
protected $nodeStorage;
......@@ -34,13 +33,6 @@ class NodeRevisionAccessCheck implements AccessInterface {
*/
protected $nodeAccess;
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* A static cache of access checks.
*
......@@ -56,10 +48,9 @@ class NodeRevisionAccessCheck implements AccessInterface {
* @param \Drupal\Core\Database\Connection $connection
* The database connection.
*/
public function __construct(EntityManagerInterface $entity_manager, Connection $connection) {
public function __construct(EntityManagerInterface $entity_manager) {
$this->nodeStorage = $entity_manager->getStorage('node');
$this->nodeAccess = $entity_manager->getAccessControlHandler('node');
$this->connection = $connection;
}
/**
......@@ -147,7 +138,7 @@ public function checkAccess(NodeInterface $node, AccountInterface $account, $op
// different revisions so there is no need for a separate database check.
// Also, if you try to revert to or delete the default revision, that's
// not good.
if ($node->isDefaultRevision() && ($this->connection->query('SELECT COUNT(*) FROM {node_field_revision} WHERE nid = :nid AND default_langcode = 1', array(':nid' => $node->id()))->fetchField() == 1 || $op == 'update' || $op == 'delete')) {
if ($node->isDefaultRevision() && ($this->nodeStorage->countDefaultLanguageRevisions($node) == 1 || $op == 'update' || $op == 'delete')) {
$this->access[$cid] = FALSE;
}
elseif ($account->hasPermission('administer nodes')) {
......
......@@ -39,6 +39,13 @@ public function userRevisionIds(AccountInterface $account) {
)->fetchCol();
}
/**
* {@inheritdoc}
*/
public function countDefaultLanguageRevisions(NodeInterface $node) {
return $this->database->query('SELECT COUNT(*) FROM {node_field_revision} WHERE nid = :nid AND default_langcode = 1', array(':nid' => $node->id()))->fetchField();
}
/**
* {@inheritdoc}
*/
......
......@@ -38,6 +38,17 @@ public function revisionIds(NodeInterface $node);
*/
public function userRevisionIds(AccountInterface $account);
/**
* Counts the number of revisions in the default language.
*
* @param \Drupal\node\NodeInterface
* The node entity.
*
* @return int
* The number of revisions in the default language.
*/
public function countDefaultLanguageRevisions(NodeInterface $node);
/**
* Updates all nodes of one type to be of another type.
*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment