You are here

function _migrate_inspect_schema in Migrate 6

Wrapper around schema_invoke('inspect'), to handle views tablenames hacked to include "dbname.".

2 calls to _migrate_inspect_schema()
migrate_save_content_set in ./migrate.module
Save a new or updated content set
migrate_schema_alter in ./migrate.module
Implementation of hook_schema_alter().

File

./migrate.module, line 1653
This module provides tools at "administer >> content >> migrate" for analyzing data from various sources and importing them into Drupal tables.

Code

function _migrate_inspect_schema($tablename = '', $tabledb = 'default') {
  static $inspect = array();

  // TW can treat external MySQL tables as internal, but we can revert
  // if we find a period in the tablename. Todo: might be better to build
  // this check direcly into schema_mysql.inc
  if (module_exists('tw') && strpos($tablename, '.')) {
    list($tabledb, $tablename) = explode('.', $tablename);
    $dbinfo = tw_get_dbinfo();
    foreach ($dbinfo as $dbkey => $db_detail) {
      if ($db_detail['name'] == $tabledb) {
        $tabledb = $dbkey;
        break;
      }
    }
  }
  if (!isset($inspect[$tabledb])) {
    db_set_active($tabledb);

    // TODO: schema_mysql_inspect($name = NULL) takes $name [tablename] which
    // limits the query to only get that table, which is probably a good idea.
    $inspect[$tabledb] = schema_invoke('inspect');
    db_set_active('default');
  }

  // If a tablename was not given, return the whole schema
  if ($tablename == '') {
    return $inspect[$tabledb];
  }

  // Return the schema for just this table.
  return $inspect[$tabledb][$tablename];
}