Unverified Commit 61392175 authored by alexpott's avatar alexpott
Browse files

Revert "Issue #3113403 by Beakerboy, daffie: Make...

Revert "Issue #3113403 by Beakerboy, daffie: Make Drupal\Core\Database\Query\Condition driver overridable"

This reverts commit 7a943a3b.
parent 7a943a3b
...@@ -942,22 +942,6 @@ public function schema() { ...@@ -942,22 +942,6 @@ public function schema() {
return $this->schema; return $this->schema;
} }
/**
* Prepares and returns a CONDITION query object.
*
* @param string $conjunction
* The operator to use to combine conditions: 'AND' or 'OR'.
*
* @return \Drupal\Core\Database\Query\Condition
* A new Condition query object.
*
* @see \Drupal\Core\Database\Query\Condition
*/
public function condition($conjunction) {
$class = $this->getDriverClass('Condition');
return new $class($conjunction);
}
/** /**
* Escapes a database name string. * Escapes a database name string.
* *
......
<?php
namespace Drupal\Core\Database\Driver\mysql;
use Drupal\Core\Database\Query\Condition as QueryCondition;
/**
* MySQL implementation of \Drupal\Core\Database\Query\Condition.
*/
class Condition extends QueryCondition {}
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\Core\Database\Driver\mysql; namespace Drupal\Core\Database\Driver\mysql;
use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Database\SchemaException; use Drupal\Core\Database\SchemaException;
use Drupal\Core\Database\SchemaObjectExistsException; use Drupal\Core\Database\SchemaObjectExistsException;
use Drupal\Core\Database\SchemaObjectDoesNotExistException; use Drupal\Core\Database\SchemaObjectDoesNotExistException;
...@@ -74,7 +75,7 @@ protected function getPrefixInfo($table = 'default', $add_prefix = TRUE) { ...@@ -74,7 +75,7 @@ protected function getPrefixInfo($table = 'default', $add_prefix = TRUE) {
protected function buildTableNameCondition($table_name, $operator = '=', $add_prefix = TRUE) { protected function buildTableNameCondition($table_name, $operator = '=', $add_prefix = TRUE) {
$table_info = $this->getPrefixInfo($table_name, $add_prefix); $table_info = $this->getPrefixInfo($table_name, $add_prefix);
$condition = $this->connection->condition('AND'); $condition = new Condition('AND');
$condition->condition('table_schema', $table_info['database']); $condition->condition('table_schema', $table_info['database']);
$condition->condition('table_name', $table_info['table'], $operator); $condition->condition('table_name', $table_info['table'], $operator);
return $condition; return $condition;
......
<?php
namespace Drupal\Core\Database\Driver\pgsql;
use Drupal\Core\Database\Query\Condition as QueryCondition;
/**
* PostgreSQL implementation of \Drupal\Core\Database\Query\Condition.
*/
class Condition extends QueryCondition {}
<?php
namespace Drupal\Core\Database\Driver\sqlite;
use Drupal\Core\Database\Query\Condition as QueryCondition;
/**
* SQLite implementation of \Drupal\Core\Database\Query\Condition.
*/
class Condition extends QueryCondition {}
...@@ -399,7 +399,7 @@ protected function mapConditionOperator($operator) { ...@@ -399,7 +399,7 @@ protected function mapConditionOperator($operator) {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function conditionGroupFactory($conjunction = 'AND') { public function conditionGroupFactory($conjunction = 'AND') {
return new static($conjunction); return new Condition($conjunction);
} }
/** /**
......
...@@ -36,7 +36,7 @@ public function __construct(Connection $connection, $table, array $options = []) ...@@ -36,7 +36,7 @@ public function __construct(Connection $connection, $table, array $options = [])
parent::__construct($connection, $options); parent::__construct($connection, $options);
$this->table = $table; $this->table = $table;
$this->condition = $this->connection->condition('AND'); $this->condition = new Condition('AND');
} }
/** /**
......
...@@ -138,7 +138,7 @@ public function __construct(Connection $connection, $table, array $options = []) ...@@ -138,7 +138,7 @@ public function __construct(Connection $connection, $table, array $options = [])
parent::__construct($connection, $options); parent::__construct($connection, $options);
$this->table = $table; $this->table = $table;
$this->conditionTable = $table; $this->conditionTable = $table;
$this->condition = $this->connection->condition('AND'); $this->condition = new Condition('AND');
} }
/** /**
......
...@@ -108,7 +108,7 @@ public function compiled() { ...@@ -108,7 +108,7 @@ public function compiled() {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function conditionGroupFactory($conjunction = 'AND') { public function conditionGroupFactory($conjunction = 'AND') {
return $this->connection->condition($conjunction); return new Condition($conjunction);
} }
/** /**
......
...@@ -134,8 +134,8 @@ public function __construct(Connection $connection, $table, $alias = NULL, $opti ...@@ -134,8 +134,8 @@ public function __construct(Connection $connection, $table, $alias = NULL, $opti
$options['return'] = Database::RETURN_STATEMENT; $options['return'] = Database::RETURN_STATEMENT;
parent::__construct($connection, $options); parent::__construct($connection, $options);
$conjunction = isset($options['conjunction']) ? $options['conjunction'] : 'AND'; $conjunction = isset($options['conjunction']) ? $options['conjunction'] : 'AND';
$this->condition = $this->connection->condition($conjunction); $this->condition = new Condition($conjunction);
$this->having = $this->connection->condition($conjunction); $this->having = new Condition($conjunction);
$this->addJoin(NULL, $table, $alias); $this->addJoin(NULL, $table, $alias);
} }
......
...@@ -521,7 +521,7 @@ public function __call($method, $args) { ...@@ -521,7 +521,7 @@ public function __call($method, $args) {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function conditionGroupFactory($conjunction = 'AND') { public function conditionGroupFactory($conjunction = 'AND') {
return $this->connection->condition($conjunction); return new Condition($conjunction);
} }
/** /**
......
...@@ -65,7 +65,7 @@ public function __construct(Connection $connection, $table, array $options = []) ...@@ -65,7 +65,7 @@ public function __construct(Connection $connection, $table, array $options = [])
parent::__construct($connection, $options); parent::__construct($connection, $options);
$this->table = $table; $this->table = $table;
$this->condition = $this->connection->condition('AND'); $this->condition = new Condition('AND');
} }
/** /**
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\Core\Database; namespace Drupal\Core\Database;
use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Database\Query\PlaceholderInterface; use Drupal\Core\Database\Query\PlaceholderInterface;
/** /**
...@@ -149,7 +150,7 @@ protected function buildTableNameCondition($table_name, $operator = '=', $add_pr ...@@ -149,7 +150,7 @@ protected function buildTableNameCondition($table_name, $operator = '=', $add_pr
// Retrieve the table name and schema // Retrieve the table name and schema
$table_info = $this->getPrefixInfo($table_name, $add_prefix); $table_info = $this->getPrefixInfo($table_name, $add_prefix);
$condition = $this->connection->condition('AND'); $condition = new Condition('AND');
$condition->condition('table_catalog', $info['database']); $condition->condition('table_catalog', $info['database']);
$condition->condition('table_schema', $table_info['schema']); $condition->condition('table_schema', $table_info['schema']);
$condition->condition('table_name', $table_info['table'], $operator); $condition->condition('table_name', $table_info['table'], $operator);
......
...@@ -175,20 +175,4 @@ public function testPostgresqlReservedWords() { ...@@ -175,20 +175,4 @@ public function testPostgresqlReservedWords() {
} }
} }
/**
* Test that the method ::condition() returns an Condition object from the driver directory.
*/
public function testCondition() {
$db = Database::getConnection('default', 'default');
$namespace = (new \ReflectionObject($db))->getNamespaceName() . "\\Condition";
$condition = $db->condition('AND');
$this->assertIdentical($namespace, get_class($condition));
$nested_and_condition = $condition->andConditionGroup();
$this->assertIdentical($namespace, get_class($nested_and_condition));
$nested_or_condition = $condition->orConditionGroup();
$this->assertIdentical($namespace, get_class($nested_or_condition));
}
} }
...@@ -159,22 +159,4 @@ public function testSpecialColumnDelete() { ...@@ -159,22 +159,4 @@ public function testSpecialColumnDelete() {
$this->assertEqual($num_records_before, $num_records_after + $num_deleted, 'Deletion adds up.'); $this->assertEqual($num_records_before, $num_records_after + $num_deleted, 'Deletion adds up.');
} }
/**
* Tests namespace of the condition object.
*/
public function testNamespaceConditionObject() {
$namespace = (new \ReflectionObject($this->connection))->getNamespaceName() . "\\Condition";
$delete = $this->connection->delete('test');
$reflection = new \ReflectionObject($delete);
$condition_property = $reflection->getProperty('condition');
$condition_property->setAccessible(TRUE);
$this->assertIdentical($namespace, get_class($condition_property->getValue($delete)));
$nested_and_condition = $delete->andConditionGroup();
$this->assertIdentical($namespace, get_class($nested_and_condition));
$nested_or_condition = $delete->orConditionGroup();
$this->assertIdentical($namespace, get_class($nested_or_condition));
}
} }
...@@ -230,22 +230,4 @@ public function testInvalidMerge() { ...@@ -230,22 +230,4 @@ public function testInvalidMerge() {
$this->fail('No InvalidMergeQueryException thrown'); $this->fail('No InvalidMergeQueryException thrown');
} }
/**
* Tests namespace of the condition object.
*/
public function testNamespaceConditionObject() {
$namespace = (new \ReflectionObject($this->connection))->getNamespaceName() . "\\Condition";
$merge = $this->connection->merge('test');
$reflection = new \ReflectionObject($merge);
$condition_property = $reflection->getProperty('condition');
$condition_property->setAccessible(TRUE);
$this->assertIdentical($namespace, get_class($condition_property->getValue($merge)));
$nested_and_condition = $merge->andConditionGroup();
$this->assertIdentical($namespace, get_class($nested_and_condition));
$nested_or_condition = $merge->orConditionGroup();
$this->assertIdentical($namespace, get_class($nested_or_condition));
}
} }
...@@ -614,26 +614,4 @@ public function testEmptyInCondition() { ...@@ -614,26 +614,4 @@ public function testEmptyInCondition() {
} }
} }
/**
* Tests namespace of the condition and having objects.
*/
public function testNamespaceConditionAndHavingObjects() {
$namespace = (new \ReflectionObject($this->connection))->getNamespaceName() . "\\Condition";
$select = $this->connection->select('test');
$reflection = new \ReflectionObject($select);
$condition_property = $reflection->getProperty('condition');
$condition_property->setAccessible(TRUE);
$this->assertIdentical($namespace, get_class($condition_property->getValue($select)));
$having_property = $reflection->getProperty('having');
$having_property->setAccessible(TRUE);
$this->assertIdentical($namespace, get_class($having_property->getValue($select)));
$nested_and_condition = $select->andConditionGroup();
$this->assertIdentical($namespace, get_class($nested_and_condition));
$nested_or_condition = $select->orConditionGroup();
$this->assertIdentical($namespace, get_class($nested_or_condition));
}
} }
...@@ -141,22 +141,4 @@ public function testSpecialColumnUpdate() { ...@@ -141,22 +141,4 @@ public function testSpecialColumnUpdate() {
$this->assertIdentical($saved_value, 'New offset value', 'Updated special column name value successfully.'); $this->assertIdentical($saved_value, 'New offset value', 'Updated special column name value successfully.');
} }
/**
* Tests namespace of the condition object.
*/
public function testNamespaceConditionObject() {
$namespace = (new \ReflectionObject($this->connection))->getNamespaceName() . "\\Condition";
$update = $this->connection->update('test');
$reflection = new \ReflectionObject($update);
$condition_property = $reflection->getProperty('condition');
$condition_property->setAccessible(TRUE);
$this->assertIdentical($namespace, get_class($condition_property->getValue($update)));
$nested_and_condition = $update->andConditionGroup();
$this->assertIdentical($namespace, get_class($nested_and_condition));
$nested_or_condition = $update->orConditionGroup();
$this->assertIdentical($namespace, get_class($nested_or_condition));
}
} }
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
namespace Drupal\Tests\Core\Database; namespace Drupal\Tests\Core\Database;
use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Database\Query\Select; use Drupal\Core\Database\Query\Select;
use Drupal\Tests\UnitTestCase; use Drupal\Tests\UnitTestCase;
...@@ -26,11 +25,7 @@ class OrderByTest extends UnitTestCase { ...@@ -26,11 +25,7 @@ class OrderByTest extends UnitTestCase {
protected function setUp() { protected function setUp() {
$connection = $this->getMockBuilder('Drupal\Core\Database\Connection') $connection = $this->getMockBuilder('Drupal\Core\Database\Connection')
->disableOriginalConstructor() ->disableOriginalConstructor()
->setMethods(['condition'])
->getMockForAbstractClass(); ->getMockForAbstractClass();
$connection->expects($this->any())
->method('condition')
->willReturn(new Condition('AND'));
$this->query = new Select($connection, 'test', NULL); $this->query = new Select($connection, 'test', NULL);
} }
......
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