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

This reverts commit 7a943a3b5f.
merge-requests/2419/head
Alex Pott 2020-03-12 14:54:51 +00:00
parent 7a943a3b5f
commit 6139217555
No known key found for this signature in database
GPG Key ID: 31905460D4A69276
19 changed files with 12 additions and 153 deletions

View File

@ -942,22 +942,6 @@ abstract class Connection {
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.
*

View File

@ -1,10 +0,0 @@
<?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 {}

View File

@ -2,6 +2,7 @@
namespace Drupal\Core\Database\Driver\mysql;
use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Database\SchemaException;
use Drupal\Core\Database\SchemaObjectExistsException;
use Drupal\Core\Database\SchemaObjectDoesNotExistException;
@ -74,7 +75,7 @@ class Schema extends DatabaseSchema {
protected function buildTableNameCondition($table_name, $operator = '=', $add_prefix = TRUE) {
$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_name', $table_info['table'], $operator);
return $condition;

View File

@ -1,10 +0,0 @@
<?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 {}

View File

@ -1,10 +0,0 @@
<?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 {}

View File

@ -399,7 +399,7 @@ class Condition implements ConditionInterface, \Countable {
* {@inheritdoc}
*/
public function conditionGroupFactory($conjunction = 'AND') {
return new static($conjunction);
return new Condition($conjunction);
}
/**

View File

@ -36,7 +36,7 @@ class Delete extends Query implements ConditionInterface {
parent::__construct($connection, $options);
$this->table = $table;
$this->condition = $this->connection->condition('AND');
$this->condition = new Condition('AND');
}
/**

View File

@ -138,7 +138,7 @@ class Merge extends Query implements ConditionInterface {
parent::__construct($connection, $options);
$this->table = $table;
$this->conditionTable = $table;
$this->condition = $this->connection->condition('AND');
$this->condition = new Condition('AND');
}
/**

View File

@ -108,7 +108,7 @@ trait QueryConditionTrait {
* {@inheritdoc}
*/
public function conditionGroupFactory($conjunction = 'AND') {
return $this->connection->condition($conjunction);
return new Condition($conjunction);
}
/**

View File

@ -134,8 +134,8 @@ class Select extends Query implements SelectInterface {
$options['return'] = Database::RETURN_STATEMENT;
parent::__construct($connection, $options);
$conjunction = isset($options['conjunction']) ? $options['conjunction'] : 'AND';
$this->condition = $this->connection->condition($conjunction);
$this->having = $this->connection->condition($conjunction);
$this->condition = new Condition($conjunction);
$this->having = new Condition($conjunction);
$this->addJoin(NULL, $table, $alias);
}

View File

@ -521,7 +521,7 @@ class SelectExtender implements SelectInterface {
* {@inheritdoc}
*/
public function conditionGroupFactory($conjunction = 'AND') {
return $this->connection->condition($conjunction);
return new Condition($conjunction);
}
/**

View File

@ -65,7 +65,7 @@ class Update extends Query implements ConditionInterface {
parent::__construct($connection, $options);
$this->table = $table;
$this->condition = $this->connection->condition('AND');
$this->condition = new Condition('AND');
}
/**

View File

@ -2,6 +2,7 @@
namespace Drupal\Core\Database;
use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Database\Query\PlaceholderInterface;
/**
@ -149,7 +150,7 @@ abstract class Schema implements PlaceholderInterface {
// Retrieve the table name and schema
$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_schema', $table_info['schema']);
$condition->condition('table_name', $table_info['table'], $operator);

View File

@ -175,20 +175,4 @@ class ConnectionTest extends DatabaseTestBase {
}
}
/**
* 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));
}
}

View File

@ -159,22 +159,4 @@ class DeleteTruncateTest extends DatabaseTestBase {
$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));
}
}

View File

@ -230,22 +230,4 @@ class MergeTest extends DatabaseTestBase {
$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));
}
}

View File

@ -614,26 +614,4 @@ class SelectTest extends DatabaseTestBase {
}
}
/**
* 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));
}
}

View File

@ -141,22 +141,4 @@ class UpdateTest extends DatabaseTestBase {
$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));
}
}

View File

@ -2,7 +2,6 @@
namespace Drupal\Tests\Core\Database;
use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Database\Query\Select;
use Drupal\Tests\UnitTestCase;
@ -26,11 +25,7 @@ class OrderByTest extends UnitTestCase {
protected function setUp() {
$connection = $this->getMockBuilder('Drupal\Core\Database\Connection')
->disableOriginalConstructor()
->setMethods(['condition'])
->getMockForAbstractClass();
$connection->expects($this->any())
->method('condition')
->willReturn(new Condition('AND'));
$this->query = new Select($connection, 'test', NULL);
}