function drush_sql_expand_wildcard_tables

8.0.x sql.drush.inc drush_sql_expand_wildcard_tables($tables, $db_tables)
6.x sql.drush.inc drush_sql_expand_wildcard_tables($tables, $db_tables)
7.x sql.drush.inc drush_sql_expand_wildcard_tables($tables, $db_tables)
master sql.drush.inc drush_sql_expand_wildcard_tables($tables, $db_tables)

Expand wildcard tables.

Parameters

array $tables: An array of table names, some of which may contain wildcards (`*`).

array $db_tables: An array with all the existing table names in the current database.

Return value

$tables array with wildcards resolved to real table names.

2 calls to drush_sql_expand_wildcard_tables()
WildcardUnitCase::testExpandWildcardTables in tests/expandWildcardTablesUnitTest.php
Tests drush_sql_expand_wildcard_tables().
_drush_sql_expand_and_filter_tables in commands/sql/sql.drush.inc
Given the table names in the input array that may contain wildcards (`*`), expand the table names so that the array returned only contains table names that exist in the database.

File

commands/sql/sql.drush.inc, line 303
Drush sql commands

Code

function drush_sql_expand_wildcard_tables($tables, $db_tables) {
  // Table name expansion based on `*` wildcard.
  $expanded_db_tables = array();
  foreach ($tables as $k => $table) {
    // Only deal with table names containing a wildcard.
    if (strpos($table, '*') !== FALSE) {
      $pattern = '/^' . str_replace('*', '.*', $table) . '$/i';
      // Merge those existing tables which match the pattern with the rest of
      // the expanded table names.
      $expanded_db_tables += preg_grep($pattern, $db_tables);
    }
  }
  return $expanded_db_tables;
}