Issue #3216552 by andypost, mondrake, Gauravmahlawat, daffie, joachim: Incorrect calls to Connection::select() in MenuTreeStorage

merge-requests/791/head
catch 2021-06-14 11:24:17 +01:00
parent 70175bc047
commit 6b94f7d8f4
2 changed files with 18 additions and 15 deletions

View File

@ -1146,6 +1146,9 @@ abstract class Connection {
* @see \Drupal\Core\Database\Query\Select
*/
public function select($table, $alias = NULL, array $options = []) {
if (!is_null($alias) && !is_string($alias)) {
@trigger_error('Passing a non-string \'alias\' argument to ' . __METHOD__ . '() is deprecated in drupal:9.3.0 and will be required in drupal:10.0.0. Refactor your calling code. See https://www.drupal.org/project/drupal/issues/3216552', E_USER_DEPRECATED);
}
$class = $this->getDriverClass('Select');
return new $class($this, $table, $alias, $options);
}

View File

@ -288,7 +288,7 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
// self::loadFull() to avoid the unserialization of fields with 'serialize'
// equal to TRUE as defined in self::schemaDefinition(). The makes $original
// easier to compare with the return value of self::preSave().
$query = $this->connection->select($this->table, $this->options);
$query = $this->connection->select($this->table, NULL, $this->options);
$query->fields($this->table);
$query->condition('id', $link['id']);
$original = $this->safeExecuteSelect($query)->fetchAssoc();
@ -451,7 +451,7 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
* Returns the relative depth.
*/
protected function doFindChildrenRelativeDepth(array $original) {
$query = $this->connection->select($this->table, $this->options);
$query = $this->connection->select($this->table, NULL, $this->options);
$query->addField($this->table, 'depth');
$query->condition('menu_name', $original['menu_name']);
$query->orderBy('depth', 'DESC');
@ -614,7 +614,7 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
// If parent is empty, there is nothing to update.
if (!empty($link['parent'])) {
// Check if at least one visible child exists in the table.
$query = $this->connection->select($this->table, $this->options);
$query = $this->connection->select($this->table, NULL, $this->options);
$query->addExpression('1');
$query->range(0, 1);
$query
@ -658,7 +658,7 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
* {@inheritdoc}
*/
public function loadByProperties(array $properties) {
$query = $this->connection->select($this->table, $this->options);
$query = $this->connection->select($this->table, NULL, $this->options);
$query->fields($this->table, $this->definitionFields());
foreach ($properties as $name => $value) {
if (!in_array($name, $this->definitionFields(), TRUE)) {
@ -685,7 +685,7 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
// @todo Standardize an efficient way to load by route name and parameters
// in place of system path. https://www.drupal.org/node/2302139
$param_key = $route_parameters ? UrlHelper::buildQuery($route_parameters) : '';
$query = $this->connection->select($this->table, $this->options);
$query = $this->connection->select($this->table, NULL, $this->options);
$query->fields($this->table, $this->definitionFields());
$query->condition('route_name', $route_name);
$query->condition('route_param_key', $param_key);
@ -710,7 +710,7 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
$missing_ids = array_diff($ids, array_keys($this->definitions));
if ($missing_ids) {
$query = $this->connection->select($this->table, $this->options);
$query = $this->connection->select($this->table, NULL, $this->options);
$query->fields($this->table, $this->definitionFields());
$query->condition('id', $missing_ids, 'IN');
$loaded = $this->safeExecuteSelect($query)->fetchAllAssoc('id', \PDO::FETCH_ASSOC);
@ -756,7 +756,7 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
* The loaded menu link definitions.
*/
protected function loadFullMultiple(array $ids) {
$query = $this->connection->select($this->table, $this->options);
$query = $this->connection->select($this->table, NULL, $this->options);
$query->fields($this->table);
$query->condition('id', $ids, 'IN');
$loaded = $this->safeExecuteSelect($query)->fetchAllAssoc('id', \PDO::FETCH_ASSOC);
@ -774,7 +774,7 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
* {@inheritdoc}
*/
public function getRootPathIds($id) {
$subquery = $this->connection->select($this->table, $this->options);
$subquery = $this->connection->select($this->table, NULL, $this->options);
// @todo Consider making this dynamic based on static::MAX_DEPTH or from the
// schema if that is generated using static::MAX_DEPTH.
// https://www.drupal.org/node/2302043
@ -783,7 +783,7 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
$result = current($subquery->execute()->fetchAll(\PDO::FETCH_ASSOC));
$ids = array_filter($result);
if ($ids) {
$query = $this->connection->select($this->table, $this->options);
$query = $this->connection->select($this->table, NULL, $this->options);
$query->fields($this->table, ['id']);
$query->orderBy('depth', 'DESC');
$query->condition('mlid', $ids, 'IN');
@ -801,7 +801,7 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
// @todo Go back to tracking in state or some other way which menus have
// expanded links? https://www.drupal.org/node/2302187
do {
$query = $this->connection->select($this->table, $this->options);
$query = $this->connection->select($this->table, NULL, $this->options);
$query->fields($this->table, ['id']);
$query->condition('menu_name', $menu_name);
$query->condition('expanded', 1);
@ -883,7 +883,7 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
* depth-first.
*/
protected function loadLinks($menu_name, MenuTreeParameters $parameters) {
$query = $this->connection->select($this->table, $this->options);
$query = $this->connection->select($this->table, NULL, $this->options);
$query->fields($this->table);
// Allow a custom root to be specified for loading a menu link tree. If
@ -1030,7 +1030,7 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
* {@inheritdoc}
*/
public function menuNameInUse($menu_name) {
$query = $this->connection->select($this->table, $this->options);
$query = $this->connection->select($this->table, NULL, $this->options);
$query->addField($this->table, 'mlid');
$query->condition('menu_name', $menu_name);
$query->range(0, 1);
@ -1041,7 +1041,7 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
* {@inheritdoc}
*/
public function getMenuNames() {
$query = $this->connection->select($this->table, $this->options);
$query = $this->connection->select($this->table, NULL, $this->options);
$query->addField($this->table, 'menu_name');
$query->distinct();
return $this->safeExecuteSelect($query)->fetchAllKeyed(0, 0);
@ -1051,7 +1051,7 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
* {@inheritdoc}
*/
public function countMenuLinks($menu_name = NULL) {
$query = $this->connection->select($this->table, $this->options);
$query = $this->connection->select($this->table, NULL, $this->options);
if ($menu_name) {
$query->condition('menu_name', $menu_name);
}
@ -1066,7 +1066,7 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
if (!$root) {
return [];
}
$query = $this->connection->select($this->table, $this->options);
$query = $this->connection->select($this->table, NULL, $this->options);
$query->fields($this->table, ['id']);
$query->condition('menu_name', $root['menu_name']);
for ($i = 1; $i <= $root['depth']; $i++) {