You are here

function demo_enum_tables in Demonstration site (Sandbox / Snapshot) 6

Same name and namespace in other branches
  1. 8 demo.module \demo_enum_tables()
  2. 5 demo.admin.inc \demo_enum_tables()
  3. 7 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).

3 calls to demo_enum_tables()
demo_drush_create_snapshot in ./demo.drush.inc
Callback for drush command demo-create.
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 522
Demonstration Site administrative pages

Code

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

  // Load database specific functions.
  if (!demo_load_include()) {
    return FALSE;
  }

  // Create a regex that matches the table prefix(es).
  if (is_array($db_prefix)) {
    $rx = '/^' . implode('|', array_filter($db_prefix)) . '/';
  }
  else {
    if ($db_prefix != '') {
      $rx = '/^' . $db_prefix . '/';
    }
  }

  // Query the database engine for the table list.
  $result = _demo_enum_tables();
  while ($table = db_fetch_array($result)) {
    $table = reset($table);
    if (is_array($db_prefix)) {

      // 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 ($db_prefix[$plain_table] == $table_prefix || $db_prefix['default'] == $table_prefix) {
          $tables[$table] = array(
            'schema' => TRUE,
            'data' => TRUE,
          );
        }
      }
    }
    else {
      if ($db_prefix != '') {
        if (preg_match($rx, $table)) {
          $tables[$table] = array(
            'schema' => TRUE,
            'data' => TRUE,
          );
        }
      }
      else {
        $tables[$table] = array(
          'schema' => TRUE,
          'data' => TRUE,
        );
      }
    }
  }

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