Commit 23d140fd authored by alexpott's avatar alexpott

Issue #2117305 by disasm, Pavan B S, ieguskiza, Jo Fitzgerald: Replace usages...

Issue #2117305 by disasm, Pavan B S, ieguskiza, Jo Fitzgerald: Replace usages of db_or() and db_and()
parent 0d27b063
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
* Hooks related to the Database system and the Schema API. * Hooks related to the Database system and the Schema API.
*/ */
use Drupal\Core\Database\Query\Condition;
/** /**
* @defgroup database Database abstraction layer * @defgroup database Database abstraction layer
* @{ * @{
...@@ -432,11 +434,11 @@ function hook_query_TAG_alter(Drupal\Core\Database\Query\AlterableInterface $que ...@@ -432,11 +434,11 @@ function hook_query_TAG_alter(Drupal\Core\Database\Query\AlterableInterface $que
if (!\Drupal::currentUser()->hasPermission('bypass node access')) { if (!\Drupal::currentUser()->hasPermission('bypass node access')) {
// The node_access table has the access grants for any given node. // The node_access table has the access grants for any given node.
$access_alias = $query->join('node_access', 'na', '%alias.nid = n.nid'); $access_alias = $query->join('node_access', 'na', '%alias.nid = n.nid');
$or = db_or(); $or = new Condition('OR');
// If any grant exists for the specified user, then user has access to the node for the specified operation. // 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 (node_access_grants($op, $query->getMetaData('account')) as $realm => $gids) {
foreach ($gids as $gid) { foreach ($gids as $gid) {
$or->condition(db_and() $or->condition((new Condition('AND'))
->condition($access_alias . '.gid', $gid) ->condition($access_alias . '.gid', $gid)
->condition($access_alias . '.realm', $realm) ->condition($access_alias . '.realm', $realm)
); );
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Drupal\comment\Plugin\views\argument; namespace Drupal\comment\Plugin\views\argument;
use Drupal\Core\Database\Connection; use Drupal\Core\Database\Connection;
use Drupal\Core\Database\Query\Condition;
use Drupal\views\Plugin\views\argument\ArgumentPluginBase; use Drupal\views\Plugin\views\argument\ArgumentPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
...@@ -90,7 +91,7 @@ public function query($group_by = FALSE) { ...@@ -90,7 +91,7 @@ public function query($group_by = FALSE) {
$subselect->where("c.entity_id = $this->tableAlias.$entity_id"); $subselect->where("c.entity_id = $this->tableAlias.$entity_id");
$subselect->condition('c.entity_type', $entity_type); $subselect->condition('c.entity_type', $entity_type);
$condition = db_or() $condition = (new Condition('OR'))
->condition("$this->tableAlias.uid", $this->argument, '=') ->condition("$this->tableAlias.uid", $this->argument, '=')
->exists($subselect); ->exists($subselect);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\comment\Plugin\views\filter; namespace Drupal\comment\Plugin\views\filter;
use Drupal\Core\Database\Query\Condition;
use Drupal\views\Plugin\views\filter\FilterPluginBase; use Drupal\views\Plugin\views\filter\FilterPluginBase;
/** /**
...@@ -26,7 +27,7 @@ public function query() { ...@@ -26,7 +27,7 @@ public function query() {
$subselect->where("c.entity_id = $this->tableAlias.$entity_id"); $subselect->where("c.entity_id = $this->tableAlias.$entity_id");
$subselect->condition('c.entity_type', $entity_type); $subselect->condition('c.entity_type', $entity_type);
$condition = db_or() $condition = (new Condition('OR'))
->condition("$this->tableAlias.uid", $this->value, $this->operator) ->condition("$this->tableAlias.uid", $this->value, $this->operator)
->exists($subselect); ->exists($subselect);
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Drupal\locale; namespace Drupal\locale;
use Drupal\Core\Database\Connection; use Drupal\Core\Database\Connection;
use Drupal\Core\Database\Query\Condition;
/** /**
* Defines a class to store localized strings in the database. * Defines a class to store localized strings in the database.
...@@ -416,7 +417,7 @@ protected function dbStringSelect(array $conditions, array $options = array()) { ...@@ -416,7 +417,7 @@ protected function dbStringSelect(array $conditions, array $options = array()) {
elseif ($table_alias == 't' && $join === 'leftJoin') { elseif ($table_alias == 't' && $join === 'leftJoin') {
// Conditions for target fields when doing an outer join only make // Conditions for target fields when doing an outer join only make
// sense if we add also OR field IS NULL. // sense if we add also OR field IS NULL.
$query->condition(db_or() $query->condition((new Condition('OR'))
->condition($field_alias, (array) $value, 'IN') ->condition($field_alias, (array) $value, 'IN')
->isNull($field_alias) ->isNull($field_alias)
); );
...@@ -429,7 +430,7 @@ protected function dbStringSelect(array $conditions, array $options = array()) { ...@@ -429,7 +430,7 @@ protected function dbStringSelect(array $conditions, array $options = array()) {
// Process other options, string filter, query limit, etc. // Process other options, string filter, query limit, etc.
if (!empty($options['filters'])) { if (!empty($options['filters'])) {
if (count($options['filters']) > 1) { if (count($options['filters']) > 1) {
$filter = db_or(); $filter = new Condition('OR');
$query->condition($filter); $query->condition($filter);
} }
else { else {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\node\Plugin\views\filter; namespace Drupal\node\Plugin\views\filter;
use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\filter\FilterPluginBase; use Drupal\views\Plugin\views\filter\FilterPluginBase;
...@@ -27,10 +28,10 @@ public function query() { ...@@ -27,10 +28,10 @@ public function query() {
$account = $this->view->getUser(); $account = $this->view->getUser();
if (!$account->hasPermission('bypass node access')) { if (!$account->hasPermission('bypass node access')) {
$table = $this->ensureMyTable(); $table = $this->ensureMyTable();
$grants = db_or(); $grants = new Condition('OR');
foreach (node_access_grants('view', $account) as $realm => $gids) { foreach (node_access_grants('view', $account) as $realm => $gids) {
foreach ($gids as $gid) { foreach ($gids as $gid) {
$grants->condition(db_and() $grants->condition((new Condition('AND'))
->condition($table . '.gid', $gid) ->condition($table . '.gid', $gid)
->condition($table . '.realm', $realm) ->condition($table . '.realm', $realm)
); );
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\Unicode;
use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\Cache;
use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Routing\RouteMatchInterface;
...@@ -218,7 +219,7 @@ function search_update_totals() { ...@@ -218,7 +219,7 @@ function search_update_totals() {
// search_total. We use a LEFT JOIN between the two tables and keep only the // search_total. We use a LEFT JOIN between the two tables and keep only the
// rows which fail to join. // rows which fail to join.
$result = db_query("SELECT t.word AS realword, i.word FROM {search_total} t LEFT JOIN {search_index} i ON t.word = i.word WHERE i.word IS NULL", array(), array('target' => 'replica')); $result = db_query("SELECT t.word AS realword, i.word FROM {search_total} t LEFT JOIN {search_index} i ON t.word = i.word WHERE i.word IS NULL", array(), array('target' => 'replica'));
$or = db_or(); $or = new Condition('OR');
foreach ($result as $word) { foreach ($result as $word) {
$or->condition('word', $word->realword); $or->condition('word', $word->realword);
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\search\Plugin\views\argument; namespace Drupal\search\Plugin\views\argument;
use Drupal\Core\Database\Query\Condition;
use Drupal\views\Plugin\views\argument\ArgumentPluginBase; use Drupal\views\Plugin\views\argument\ArgumentPluginBase;
use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\ViewExecutable; use Drupal\views\ViewExecutable;
...@@ -76,7 +77,7 @@ public function query($group_by = FALSE) { ...@@ -76,7 +77,7 @@ public function query($group_by = FALSE) {
else { else {
$search_index = $this->ensureMyTable(); $search_index = $this->ensureMyTable();
$search_condition = db_and(); $search_condition = new Condition('AND');
// Create a new join to relate the 'search_total' table to our current 'search_index' table. // Create a new join to relate the 'search_total' table to our current 'search_index' table.
$definition = array( $definition = array(
...@@ -109,7 +110,7 @@ public function query($group_by = FALSE) { ...@@ -109,7 +110,7 @@ public function query($group_by = FALSE) {
// Add the keyword conditions, as is done in // Add the keyword conditions, as is done in
// SearchQuery::prepareAndNormalize(), but simplified because we are // SearchQuery::prepareAndNormalize(), but simplified because we are
// only concerned with relevance ranking so we do not need to normalize. // only concerned with relevance ranking so we do not need to normalize.
$or = db_or(); $or = new Condition('OR');
foreach ($words as $word) { foreach ($words as $word) {
$or->condition("$search_index.word", $word); $or->condition("$search_index.word", $word);
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\search\Plugin\views\filter; namespace Drupal\search\Plugin\views\filter;
use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\filter\FilterPluginBase; use Drupal\views\Plugin\views\filter\FilterPluginBase;
use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\display\DisplayPluginBase;
...@@ -150,7 +151,7 @@ public function query() { ...@@ -150,7 +151,7 @@ public function query() {
else { else {
$search_index = $this->ensureMyTable(); $search_index = $this->ensureMyTable();
$search_condition = db_and(); $search_condition = new Condition('AND');
// Create a new join to relate the 'search_total' table to our current // Create a new join to relate the 'search_total' table to our current
// 'search_index' table. // 'search_index' table.
...@@ -184,7 +185,7 @@ public function query() { ...@@ -184,7 +185,7 @@ public function query() {
// Add the keyword conditions, as is done in // Add the keyword conditions, as is done in
// SearchQuery::prepareAndNormalize(), but simplified because we are // SearchQuery::prepareAndNormalize(), but simplified because we are
// only concerned with relevance ranking so we do not need to normalize. // only concerned with relevance ranking so we do not need to normalize.
$or = db_or(); $or = new Condition('OR');
foreach ($words as $word) { foreach ($words as $word) {
$or->condition("$search_index.word", $word); $or->condition("$search_index.word", $word);
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\search; namespace Drupal\search;
use Drupal\Core\Database\Query\Condition;
use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\Unicode;
use Drupal\Core\Database\Query\SelectExtender; use Drupal\Core\Database\Query\SelectExtender;
use Drupal\Core\Database\Query\SelectInterface; use Drupal\Core\Database\Query\SelectInterface;
...@@ -205,7 +206,7 @@ public function searchExpression($expression, $type) { ...@@ -205,7 +206,7 @@ public function searchExpression($expression, $type) {
$this->addTag('search_' . $type); $this->addTag('search_' . $type);
// Initialize conditions and status. // Initialize conditions and status.
$this->conditions = db_and(); $this->conditions = new Condition('AND');
$this->status = 0; $this->status = 0;
return $this; return $this;
...@@ -313,7 +314,7 @@ protected function parseSearchExpression() { ...@@ -313,7 +314,7 @@ protected function parseSearchExpression() {
} }
$has_or = TRUE; $has_or = TRUE;
$has_new_scores = FALSE; $has_new_scores = FALSE;
$queryor = db_or(); $queryor = new Condition('OR');
foreach ($key as $or) { foreach ($key as $or) {
list($num_new_scores) = $this->parseWord($or); list($num_new_scores) = $this->parseWord($or);
$has_new_scores |= $num_new_scores; $has_new_scores |= $num_new_scores;
...@@ -401,7 +402,7 @@ public function prepareAndNormalize() { ...@@ -401,7 +402,7 @@ public function prepareAndNormalize() {
} }
// Build the basic search query: match the entered keywords. // Build the basic search query: match the entered keywords.
$or = db_or(); $or = new Condition('OR');
foreach ($this->words as $word) { foreach ($this->words as $word) {
$or->condition('i.word', $word); $or->condition('i.word', $word);
} }
......
...@@ -74,8 +74,8 @@ function conditionReplaceString($search, $replace, &$condition) { ...@@ -74,8 +74,8 @@ function conditionReplaceString($search, $replace, &$condition) {
$conditions =& $condition['field']->conditions(); $conditions =& $condition['field']->conditions();
foreach ($conditions as $key => &$subcondition) { foreach ($conditions as $key => &$subcondition) {
if (is_numeric($key)) { if (is_numeric($key)) {
// As conditions can have subconditions, for example db_or(), the // As conditions can be nested, the function has to be called
// function has to be called recursively. // recursively.
$this->conditionReplaceString($search, $replace, $subcondition); $this->conditionReplaceString($search, $replace, $subcondition);
} }
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\taxonomy\Plugin\views\argument; namespace Drupal\taxonomy\Plugin\views\argument;
use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
...@@ -106,7 +107,7 @@ public function query($group_by = FALSE) { ...@@ -106,7 +107,7 @@ public function query($group_by = FALSE) {
// Now build the subqueries. // Now build the subqueries.
$subquery = db_select('taxonomy_index', 'tn'); $subquery = db_select('taxonomy_index', 'tn');
$subquery->addField('tn', 'nid'); $subquery->addField('tn', 'nid');
$where = db_or()->condition('tn.tid', $tids, $operator); $where = (new Condition('OR'))->condition('tn.tid', $tids, $operator);
$last = "tn"; $last = "tn";
if ($this->options['depth'] > 0) { if ($this->options['depth'] > 0) {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\taxonomy\Plugin\views\filter; namespace Drupal\taxonomy\Plugin\views\filter;
use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
/** /**
...@@ -72,7 +73,7 @@ public function query() { ...@@ -72,7 +73,7 @@ public function query() {
// Now build the subqueries. // Now build the subqueries.
$subquery = db_select('taxonomy_index', 'tn'); $subquery = db_select('taxonomy_index', 'tn');
$subquery->addField('tn', 'nid'); $subquery->addField('tn', 'nid');
$where = db_or()->condition('tn.tid', $this->value, $operator); $where = (new Condition('OR'))->condition('tn.tid', $this->value, $operator);
$last = "tn"; $last = "tn";
if ($this->options['depth'] > 0) { if ($this->options['depth'] > 0) {
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Drupal\user\Plugin\EntityReferenceSelection; namespace Drupal\user\Plugin\EntityReferenceSelection;
use Drupal\Core\Database\Connection; use Drupal\Core\Database\Connection;
use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Database\Query\SelectInterface; use Drupal\Core\Database\Query\SelectInterface;
use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection; use Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection;
...@@ -228,17 +229,17 @@ public function entityQueryAlter(SelectInterface $query) { ...@@ -228,17 +229,17 @@ public function entityQueryAlter(SelectInterface $query) {
// Re-add the condition and a condition on uid = 0 so that we end up // Re-add the condition and a condition on uid = 0 so that we end up
// with a query in the form: // with a query in the form:
// WHERE (name LIKE :name) OR (:anonymous_name LIKE :name AND uid = 0) // WHERE (name LIKE :name) OR (:anonymous_name LIKE :name AND uid = 0)
$or = db_or(); $or = new Condition('OR');
$or->condition($condition['field'], $condition['value'], $condition['operator']); $or->condition($condition['field'], $condition['value'], $condition['operator']);
// Sadly, the Database layer doesn't allow us to build a condition // Sadly, the Database layer doesn't allow us to build a condition
// in the form ':placeholder = :placeholder2', because the 'field' // in the form ':placeholder = :placeholder2', because the 'field'
// part of a condition is always escaped. // part of a condition is always escaped.
// As a (cheap) workaround, we separately build a condition with no // As a (cheap) workaround, we separately build a condition with no
// field, and concatenate the field and the condition separately. // field, and concatenate the field and the condition separately.
$value_part = db_and(); $value_part = new Condition('AND');
$value_part->condition('anonymous_name', $condition['value'], $condition['operator']); $value_part->condition('anonymous_name', $condition['value'], $condition['operator']);
$value_part->compile($this->connection, $query); $value_part->compile($this->connection, $query);
$or->condition(db_and() $or->condition((new Condition('AND'))
->where(str_replace('anonymous_name', ':anonymous_name', (string) $value_part), $value_part->arguments() + array(':anonymous_name' => \Drupal::config('user.settings')->get('anonymous'))) ->where(str_replace('anonymous_name', ':anonymous_name', (string) $value_part), $value_part->arguments() + array(':anonymous_name' => \Drupal::config('user.settings')->get('anonymous')))
->condition('base_table.uid', 0) ->condition('base_table.uid', 0)
); );
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\user\Plugin\views\filter; namespace Drupal\user\Plugin\views\filter;
use Drupal\Core\Database\Query\Condition;
use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\ViewExecutable; use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\filter\BooleanOperator; use Drupal\views\Plugin\views\filter\BooleanOperator;
...@@ -28,7 +29,7 @@ public function query() { ...@@ -28,7 +29,7 @@ public function query() {
$this->ensureMyTable(); $this->ensureMyTable();
$field = $this->tableAlias . '.' . $this->realField . ' '; $field = $this->tableAlias . '.' . $this->realField . ' ';
$or = db_or(); $or = new Condition('OR');
if (empty($this->value)) { if (empty($this->value)) {
$or->condition($field, '***CURRENT_USER***', '<>'); $or->condition($field, '***CURRENT_USER***', '<>');
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\views; namespace Drupal\views;
use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\HandlerBase; use Drupal\views\Plugin\views\HandlerBase;
...@@ -268,8 +269,8 @@ public function addFilter() { ...@@ -268,8 +269,8 @@ public function addFilter() {
$options['group'] = 0; $options['group'] = 0;
} }
// add_condition determines whether a single expression is enough(FALSE) or the // If $add_condition is set to FALSE, a single expression is enough. If it
// conditions should be added via an db_or()/db_and() (TRUE). // is set to TRUE, conditions will be added.
$add_condition = TRUE; $add_condition = TRUE;
if ($operator == 'not') { if ($operator == 'not') {
$value = NULL; $value = NULL;
...@@ -326,7 +327,7 @@ public function addFilter() { ...@@ -326,7 +327,7 @@ public function addFilter() {
if ($add_condition) { if ($add_condition) {
$field = $this->handler->realField; $field = $this->handler->realField;
$clause = $operator == 'or' ? db_or() : db_and(); $clause = $operator == 'or' ? new Condition('OR') : new Condition('AND');
foreach ($this->handler->tableAliases as $value => $alias) { foreach ($this->handler->tableAliases as $value => $alias) {
$clause->condition("$alias.$field", $value); $clause->condition("$alias.$field", $value);
} }
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
namespace Drupal\views\Plugin\views\display; namespace Drupal\views\Plugin\views\display;
use Drupal\Core\Database\Query\Condition;
/** /**
* The plugin that handles an EntityReference display. * The plugin that handles an EntityReference display.
* *
...@@ -131,7 +133,7 @@ public function query() { ...@@ -131,7 +133,7 @@ public function query() {
} }
// Multiple search fields are OR'd together. // Multiple search fields are OR'd together.
$conditions = db_or(); $conditions = new Condition('OR');
// Build the condition using the selected search fields. // Build the condition using the selected search fields.
foreach ($style_options['options']['search_fields'] as $field_id) { foreach ($style_options['options']['search_fields'] as $field_id) {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\views\Plugin\views\filter; namespace Drupal\views\Plugin\views\filter;
use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
/** /**
...@@ -265,7 +266,7 @@ protected function opContains($field) { ...@@ -265,7 +266,7 @@ protected function opContains($field) {
} }
protected function opContainsWord($field) { protected function opContainsWord($field) {
$where = $this->operator == 'word' ? db_or() : db_and(); $where = $this->operator == 'word' ? new Condition('OR') : new Condition('AND');
// Don't filter on empty strings. // Don't filter on empty strings.
if (empty($this->value)) { if (empty($this->value)) {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
use Drupal\Component\Utility\NestedArray; use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\Cache;
use Drupal\Core\Database\Database; use Drupal\Core\Database\Database;
use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\display\DisplayPluginBase;
...@@ -830,7 +831,7 @@ public function clearFields() { ...@@ -830,7 +831,7 @@ public function clearFields() {
* @code * @code
* $this->query->addWhere( * $this->query->addWhere(
* $this->options['group'], * $this->options['group'],
* db_or() * (new Condition('OR'))
* ->condition($field, $value, 'NOT IN') * ->condition($field, $value, 'NOT IN')
* ->condition($field, $value, 'IS NULL') * ->condition($field, $value, 'IS NULL')
* ); * );
...@@ -1056,13 +1057,13 @@ protected function buildCondition($where = 'where') { ...@@ -1056,13 +1057,13 @@ protected function buildCondition($where = 'where') {
$has_arguments = FALSE; $has_arguments = FALSE;
$has_filter = FALSE; $has_filter = FALSE;
$main_group = db_and(); $main_group = new Condition('AND');
$filter_group = $this->groupOperator == 'OR' ? db_or() : db_and(); $filter_group = $this->groupOperator == 'OR' ? new Condition('OR') : new Condition('AND');
foreach ($this->$where as $group => $info) { foreach ($this->$where as $group => $info) {
if (!empty($info['conditions'])) { if (!empty($info['conditions'])) {
$sub_group = $info['type'] == 'OR' ? db_or() : db_and(); $sub_group = $info['type'] == 'OR' ? new Condition('OR') : new Condition('AND');
foreach ($info['conditions'] as $clause) { foreach ($info['conditions'] as $clause) {
if ($clause['operator'] == 'formula') { if ($clause['operator'] == 'formula') {
$has_condition = TRUE; $has_condition = TRUE;
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Drupal\KernelTests\Core\Database; namespace Drupal\KernelTests\Core\Database;
use Drupal\Core\Database\Database; use Drupal\Core\Database\Database;
use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Database\RowCountException; use Drupal\Core\Database\RowCountException;
use Drupal\user\Entity\User; use Drupal\user\Entity\User;
...@@ -312,7 +313,7 @@ function testNestedConditions() { ...@@ -312,7 +313,7 @@ function testNestedConditions() {
$query = db_select('test'); $query = db_select('test');
$query->addField('test', 'job'); $query->addField('test', 'job');
$query->condition('name', 'Paul'); $query->condition('name', 'Paul');
$query->condition(db_or()->condition('age', 26)->condition('age', 27)); $query->condition((new Condition('OR'))->condition('age', 26)->condition('age', 27));
$job = $query->execute()->fetchField(); $job = $query->execute()->fetchField();
$this->assertEqual($job, 'Songwriter', 'Correct data retrieved.'); $this->assertEqual($job, 'Songwriter', 'Correct data retrieved.');
...@@ -395,7 +396,7 @@ function testSelectWithRowCount() { ...@@ -395,7 +396,7 @@ function testSelectWithRowCount() {
public function testJoinConditionObject() { public function testJoinConditionObject() {
// Same test as testDefaultJoin, but with a Condition object. // Same test as testDefaultJoin, but with a Condition object.
$query = db_select('test_task', 't'); $query = db_select('test_task', 't');
$join_cond = db_and()->where('t.pid = p.id'); $join_cond = (new Condition('AND'))->where('t.pid = p.id');
$people_alias = $query->join('test', 'p', $join_cond); $people_alias = $query->join('test', 'p', $join_cond);
$name_field = $query->addField($people_alias, 'name', 'name'); $name_field = $query->addField($people_alias, 'name', 'name');
$query->addField('t', 'task', 'task'); $query->addField('t', 'task', 'task');
...@@ -418,7 +419,7 @@ public function testJoinConditionObject() { ...@@ -418,7 +419,7 @@ public function testJoinConditionObject() {
// Test a condition object that creates placeholders. // Test a condition object that creates placeholders.
$t1_name = 'John'; $t1_name = 'John';
$t2_name = 'George'; $t2_name = 'George';
$join_cond = db_and() $join_cond = (new Condition('AND'))
->condition('t1.name', $t1_name) ->condition('t1.name', $t1_name)
->condition('t2.name', $t2_name); ->condition('t2.name', $t2_name);
$query = db_select('test', 't1'); $query = db_select('test', 't1');
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
namespace Drupal\KernelTests\Core\Database; namespace Drupal\KernelTests\Core\Database;
use Drupal\Core\Database\Query\Condition;
/** /**
* Tests the Update query builder, complex queries. * Tests the Update query builder, complex queries.
* *
...@@ -15,7 +17,7 @@ class UpdateComplexTest extends DatabaseTestBase { ...@@ -15,7 +17,7 @@ class UpdateComplexTest extends DatabaseTestBase {
function testOrConditionUpdate() { function testOrConditionUpdate() {
$update = db_update('test') $update = db_update('test')
->fields(array('job' => 'Musician')) ->fields(array('job' => 'Musician'))
->condition(db_or() ->condition((new Condition('OR'))
->condition('name', 'John') ->condition('name', 'John')
->condition('name', 'Paul') ->condition('name', 'Paul')
); );
......
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