You are here

function demo_enum_tables in Demonstration site (Sandbox / Snapshot) 7

Same name and namespace in other branches
  1. 8 demo.module \demo_enum_tables()
  2. 5 demo.admin.inc \demo_enum_tables()
  3. 6 demo.admin.inc \demo_enum_tables()

Returns a list of tables in the active database.

Only returns tables whose prefix matches the configured one (or ones, if there are multiple).

2 calls to demo_enum_tables()
demo_dump_form in ./demo.admin.inc
Form builder to create a new snapshot.
_demo_reset in ./demo.admin.inc
Reset site using snapshot.

File

./demo.admin.inc, line 608
Demonstration Site administrative pages.

Code

function demo_enum_tables() {
  $tables = array();

  // Load database specific functions.
  if (!demo_load_include()) {
    return FALSE;
  }
  $connection = Database::getConnection();
  $db_options = $connection
    ->getConnectionOptions();

  // Create a regex that matches the table prefix(es).
  // We are only interested in non-empty table prefixes.
  $prefixes = array();
  if (!empty($db_options['prefix'])) {
    if (is_array($db_options['prefix'])) {
      $prefixes = array_filter($db_options['prefix']);
    }
    elseif ($db_options['prefix'] != '') {
      $prefixes['default'] = $db_options['prefix'];
    }
    $rx = '/^' . implode('|', $prefixes) . '/';
  }

  // Query the database engine for the table list.
  $result = _demo_enum_tables();
  foreach ($result as $table) {
    if (!empty($prefixes)) {

      // Check if table name matches a configured prefix.
      if (preg_match($rx, $table, $matches)) {
        $table_prefix = $matches[0];
        $plain_table = substr($table, strlen($table_prefix));
        if (isset($prefixes[$plain_table]) && $prefixes[$plain_table] == $table_prefix || $prefixes['default'] == $table_prefix) {
          $tables[$table] = array(
            'schema' => TRUE,
            'data' => TRUE,
          );
        }
      }
    }
    else {
      $tables[$table] = array(
        'schema' => TRUE,
        'data' => TRUE,
      );
    }
  }

  // Apply default exclude list.
  $excludes = array(
    // Drupal core.
    '{cache}',
    '{cache_bootstrap}',
    '{cache_block}',
    '{cache_content}',
    '{cache_field}',
    '{cache_filter}',
    '{cache_form}',
    '{cache_menu}',
    '{cache_page}',
    '{cache_path}',
    '{cache_update}',
    '{watchdog}',
    // CTools.
    '{ctools_object_cache}',
    // Administration menu.
    '{cache_admin_menu}',
    // Panels.
    '{panels_object_cache}',
    // Views.
    '{cache_views}',
    '{cache_views_data}',
    '{views_object_cache}',
  );
  foreach (array_map(array(
    $connection,
    'prefixTables',
  ), $excludes) as $table) {
    if (isset($tables[$table])) {
      $tables[$table]['data'] = FALSE;
    }
  }
  return $tables;
}