Projet

Général

Profil

Révision 01dfd3b5

Ajouté par Assos Assos il y a plus de 3 ans

Udpate to 7.77

Voir les différences:

drupal7/includes/database/schema.inc
169 169
 */
170 170
abstract class DatabaseSchema implements QueryPlaceholderInterface {
171 171

  
172
  /**
173
   * The database connection.
174
   *
175
   * @var DatabaseConnection
176
   */
172 177
  protected $connection;
173 178

  
174 179
  /**
......
343 348
    // couldn't use db_select() here because it would prefix
344 349
    // information_schema.tables and the query would fail.
345 350
    // Don't use {} around information_schema.tables table.
346
    return $this->connection->query("SELECT table_name FROM information_schema.tables WHERE " . (string) $condition, $condition->arguments())->fetchAllKeyed(0, 0);
351
    return $this->connection->query("SELECT table_name AS table_name FROM information_schema.tables WHERE " . (string) $condition, $condition->arguments())->fetchAllKeyed(0, 0);
352
  }
353

  
354
  /**
355
   * Finds all tables that are like the specified base table name. This is a
356
   * backport of the change made to findTables in Drupal 8 to work with virtual,
357
   * un-prefixed table names. The original function is retained for Backwards
358
   * Compatibility.
359
   * @see https://www.drupal.org/node/2552435
360
   *
361
   * @param string $table_expression
362
   *   An SQL expression, for example "cache_%" (without the quotes).
363
   *
364
   * @return array
365
   *   Both the keys and the values are the matching tables.
366
   */
367
  public function findTablesD8($table_expression) {
368
    // Load all the tables up front in order to take into account per-table
369
    // prefixes. The actual matching is done at the bottom of the method.
370
    $condition = $this->buildTableNameCondition('%', 'LIKE');
371
    $condition->compile($this->connection, $this);
372

  
373
    $individually_prefixed_tables = $this->connection->getUnprefixedTablesMap();
374
    $default_prefix = $this->connection->tablePrefix();
375
    $default_prefix_length = strlen($default_prefix);
376
    $tables = array();
377
    // Normally, we would heartily discourage the use of string
378
    // concatenation for conditionals like this however, we
379
    // couldn't use db_select() here because it would prefix
380
    // information_schema.tables and the query would fail.
381
    // Don't use {} around information_schema.tables table.
382
    $results = $this->connection->query("SELECT table_name AS table_name FROM information_schema.tables WHERE " . (string) $condition, $condition->arguments());
383
    foreach ($results as $table) {
384
      // Take into account tables that have an individual prefix.
385
      if (isset($individually_prefixed_tables[$table->table_name])) {
386
        $prefix_length = strlen($this->connection->tablePrefix($individually_prefixed_tables[$table->table_name]));
387
      }
388
      elseif ($default_prefix && substr($table->table_name, 0, $default_prefix_length) !== $default_prefix) {
389
        // This table name does not start the default prefix, which means that
390
        // it is not managed by Drupal so it should be excluded from the result.
391
        continue;
392
      }
393
      else {
394
        $prefix_length = $default_prefix_length;
395
      }
396

  
397
      // Remove the prefix from the returned tables.
398
      $unprefixed_table_name = substr($table->table_name, $prefix_length);
399

  
400
      // The pattern can match a table which is the same as the prefix. That
401
      // will become an empty string when we remove the prefix, which will
402
      // probably surprise the caller, besides not being a prefixed table. So
403
      // remove it.
404
      if (!empty($unprefixed_table_name)) {
405
        $tables[$unprefixed_table_name] = $unprefixed_table_name;
406
      }
407
    }
408

  
409
    // Convert the table expression from its SQL LIKE syntax to a regular
410
    // expression and escape the delimiter that will be used for matching.
411
    $table_expression = str_replace(array('%', '_'), array('.*?', '.'), preg_quote($table_expression, '/'));
412
    $tables = preg_grep('/^' . $table_expression . '$/i', $tables);
413

  
414
    return $tables;
347 415
  }
348 416

  
349 417
  /**

Formats disponibles : Unified diff