Skip to content
Snippets Groups Projects
Commit 80e1ff2c authored by catch's avatar catch
Browse files

Issue #1792380 by theo_: Fixed DatabaseCondition not cloning SelectQuery value object.

parent 0244e9c8
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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']);
}
}
}
}
......
<?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');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment