Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
7b77b90c
Commit
7b77b90c
authored
Jun 25, 2010
by
Dries
Browse files
- Patch
#795174
by Berdir: use %alias in SelectQuery joins and remove workarounds.
parent
b54ff2c8
Changes
6
Hide whitespace changes
Inline
Side-by-side
modules/book/book.module
View file @
7b77b90c
...
...
@@ -370,12 +370,12 @@ function book_get_books() {
if
(
$nids
)
{
$query
=
db_select
(
'book'
,
'b'
,
array
(
'fetch'
=>
PDO
::
FETCH_ASSOC
));
$node_alias
=
$query
->
join
(
'node'
,
'n'
,
'b.nid = n.nid'
);
$menu_links_alias
=
$query
->
join
(
'menu_links'
,
'ml'
,
'b.mlid = ml.mlid'
);
$query
->
join
(
'node'
,
'n'
,
'b.nid = n.nid'
);
$query
->
join
(
'menu_links'
,
'ml'
,
'b.mlid = ml.mlid'
);
$query
->
addField
(
'n'
,
'type'
,
'type'
);
$query
->
addField
(
'n'
,
'title'
,
'title'
);
$query
->
fields
(
'b'
);
$query
->
fields
(
$menu_links_alias
);
$query
->
fields
(
'ml'
);
$query
->
condition
(
'n.nid'
,
$nids
,
'IN'
);
$query
->
condition
(
'n.status'
,
1
);
$query
->
orderBy
(
'ml.weight'
);
...
...
@@ -1268,10 +1268,10 @@ function book_menu_subtree_data($link) {
// If the subtree data was not in the cache, $data will be NULL.
if
(
!
isset
(
$data
))
{
$query
=
db_select
(
'menu_links'
,
'ml'
,
array
(
'fetch'
=>
PDO
::
FETCH_ASSOC
));
$menu_router_alias
=
$query
->
join
(
'menu_router'
,
'm'
,
'm.path = ml.router_path'
);
$book_alias
=
$query
->
join
(
'book'
,
'b'
,
'ml.mlid = b.mlid'
);
$query
->
fields
(
$book_alias
);
$query
->
fields
(
$menu_router_alias
,
array
(
'load_functions'
,
'to_arg_functions'
,
'access_callback'
,
'access_arguments'
,
'page_callback'
,
'page_arguments'
,
'delivery_callback'
,
'title'
,
'title_callback'
,
'title_arguments'
,
'type'
));
$query
->
join
(
'menu_router'
,
'm'
,
'm.path = ml.router_path'
);
$query
->
join
(
'book'
,
'b'
,
'ml.mlid = b.mlid'
);
$query
->
fields
(
'b'
);
$query
->
fields
(
'm'
,
array
(
'load_functions'
,
'to_arg_functions'
,
'access_callback'
,
'access_arguments'
,
'page_callback'
,
'page_arguments'
,
'delivery_callback'
,
'title'
,
'title_callback'
,
'title_arguments'
,
'type'
));
$query
->
fields
(
'ml'
);
$query
->
condition
(
'menu_name'
,
$link
[
'menu_name'
]);
for
(
$i
=
1
;
$i
<=
MENU_MAX_DEPTH
&&
$link
[
"p
$i
"
];
++
$i
)
{
...
...
modules/node/node.admin.inc
View file @
7b77b90c
...
...
@@ -119,14 +119,12 @@ function node_filters() {
function
node_build_filter_query
(
SelectQueryInterface
$query
)
{
// Build query
$filter_data
=
isset
(
$_SESSION
[
'node_overview_filter'
])
?
$_SESSION
[
'node_overview_filter'
]
:
array
();
$counter
=
0
;
foreach
(
$filter_data
as
$index
=>
$filter
)
{
list
(
$key
,
$value
)
=
$filter
;
switch
(
$key
)
{
case
'term'
:
$index
=
'ti'
.
$counter
++
;
$query
->
join
(
'taxonomy_index'
,
$index
,
"n.nid =
$index
.nid"
);
$query
->
condition
(
$index
.
'.tid'
,
$value
);
$alias
=
$query
->
join
(
'taxonomy_index'
,
'ti'
,
"n.nid = %alias.nid"
);
$query
->
condition
(
$alias
.
'.tid'
,
$value
);
break
;
case
'status'
:
// Note: no exploitable hole as $key/$value have already been checked when submitted
...
...
modules/node/node.module
View file @
7b77b90c
...
...
@@ -3031,15 +3031,15 @@ function node_query_node_access_alter(QueryAlterableInterface $query) {
if
(
!
(
$table
instanceof
SelectQueryInterface
)
&&
$table
==
'node'
)
{
// The node_access table has the access grants for any given node.
$access_alias
=
$query
->
join
(
'node_access'
,
'na'
,
"na
.nid =
{
$nalias
}
.nid
"
);
$access_alias
=
$query
->
join
(
'node_access'
,
'na'
,
'%alias
.nid =
'
.
$nalias
.
'
.nid
'
);
$or
=
db_or
();
// If any grant exists for the specified user, then user has access
// to the node for the specified operation.
foreach
(
$grants
as
$realm
=>
$gids
)
{
foreach
(
$gids
as
$gid
)
{
$or
->
condition
(
db_and
()
->
condition
(
"
{
$access_alias
}
.gid
"
,
$gid
)
->
condition
(
"
{
$access_alias
}
.realm
"
,
$realm
)
->
condition
(
$access_alias
.
'
.gid
'
,
$gid
)
->
condition
(
$access_alias
.
'
.realm
'
,
$realm
)
);
}
}
...
...
@@ -3048,7 +3048,7 @@ function node_query_node_access_alter(QueryAlterableInterface $query) {
$query
->
condition
(
$or
);
}
$query
->
condition
(
"
{
$access_alias
}
.grant_
$op
"
,
1
,
'>='
);
$query
->
condition
(
$access_alias
.
'
.grant_
'
.
$op
,
1
,
'>='
);
}
}
}
...
...
modules/simpletest/tests/database_test.module
View file @
7b77b90c
...
...
@@ -11,8 +11,8 @@ function database_test_query_alter(QueryAlterableInterface $query) {
}
if
(
$query
->
hasTag
(
'database_test_alter_add_join'
))
{
$people_alias
=
$query
->
join
(
'test'
,
'people'
,
"test_task.pid
=people
.id"
);
$name_field
=
$query
->
addField
(
'
people
'
,
'name'
,
'name'
);
$people_alias
=
$query
->
join
(
'test'
,
'people'
,
"test_task.pid
= %alias
.id"
);
$name_field
=
$query
->
addField
(
$
people
_alias
,
'name'
,
'name'
);
$query
->
condition
(
$people_alias
.
'.id'
,
2
);
}
...
...
modules/system/system.api.php
View file @
7b77b90c
...
...
@@ -2656,14 +2656,14 @@ function hook_query_TAG_alter(QueryAlterableInterface $query) {
// Skip the extra joins and conditions for node admins.
if
(
!
user_access
(
'bypass node access'
))
{
// The node_access table has the access grants for any given node.
$access_alias
=
$query
->
join
(
'node_access'
,
'na'
,
'
na
.nid = n.nid'
);
$access_alias
=
$query
->
join
(
'node_access'
,
'na'
,
'
%alias
.nid = n.nid'
);
$or
=
db_or
();
// If any grant exists for the specified user, then user has access to the node for the specified operation.
foreach
(
node_access_grants
(
$op
,
$query
->
getMetaData
(
'account'
))
as
$realm
=>
$gids
)
{
foreach
(
$gids
as
$gid
)
{
$or
->
condition
(
db_and
()
->
condition
(
"
{
$access_alias
}
.gid
"
,
$gid
)
->
condition
(
"
{
$access_alias
}
.realm
"
,
$realm
)
->
condition
(
$access_alias
.
'
.gid
'
,
$gid
)
->
condition
(
$access_alias
.
'
.realm
'
,
$realm
)
);
}
}
...
...
@@ -2672,7 +2672,7 @@ function hook_query_TAG_alter(QueryAlterableInterface $query) {
$query
->
condition
(
$or
);
}
$query
->
condition
(
"
{
$access_alias
}
.
grant_
$op
"
,
1
,
'>='
);
$query
->
condition
(
$access_alias
.
'
grant_
'
.
$op
,
1
,
'>='
);
}
}
}
...
...
modules/user/user.module
View file @
7b77b90c
...
...
@@ -3144,8 +3144,6 @@ function user_filters() {
*/
function
user_build_filter_query
(
SelectQuery
$query
)
{
$filters
=
user_filters
();
$role_count
=
0
;
$permission_count
=
0
;
// Extend Query with filter conditions.
foreach
(
isset
(
$_SESSION
[
'user_overview_filter'
])
?
$_SESSION
[
'user_overview_filter'
]
:
array
()
as
$filter
)
{
list
(
$key
,
$value
)
=
$filter
;
...
...
@@ -3159,19 +3157,13 @@ function user_build_filter_query(SelectQuery $query) {
if
(
user_access
(
$value
,
$account
))
{
continue
;
}
$user_role_alias
=
'ur'
.
$role_count
;
$permission_alias
=
'p'
.
$permission_count
;
$query
->
innerJoin
(
'users_roles'
,
$user_role_alias
,
$user_role_alias
.
'.uid = u.uid'
);
$query
->
innerJoin
(
'role_permission'
,
$permission_alias
,
$user_role_alias
.
'.rid = '
.
$permission_alias
.
'.rid'
);
$user_role_alias
=
$query
->
join
(
'users_roles'
,
'ur'
,
'%alias.uid = u.uid'
);
$permission_alias
=
$query
->
join
(
'role_permission'
,
'p'
,
$user_role_alias
.
'.rid = %alias.rid'
);
$query
->
condition
(
$permission_alias
.
'.permission'
,
$value
);
$role_count
++
;
$permission_count
++
;
}
else
if
(
$key
==
'role'
)
{
$user_role_alias
=
'ur'
.
$role_count
;
$query
->
innerJoin
(
'users_roles'
,
$user_role_alias
,
$user_role_alias
.
'.uid = u.uid'
);
$user_roles_alias
=
$query
->
join
(
'users_roles'
,
'ur'
,
'%alias.uid = u.uid'
);
$query
->
condition
(
$user_role_alias
.
'.rid'
,
$value
);
$role_count
++
;
}
else
{
$query
->
condition
(
$filters
[
$key
][
'field'
],
$value
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment