diff options
Diffstat (limited to 'migrate_database.php')
| -rwxr-xr-x[-rw-r--r--] | migrate_database.php | 145 |
1 files changed, 72 insertions, 73 deletions
diff --git a/migrate_database.php b/migrate_database.php index e2348aa..b03f176 100644..100755 --- a/migrate_database.php +++ b/migrate_database.php @@ -11,9 +11,11 @@ /** * Initialization */ +namespace Bitweaver; + $gBitSmarty->assign( 'next_step', $step ); -require_once( 'includes/install_inc.php' ); -require_once( 'includes/get_databases_inc.php' ); +require_once 'includes/install_inc.php'; +require_once 'includes/get_databases_inc.php'; // set the maximum execution time to very high ini_set( "max_execution_time", "86400" ); @@ -35,7 +37,7 @@ if( isset( $_REQUEST['db_src'] ) ) { $gBitSmarty->assign( 'name_dst', $_REQUEST['name_dst'] ); $gBitSmarty->assign( 'prefix_dst', $_REQUEST['prefix_dst'] ); - $skip_tables = isset($_REQUEST['skip_tables']) ? $_REQUEST['skip_tables'] : array(); + $skip_tables = isset($_REQUEST['skip_tables']) ? $_REQUEST['skip_tables'] : []; $gBitSmarty->assign( 'skip_tables_select', $skip_tables ); $empty_tables = isset($_REQUEST['empty_tables']); $gBitSmarty->assign( 'empty_tables', $empty_tables ); @@ -47,8 +49,8 @@ if( isset( $_REQUEST['db_src'] ) ) { $gBitSmarty->assign( 'debug', $debug ); } else { //defaults - $gBitSmarty->assign( 'convert_blobs', TRUE ); - $gBitSmarty->assign( 'stop_on_errors', TRUE ); + $gBitSmarty->assign( 'convert_blobs', true ); + $gBitSmarty->assign( 'stop_on_errors', true ); } if (isset($_REQUEST['fSubmitDatabase']) || isset($_REQUEST['fUpdateTables'])) { @@ -62,7 +64,7 @@ if (isset($_REQUEST['fSubmitDatabase']) || isset($_REQUEST['fUpdateTables'])) { $gBitDbName = $_REQUEST['name_src']; $prefix_src = $_REQUEST['prefix_src']; if (testDatabase()) { - $gBitSmarty->assign( 'error_src', TRUE ); + $gBitSmarty->assign( 'error_src', true ); return; } else { $gDb_src = new BitDb(); @@ -71,7 +73,7 @@ if (isset($_REQUEST['fSubmitDatabase']) || isset($_REQUEST['fUpdateTables'])) { $tables_src = $gDb_src->MetaTables(); if (isset($_REQUEST['fUpdateTables'])) { - $gBitSmarty->assignByRef( 'skip_tables', $tables_src ); + $gBitSmarty->assign( 'skip_tables', $tables_src ); return; } @@ -83,44 +85,45 @@ if (isset($_REQUEST['fSubmitDatabase']) || isset($_REQUEST['fUpdateTables'])) { $gBitDbName = $_REQUEST['name_dst']; $prefix_dst = $_REQUEST['prefix_dst']; if (testDatabase()) { - $gBitSmarty->assign( 'error_dst', TRUE ); + $gBitSmarty->assign( 'error_dst', true ); return; } else { $gDb_dst = new BitDb(); } - require_once( 'create_config_inc.php' ); - $createHash = array( - "gBitDbType" => $_REQUEST['db_dst'], - "gBitDbHost" => $tmpHost, - "gBitDbUser" => $_REQUEST['user_dst'], - "gBitDbPassword" => $_REQUEST['pass_dst'], - "gBitDbName" => $_REQUEST['name_dst'], + require_once 'create_config_inc.php'; + $createHash = [ + "gBitDbType" => $_REQUEST['db_dst'], + "gBitDbHost" => $tmpHost, + "gBitDbUser" => $_REQUEST['user_dst'], + "gBitDbPassword" => $_REQUEST['pass_dst'], + "gBitDbName" => $_REQUEST['name_dst'], //"gBitDbCaseSensitivity" => $_REQUEST['dbcase'], - "bit_db_prefix" => $_REQUEST['prefix_dst'], - "bit_root_url" => $_REQUEST['baseurl'], - "auto_bug_submit" => isset( $_REQUEST['auto_bug_submit'] ) ? 'TRUE' : 'FALSE', - "is_live" => isset( $_REQUEST['is_live'] ) ? 'TRUE' : 'FALSE', - ); + "bit_db_prefix" => $_REQUEST['prefix_dst'], + "bit_root_url" => $_REQUEST['baseurl'], + "auto_bug_submit" => isset( $_REQUEST['auto_bug_submit'] ) ? 'true' : 'false', + "is_live" => isset( $_REQUEST['is_live'] ) ? 'true' : 'false', + ]; create_config( $createHash ); // init db connections //vd($gDb_src); //vd($gDb_dst);die; - if($debug) { + if ($debug) { $gDb_dst->debug(); } // list source tables list - $tables_src = array($tables_src[2]); - $tables_dst = getTables($gDb_dst); - print_r($tables_src);die; + $tables_src = [ $tables_src[2] ]; + $tables_dst = $gDb_dst->MetaTables( ); + print_r( $tables_src ); + die; - $table_schema = array(); + $table_schema = []; // iterate through source tables - foreach($tables_src as $table) { - if (array_search($table, $skip_tables) !== FALSE) { + foreach ( $tables_src as $table ) { + if (array_search( $table, $skip_tables ) !== false) { if ($debug) echo "Skipping $table<br>\n"; continue; @@ -128,46 +131,46 @@ if (isset($_REQUEST['fSubmitDatabase']) || isset($_REQUEST['fUpdateTables'])) { if ($debug) echo "Creating $table<br>\n"; - if ($empty_tables && $gDb_dst->tableExists($table)) - $gDb_dst->dropTables(array($table)); + if ($empty_tables && $gDb_dst->tableExists( $table )) + $gDb_dst->dropTables( [ $table ] ); $schema = $gDb_src->MetaColumns( $table, false, true ); $t = ""; $first = true; - foreach(array_keys($schema) as $col) { - $t .= (!$first) ? ",\n" : ""; + foreach ( array_keys( $schema ) as $col ) { + $t .= ( !$first ) ? ",\n" : ""; $x = $schema[$col]; $t .= $x->name . " "; - switch($x->type) { + switch ($x->type) { case "tinyint": case "int": - $i = abs(( ( (int)$x->max_length ^ 2) - 1 )); - $i = ($i == 5) ? 4 : $i; - $i = ($i == 0) ? 1 : $i; + $i = abs( ( (int) $x->max_length ^ 2 ) - 1 ); + $i = ( $i == 5 ) ? 4 : $i; + $i = ( $i == 0 ) ? 1 : $i; $t .= "I" . $i; break; case "double": $t .= "N"; break; - + case "varchar": case "char": case "enum": case "decimal": $t .= "C(" . $x->max_length . ")"; break; - + case "time": case "timestamp": case "datetime": $t .= "T"; break; - + case "date": $t .= "D"; break; - + case "blob": case "longblob": case "tinyblob": @@ -178,14 +181,14 @@ if (isset($_REQUEST['fSubmitDatabase']) || isset($_REQUEST['fUpdateTables'])) { $t .= "X"; break; default: - die(tra("No support for type '".$x->type."' - please log a bug at http://sf.net/projects/bitweaver")); + die( KernelTools::tra( "No support for type '" . $x->type . "' - please log a bug at http://sf.net/projects/bitweaver" ) ); } - $default = (!$x->binary) ? $x->has_default : false; - $t .= " " . ( ($x->unsigned) ? "UNSIGNED" : "" ) . " " - . ( ($x->not_null) ? "NOTNULL" : "" ) . " " - . ( ($x->auto_increment) ? "AUTO" : "" ) . " " - . ( ($x->primary_key) ? "PRIMARY" : "" ) . " " - . ( ($default) ? "DEFAULT ". $x->default_value : "" ); + $default = ( !$x->binary ) ? $x->has_default : false; + $t .= " " . ( $x->unsigned ? "UNSIGNED" : "" ) . " " + . ( $x->not_null ? "NOTNULL" : "" ) . " " + . ( $x->auto_increment ? "AUTO" : "" ) . " " + . ( $x->primary_key ? "PRIMARY" : "" ) . " " + . ( $default ? "DEFAULT " . $x->default_value : "" ); $table_schema[$table] = $t; $first = false; } @@ -195,43 +198,40 @@ if (isset($_REQUEST['fSubmitDatabase']) || isset($_REQUEST['fUpdateTables'])) { //vd($table_schema); //vd($indices); - $pOptions = array(); + $pOptions = []; if ($empty_tables) $pOptions[] = "REPLACE"; switch ($gDb_dst->mType) { case "mysql": - // SHOULD HANDLE INNODB so foreign keys are cool - XOXO spiderr - $pOptions['mysql'] = 'TYPE=INNODB'; + // SHOULD HANDLE INNODB so foreign keys are cool - XOXO spiderr + $pOptions['mysql'] = 'TYPE=INNODB'; default: //$pOptions[] = 'REPLACE'; } - $dict = NewDataDictionary($gDb_dst->mDb); + $dict = NewDataDictionary( $gDb_dst->mDb, 'firebird' ); $result = true; - foreach(array_keys($table_schema) AS $tableName) - { - $completeTableName = $prefix_dst.$tableName; - $sql = $dict->CreateTableSQL($completeTableName, $table_schema[$tableName], $pOptions); - if ($sql && ($dict->ExecuteSQLArray($sql) > 0)) - { + foreach ( array_keys( $table_schema ) as $tableName ) { + $completeTableName = $prefix_dst . $tableName; + $sql = $dict->CreateTableSQL( $completeTableName, $table_schema[$tableName], $pOptions ); + if ($sql && ( $dict->ExecuteSQLArray( $sql ) > 0 )) { // Success } - else - { + else { // Failure - array_push($gDb_dst->mFailed, $gDb_dst->mDb->ErrorMsg()); + array_push( $gDb_dst->mFailed, $gDb_dst->mDb->ErrorMsg() ); if ($stop_on_errors) break; } - foreach( array_keys( $indices ) as $index ) { - foreach( array_keys( $indices[$index] ) as $col) { - $completeTableName = $prefix_dst.$index; - $flds = implode(",", $indices[$index][$col]["columns"]); - $name = implode("_", $indices[$index][$col]["columns"]); - $sql = $dict->CreateIndexSQL( $index."_".$name, $completeTableName, $flds, (($indices[$index][$col]["unique"]) ? array("UNIQUE") : NULL) ); - if( $sql && ($dict->ExecuteSQLArray($sql) > 0)) + foreach ( array_keys( $indices ) as $index ) { + foreach ( array_keys( $indices[$index] ) as $col ) { + $completeTableName = $prefix_dst . $index; + $flds = implode( ",", $indices[$index][$col]["columns"] ); + $name = implode( "_", $indices[$index][$col]["columns"] ); + $sql = $dict->CreateIndexSQL( "{$index}_$name", $completeTableName, $flds, ( $indices[$index][$col]["unique"] ) ? [ "UNIQUE" ] : null ); + if ($sql && ($dict->ExecuteSQLArray($sql) > 0)) { // Success } else { @@ -279,8 +279,8 @@ if (isset($_REQUEST['fSubmitDatabase']) || isset($_REQUEST['fUpdateTables'])) { $results[]= "$table: migrated $q records".(($c > 0) ? "and converted $c blobs" : ""); } //vd($gDb_dst->mFailed);die; - $gBitSmarty->assignByRef( 'results', $results ); - $gBitSmarty->assignByRef( 'errors', $gDb_dst->mFailed ); + $gBitSmarty->assign( 'results', $results ); + $gBitSmarty->assign( 'errors', $gDb_dst->mFailed ); $app = "_done"; $gBitSmarty->assign( 'next_step', $step + 1 ); @@ -293,12 +293,11 @@ function testDatabase() { ini_set('sybct.min_server_severity', '11'); } - $gBitDb = &ADONewConnection($gBitDbType); + $gBitDb = ADONewConnection($gBitDbType); - if( !$gBitDb->Connect($gBitDbHost, $gBitDbUser, $gBitDbPassword, $gBitDbName) ) { - return TRUE; + if( !$gBitDb->Connect($gBitDbHost, $gBitDbUser, $gBitDbPassword, $gBitDbType != 'pdo' ? $gBitDbName : NULL ) ) { + return true; } - return FALSE; + return false; } -?> |
