Index: modules/Migration/Migration.php
===================================================================
--- modules/Migration/Migration.php (revision 9540)
+++ modules/Migration/Migration.php (working copy)
@@ -16,6 +16,7 @@
//Step : 4 => Put the old dump into the New Database
//Step : 5 => Modify the new database with the new changes
+
class Migration
{
@@ -103,8 +104,20 @@
function takeDatabaseDump($host_name,$mysql_port,$mysql_username,$mysql_password,$dbname)
{
global $migrationlog;
+
+ // DG 26 Sept 2006
+ // Don't assume mysql is in the path!!!!
+ // Should be a way to make this global....
+ $dg_pathprefix = '/home/vtigerCRM5/vtigerCRM5_rc/mysql/bin/';
+ $dg_dumpdir = '/home/vtigerCRM5/vtigerCRM5_rc/apache/htdocs/vtigerCRM/test/';
+
$migrationlog->debug("Inside the function takeDatabaseDump($host_name,$mysql_port,$mysql_username,$mysql_password,$dbname). Going to take the specified database dump...");
+ if ((! $dg_pathprefix) || (! $dg_dumpdir)) {
+ $migrationlog->debug("dg_pathprefix or dg_dumpdir not set! Aborting!");
+ exit;
+ }
+
$dump_filename = 'dump_'.$dbname.'.txt';
if($mysql_password != '')
@@ -116,35 +129,45 @@
$password_str = '';
}
+ $current_working_dir = $dg_dumpdir;
+
//This if is used when we cannot access mysql from vtiger root directory
if($_SESSION['set_server_mysql_path'] != '')
{
- $current_working_dir = getcwd();
+ $current_working_dir = $dg_dumpdir;
$server_mysql_path = $_SESSION['set_server_mysql_path'];
- $dump_str = "mysqldump -u".$mysql_username.$password_str." -h ".$host_name." --port=".$mysql_port." ".$dbname." >> ".$dump_filename;
- $migrationlog->debug("Server path set. Dump string to execute ==> $dump_str");
-
chdir ($server_mysql_path);
+ $migrationlog->debug("Server path set: |".$server_mysql_path."|");
+ $dump_str = 'mysqldump -u'.$mysql_username.$password_str.' -h '.$host_name.' --port='.$mysql_port.' '.$dbname.' >>'.$current_working_dir.$dump_filename;
+ $migrationlog->debug("Server path set. Dump string to execute ==> |".$dump_str."|");
+
exec("echo 'set FOREIGN_KEY_CHECKS = 0;' > ".$dump_filename);
exec($dump_str);
exec("echo 'set FOREIGN_KEY_CHECKS = 1;' >> ".$dump_filename);
-
- exec('cp "'.$server_mysql_path.'\\'.$dump_filename.'" "'.$current_working_dir.'\\'.$dump_filename).'"';
+
+ // DG 27 Sept 2006
+ // Don't need this step when we can just dump direct
+ //exec('cp "'.$server_mysql_path.'\\'.$dump_filename.'" "'.$current_working_dir.'\\'.$dump_filename).'"';
chdir ($current_working_dir);
}
else
{
- $migrationlog->debug("Dump string to execute ==> mysqldump -u".$mysql_username." -h ".$host_name.$password_str." --port=".$mysql_port." ".$dbname." >> ".$dump_filename);
+ // DG 27 Sept 2006
+ // Why was this commented out??
- exec("echo 'set FOREIGN_KEY_CHECKS = 0;' > ".$dump_filename);
- exec("mysqldump -u".$mysql_username." -h ".$host_name.$password_str." --port=".$mysql_port." ".$dbname." >> ".$dump_filename);
- exec("echo 'set FOREIGN_KEY_CHECKS = 1;' >> ".$dump_filename);
+ $migrationlog->debug("No value set for session variable set_server_mysql_path so we use the hardcoded path prefix value dg_pathprefix instead: |".$dg_pathprefix);
+ $dump_str = $dg_pathprefix.'mysqldump -u'.$mysql_username.$password_str.' -h '.$host_name.' --port='.$mysql_port.' '.$dbname.' >>'.$current_working_dir.$dump_filename;
+ $migrationlog->debug("Dump string to execute: ".$dump_str);
+
+ exec("echo 'set FOREIGN_KEY_CHECKS = 0;' > ".$current_working_dir.$dump_filename);
+ exec($dump_str);
+ exec("echo 'set FOREIGN_KEY_CHECKS = 1;' >> ".$current_working_dir.$dump_filename);
}
- $_SESSION['migration_log'] .= '
'.$dbname.' Database Dump has been taken and the file is ==> '.$dump_filename;
- $migrationlog->debug("
$dbname Database Dump has been taken and the file is ==> $dump_filename");
+ $_SESSION['migration_log'] .= '
'.$dbname.' Database Dump has been taken and the file is ==> '.$current_working_dir.$dump_filename;
+ $migrationlog->debug("
$dbname Database Dump has been taken and the file is ==> ".$current_working_dir.$dump_filename);
return $dump_filename;
}
@@ -197,8 +220,19 @@
function applyDumpData($host_name,$mysql_port,$mysql_username,$mysql_password,$dbname,$dumpfile)
{
global $migrationlog;
+ // DG 26 Sept 2006
+ // Don't assume mysql is in the path!!!!
+ // Should be a way to make this global....
+ $dg_pathprefix = '/home/vtigerCRM5/vtigerCRM5_rc/mysql/bin/';
+ $dg_dumpdir = '/home/vtigerCRM5/vtigerCRM5_rc/apache/htdocs/vtigerCRM/test/';
+
$migrationlog->debug("Inside the function applyDumpData($host_name,$mysql_port,$mysql_username,$mysql_password,$dbname,$dumpfile).");
+ if ((! $dg_pathprefix) || (! $dg_dumpdir)) {
+ $migrationlog->debug("dg_pathprefix or dg_dumpdir not set! Aborting!");
+ exit;
+ }
+
if($mysql_password != '')
{
$password_str = " --password=".$mysql_password;
@@ -208,13 +242,14 @@
$password_str = '';
}
+ $current_working_dir = $dg_dumpdir;
//This if is used when we cannot access mysql from vtiger root directory
if($_SESSION['set_server_mysql_path'] != '')
{
- $current_working_dir = getcwd();
$server_mysql_path = $_SESSION['set_server_mysql_path'];
-
- $dump_str = "mysql --user=".$mysql_username.$password_str." -h ".$host_name." --force --port=".$mysql_port." ".$dbname." < ".$dumpfile;
+ $migrationlog->debug("Changed directory to |$server_mysql_path|");
+
+ $dump_str = "./mysql --user=".$mysql_username.$password_str." -h ".$host_name." --force --port=".$mysql_port." ".$dbname." < ".$current_working_dir.$dumpfile;
$migrationlog->debug("MySQL server path set. Dump string to apply ==> $dump_str");
//exec("path = $server_mysql_path");
@@ -226,8 +261,10 @@
}
else
{
- exec("mysql --user=".$mysql_username." -h ".$host_name." --force --port=".$mysql_port.$password_str." ".$dbname." < ".$dumpfile);
- $migrationlog->debug("Dump string to apply ==> mysql --user=$mysql_username -h $host_name --force --port=$mysql_port $password_str $dbname < $dumpfile");
+ $migrationlog->debug("No value set for session variable set_server_mysql_path so we use the hardcoded path prefix value dg_pathprefix instead: |".$dg_pathprefix);
+ $dump_str = $dg_pathprefix."mysql --user=".$mysql_username." -h ".$host_name." --force --port=".$mysql_port.$password_str." ".$dbname." < ".$current_working_dir.$dumpfile;
+ exec($dump_str);
+ $migrationlog->debug("Dump string to apply ==>".$dump_str);
}
$_SESSION['migration_log'] .= '
Database Dump has been applied to the '.$dbname.' Database from '.$dumpfile.'';
@@ -359,7 +396,8 @@
}
else
{
- echo '
The Source database dump taken may not contain all values. So please use other option.';
+ $filesize = filesize($dump_file);
+ echo '
The Source database dump taken was only '.$filesize.' bytes long which is suspiciously small.
Please check the Migration Log for clues as to what happened.';
include("modules/Migration/MigrationStep1.php");
exit;
}
@@ -411,6 +449,9 @@
$migrationlog->debug("Going to apply the old database dump to the new database.");
$this->applyDumpData($new_host_name,$new_mysql_port,$new_mysql_username,$new_mysql_password,$new_dbname,$dump_file);
+ // DG 27 Sept 2006
+ // Is this check even valid????
+
//get the number of tables in new database
$new_tables_count = $this->getTablesCountInNewDatabase();