Unverified Commit f124d526 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3130655 by daffie, andypost, Beakerboy, ravi.shankar, alexpott,...

Issue #3130655 by daffie, andypost, Beakerboy, ravi.shankar, alexpott, mradcliffe, Lendude: Deprecate creating an instance of the class Drupal\Core\Database\Query\Condition with the new keyword
parent cf5d3de9
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -1171,7 +1171,10 @@ public function schema() {
   */
  public function condition($conjunction) {
    $class = $this->getDriverClass('Condition');
    return new $class($conjunction);
    // Creating an instance of the class Drupal\Core\Database\Query\Condition
    // should only be created from the database layer. This will allow database
    // drivers to override the default Condition class.
    return new $class($conjunction, FALSE);
  }

  /**
+12 −1
Original line number Diff line number Diff line
@@ -78,8 +78,19 @@ class Condition implements ConditionInterface, \Countable {
   *
   * @param string $conjunction
   *   The operator to use to combine conditions: 'AND' or 'OR'.
   * @param bool $trigger_deprecation
   *   If TRUE then trigger the deprecation warning.
   *
   * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Creating an
   *   instance of this class is deprecated.
   *
   * @see https://www.drupal.org/node/3159568
   */
  public function __construct($conjunction) {
  public function __construct($conjunction, $trigger_deprecation = TRUE) {
    if ($trigger_deprecation) {
      @trigger_error('Creating an instance of this class is deprecated in drupal:9.1.0 and is removed in drupal:10.0.0. Use Database::getConnection()->condition() instead. See https://www.drupal.org/node/3159568', E_USER_DEPRECATED);
    }

    $this->conditions['#conjunction'] = $conjunction;
  }

+10 −0
Original line number Diff line number Diff line
@@ -179,4 +179,14 @@ public function &getComments() {
    return $this->comments;
  }

  /**
   * Gets the database connection to be used for the query.
   *
   * @return \Drupal\Core\Database\Connection
   *   The database connection to be used for the query.
   */
  public function getConnection() {
    return $this->connection;
  }

}
+1 −2
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@
namespace Drupal\Core\Entity\Query\Sql;

use Drupal\Core\Database\Query\SelectInterface;
use Drupal\Core\Database\Query\Condition as SqlCondition;
use Drupal\Core\Entity\Query\ConditionBase;
use Drupal\Core\Entity\Query\ConditionInterface;

@@ -40,7 +39,7 @@ public function compile($conditionContainer) {
    $tables = $this->query->getTables($sql_query);
    foreach ($this->conditions as $condition) {
      if ($condition['field'] instanceof ConditionInterface) {
        $sql_condition = new SqlCondition($condition['field']->getConjunction());
        $sql_condition = $sql_query->getConnection()->condition($condition['field']->getConjunction());
        // Add the SQL query to the object before calling this method again.
        $sql_condition->sqlQuery = $sql_query;
        $condition['field']->nestedInsideOrCondition = $this->nestedInsideOrCondition || strtoupper($this->conjunction) === 'OR';
+1 −2
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@
use Drupal\Core\Database\Query\SelectInterface;
use Drupal\Core\Entity\Query\ConditionAggregateBase;
use Drupal\Core\Entity\Query\ConditionAggregateInterface;
use Drupal\Core\Database\Query\Condition as SqlCondition;
use Drupal\Core\Entity\Query\QueryBase;

/**
@@ -26,7 +25,7 @@ public function compile($conditionContainer) {
    $tables = new Tables($sql_query);
    foreach ($this->conditions as $condition) {
      if ($condition['field'] instanceof ConditionAggregateInterface) {
        $sql_condition = new SqlCondition($condition['field']->getConjunction());
        $sql_condition = $sql_query->getConnection()->condition($condition['field']->getConjunction());
        // Add the SQL query to the object before calling this method again.
        $sql_condition->sqlQuery = $sql_query;
        $condition['field']->compile($sql_condition);
Loading