--- 1349080-d8-move-access-to-join-condition-update-test.patch 2013-11-13 09:07:21.185482799 +0100 +++ 1349080-143-d8-move-access-to-join-condition-update-test.patch 2013-11-13 09:07:21.005485061 +0100 @@ -1,5 +1,5 @@ diff --git a/core/lib/Drupal/Core/Database/Query/SelectExtender.php b/core/lib/Drupal/Core/Database/Query/SelectExtender.php -index 2f27d1b..47ee063 100644 +index d60931d..746335b 100644 --- a/core/lib/Drupal/Core/Database/Query/SelectExtender.php +++ b/core/lib/Drupal/Core/Database/Query/SelectExtender.php @@ -55,7 +55,7 @@ public function uniqueIdentifier() { @@ -11,9 +11,61 @@ } /* Implementations of Drupal\Core\Database\Query\AlterableInterface. */ +diff --git a/core/modules/node/lib/Drupal/node/NodeGrantDatabaseStorage.php b/core/modules/node/lib/Drupal/node/NodeGrantDatabaseStorage.php +index 8dcc8f3..590ffee 100644 +--- a/core/modules/node/lib/Drupal/node/NodeGrantDatabaseStorage.php ++++ b/core/modules/node/lib/Drupal/node/NodeGrantDatabaseStorage.php +@@ -124,7 +124,7 @@ public function checkAll(AccountInterface $account) { + /** + * {@inheritdoc} + */ +- public function alterQuery($query, array $tables, $op, AccountInterface $account, $base_table) { ++ public function alterQuery($query, array &$tables, $op, AccountInterface $account, $base_table) { + if (!$langcode = $query->getMetaData('langcode')) { + $langcode = FALSE; + } +@@ -174,8 +174,23 @@ public function alterQuery($query, array $tables, $op, AccountInterface $account + $field = 'nid'; + // Now handle entities. + $subquery->where("$nalias.$field = na.nid"); +- +- $query->exists($subquery); ++ if (empty($tableinfo['join type'])) { ++ // If we are looking at the main table of the query, apply the ++ // subquery directly. ++ $query->exists($subquery); ++ } ++ else { ++ // If we are looking at a joined table, add the node access check ++ // to the join condition. ++ $tables[$nalias]['condition'] .= ' AND EXISTS(' . (string)$subquery . ')'; ++ $tables[$nalias]['arguments'] += $subquery->arguments(); ++ // Increment the placeholder count on the main query until it matches the placeholders ++ // used by the subquery. ++ $cond_count = $subquery->nextPlaceholder(); ++ while ($cond_count--) { ++ $query->nextPlaceholder(); ++ } ++ } + } + } + } +diff --git a/core/modules/node/lib/Drupal/node/NodeGrantDatabaseStorageInterface.php b/core/modules/node/lib/Drupal/node/NodeGrantDatabaseStorageInterface.php +index 2457b8f..dc02656 100644 +--- a/core/modules/node/lib/Drupal/node/NodeGrantDatabaseStorageInterface.php ++++ b/core/modules/node/lib/Drupal/node/NodeGrantDatabaseStorageInterface.php +@@ -49,7 +49,7 @@ public function checkAll(AccountInterface $account); + * @return int + * Status of the access check. + */ +- public function alterQuery($query, array $tables, $op, AccountInterface $account, $base_table); ++ public function alterQuery($query, array &$tables, $op, AccountInterface $account, $base_table); + + /** + * Writes a list of grants to the database, deleting previously saved ones. diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessSubqueryTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessSubqueryTest.php new file mode 100644 -index 0000000..70873c4 +index 0000000..31ef2b8 --- /dev/null +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessSubqueryTest.php @@ -0,0 +1,204 @@ @@ -171,7 +223,7 @@ + // We now expect the regular user to have the same number of rows, but with + // a value in the subquery columns for node 2 instead of null. + // $expected_user_count++; -+ ++ + // Re-run queries from above: + $query = clone $base_query; + $query->addMetaData('account', $this->admin_user); @@ -222,10 +274,10 @@ + } +} diff --git a/core/modules/node/node.module b/core/modules/node/node.module -index f663387..c684f00 100644 +index 438104d..59ff47a 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module -@@ -2798,7 +2798,7 @@ function node_query_node_access_alter(AlterableInterface $query) { +@@ -1758,7 +1758,7 @@ function node_query_node_access_alter(AlterableInterface $query) { return; } @@ -234,29 +286,3 @@ $base_table = $query->getMetaData('base_table'); // If the base table is not given, default to node if present. if (!$base_table) { -@@ -2863,8 +2863,23 @@ function node_query_node_access_alter(AlterableInterface $query) { - $field = 'nid'; - // Now handle entities. - $subquery->where("$nalias.$field = na.nid"); -- -- $query->exists($subquery); -+ if (empty($tableinfo['join type'])) { -+ // If we are looking at the main table of the query, apply the -+ // subquery directly. -+ $query->exists($subquery); -+ } -+ else { -+ // If we are looking at a joined table, add the node access check -+ // to the join condition. -+ $tables[$nalias]['condition'] .= ' AND EXISTS(' . (string)$subquery . ')'; -+ $tables[$nalias]['arguments'] += $subquery->arguments(); -+ // Increment the placeholder count on the main query until it matches the placeholders -+ // used by the subquery. -+ $cond_count = $subquery->nextPlaceholder(); -+ while ($cond_count--) { -+ $query->nextPlaceholder(); -+ } -+ } - } - } - }