summaryrefslogtreecommitdiffstats
path: root/migrate.module
diff options
context:
space:
mode:
authorMike Ryan2010-01-03 22:31:55 +0000
committerMike Ryan2010-01-03 22:31:55 +0000
commita504bdebc47ec95d7ab382b3fcc45a6d45a706b9 (patch)
tree35912005d9375fb3d0bf0b468404cdd1c834a9bd /migrate.module
parent5dfee0436fbedd2a50b6cdc8623cd469d88447cb (diff)
#661934 by frankcarey, mikeryan: Support for external tables using views/tw dbname.tablename support
Diffstat (limited to 'migrate.module')
-rwxr-xr-xmigrate.module51
1 files changed, 40 insertions, 11 deletions
diff --git a/migrate.module b/migrate.module
index 1b1b8a1..a1c2a11 100755
--- a/migrate.module
+++ b/migrate.module
@@ -172,10 +172,7 @@ function migrate_save_content_set(&$content_set, $options = array()) {
$tablename = $view->base_table;
}
- db_set_active($tabledb);
- $inspect = schema_invoke('inspect');
- db_set_active('default');
- $sourceschema = $inspect[$tablename];
+ $sourceschema = _migrate_inspect_schema($tablename, $tabledb);
// If the PK of the content set is defined, make sure we have a mapping table
if (isset($content_set->sourcekey) && $content_set->sourcekey) {
@@ -1123,7 +1120,6 @@ function migrate_schema_alter(&$schema) {
// before our install hook.
if (db_table_exists('migrate_content_sets')) {
$result = db_query("SELECT * FROM {migrate_content_sets}");
- static $inspect = array();
while ($content_set = db_fetch_object($result)) {
$maptablename = migrate_map_table_name($content_set->mcsid);
$msgtablename = migrate_message_table_name($content_set->mcsid);
@@ -1146,12 +1142,7 @@ function migrate_schema_alter(&$schema) {
$tabledb = 'default';
}
$tablename = $view->base_table;
- if (!isset($inspect[$tabledb])) {
- db_set_active($tabledb);
- $inspect[$tabledb] = schema_invoke('inspect');
- db_set_active('default');
- }
- $sourceschema = $inspect[$tabledb][$tablename];
+ $sourceschema = _migrate_inspect_schema($tablename, $tabledb);
// If the PK of the content set is defined, make sure we have a mapping table
$sourcekey = $content_set->sourcekey;
if ($sourcekey) {
@@ -1434,6 +1425,9 @@ function _migrate_get_view_count($view, $args = NULL) {
return $view->total_rows;
}
+/**
+ * Get the PHP memory_limit value in bytes
+ */
function _migrate_memory_limit() {
$value = trim(ini_get('memory_limit'));
$last = strtolower($value[strlen($value)-1]);
@@ -1448,3 +1442,38 @@ function _migrate_memory_limit() {
return $value;
}
+
+/**
+ * Wrapper around schema_invoke('inspect'), to handle views tablenames
+ * hacked to include "dbname.".
+ */
+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 (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];
+}