Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
80e1ff2c
Commit
80e1ff2c
authored
12 years ago
by
catch
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#1792380
by theo_: Fixed DatabaseCondition not cloning SelectQuery value object.
parent
0244e9c8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/lib/Drupal/Core/Database/Query/Condition.php
+7
-2
7 additions, 2 deletions
core/lib/Drupal/Core/Database/Query/Condition.php
core/modules/system/lib/Drupal/system/Tests/Database/SelectCloneTest.php
+47
-0
47 additions, 0 deletions
...stem/lib/Drupal/system/Tests/Database/SelectCloneTest.php
with
54 additions
and
2 deletions
core/lib/Drupal/Core/Database/Query/Condition.php
+
7
−
2
View file @
80e1ff2c
...
...
@@ -259,8 +259,13 @@ public function __toString() {
function
__clone
()
{
$this
->
changed
=
TRUE
;
foreach
(
$this
->
conditions
as
$key
=>
$condition
)
{
if
(
$key
!==
'#conjunction'
&&
$condition
[
'field'
]
instanceOf
ConditionInterface
)
{
$this
->
conditions
[
$key
][
'field'
]
=
clone
(
$condition
[
'field'
]);
if
(
$key
!==
'#conjunction'
)
{
if
(
$condition
[
'field'
]
instanceOf
ConditionInterface
)
{
$this
->
conditions
[
$key
][
'field'
]
=
clone
(
$condition
[
'field'
]);
}
if
(
$condition
[
'value'
]
instanceOf
SelectInterface
)
{
$this
->
conditions
[
$key
][
'value'
]
=
clone
(
$condition
[
'value'
]);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
core/modules/system/lib/Drupal/system/Tests/Database/SelectCloneTest.php
0 → 100644
+
47
−
0
View file @
80e1ff2c
<?php
/**
* @file
* Contains \Drupal\system\Tests\Database\SelectCloneTest.
*/
namespace
Drupal\system\Tests\Database
;
/**
* Test cloning Select queries.
*/
class
SelectCloneTest
extends
DatabaseTestBase
{
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'Select tests, cloning'
,
'description'
=>
'Test cloning Select queries.'
,
'group'
=>
'Database'
,
);
}
/**
* Test that subqueries as value within conditions are cloned properly.
*/
function
testSelectConditionSubQueryCloning
()
{
$subquery
=
db_select
(
'test'
,
't'
);
$subquery
->
addField
(
't'
,
'id'
,
'id'
);
$subquery
->
condition
(
'age'
,
28
,
'<'
);
$query
=
db_select
(
'test'
,
't'
);
$query
->
addField
(
't'
,
'name'
,
'name'
);
$query
->
condition
(
'id'
,
$subquery
,
'IN'
);
$clone
=
clone
$query
;
// Cloned query should not be altered by the following modification
// happening on original query.
$subquery
->
condition
(
'age'
,
25
,
'>'
);
$clone_result
=
$clone
->
countQuery
()
->
execute
()
->
fetchField
();
$query_result
=
$query
->
countQuery
()
->
execute
()
->
fetchField
();
// Make sure the cloned query has not been modified
$this
->
assertEqual
(
3
,
$clone_result
,
'The cloned query returns the expected number of rows'
);
$this
->
assertEqual
(
2
,
$query_result
,
'The query returns the expected number of rows'
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment