Browse Source

Migration framework: Added switch to either migrate or synchronize - refs BT#4882

Yannick Warnier 12 years ago
parent
commit
2968ae32cd
2 changed files with 36 additions and 34 deletions
  1. 4 2
      tests/migrate/config.dist.php
  2. 32 32
      tests/migrate/migrate.php

+ 4 - 2
tests/migrate/config.dist.php

@@ -66,12 +66,14 @@ $servers = array(
     array(  'name'          => 'Old ms',
             'filename'      => 'db_matches.php',   
             'connection'    => $config,
-            'active'        => false
+            'active'        => false,
+            'action'        => 'm', //m for migrate, s for synchronize
     ),
     array(  'name' => 'with e class stuff',
             'filename'      => 'db_matches_2.php',   
             'connection'    => $config2,
-            'active'        => true
+            'active'        => true,
+            'action'        => 'm', //m for migrate, s for synchronize
     ),    
 );
 

+ 32 - 32
tests/migrate/migrate.php

@@ -1,5 +1,9 @@
 <?php
-
+/**
+ * Base process migration script. This script reads a specific configuration file and contacts libraries
+ * in order to know what to migrate and where
+ * @package chamilo.migration
+ */
 /**
  * Load required classes
  */
@@ -21,20 +25,21 @@ require_once 'migration.class.php';
 if (empty($servers)) {
     die("This script requires a servers array with the connection settings and the file to parse\n");
 }
-
+/**
+ * Read the configuration file
+ */
 if (!empty($servers)) {
-    foreach($servers as $server_info) {        
+    foreach ($servers as $server_info) {
         if ($server_info['active']) {
             echo "\n---- Start loading server----- \n";
             echo $server_info['name']."\n\n";
-            //echo "---- ----------------------- \n";            
             
-            $config_info = $server_info['connection'];            
+            $config_info = $server_info['connection'];
             $db_type = $config_info['type'];
             
             if (empty($db_type)) {
                 die("This script requires a DB type to work. Please update orig_db_conn.inc.php\n");
-            }            
+            }
             $file = dirname(__FILE__) . '/migration.' . $db_type . '.class.php';
             if (!is_file($file)) {
                 die("Could not find db type file " . $file . "\n");
@@ -42,35 +47,30 @@ if (!empty($servers)) {
             require_once $file;
             $class = 'Migration' . strtoupper($db_type);
             $m = new $class($config_info['host'], $config_info['port'], $config_info['db_user'], $config_info['db_pass'], $config_info['db_name']);
-            //$m->connect();
+            $m->connect();
+            if ($server_info['m']) {
+                /**
+                 * Prepare the arrays of matches that will allow for the migration
+                 */
+                $migrate = array();
+                include $server_info['filename'];
+                //Default migration from MSSQL to Chamilo MySQL
+                $m->migrate($matches);
+            } elseif ($server_info['s']) {
+                //Getting transactions from MSSQL (via webservices)
+                if (isset($matches['web_service_calls']['filename'])) {
+                    require_once $matches['web_service_calls']['filename'];
+                }
+                //This functions truncates the transaction lists!
+                $m->test_transactions($matches['web_service_calls']);
+                //$m->search_transactions($matches['web_service_calls']);
             
-            /**
-             * Prepare the arrays of matches that will allow for the migration
-             */
-            
-            $migrate = array();
-            include $server_info['filename'];
-            //Default migration from MSSQL to Chamilo MySQL
-            //$m->migrate($matches);
-            
-            //Getting transactions from MSSQL (via webservices)
-            
-            if (isset($matches['web_service_calls']['filename'])) {                
-                require_once $matches['web_service_calls']['filename'];    
+                //Load transactions saved before            
+                $m->load_transactions($matches);
             }
-            //This functions truncates the transaction lists!
-            $m->test_transactions($matches['web_service_calls']);
-            
-            //$m->search_transactions($matches['web_service_calls']);
-            
-            //Load transactions saved before            
-            $m->load_transactions($matches);    
-            
-            //print_r($m->errors_stack);
-            //echo "OK so far\n";
             echo "\n ---- End loading server----- \n";
         } else {
             error_log("db_matches not activated: {$server_info['name']} {$server_info['filename']}");
-        }        
+        }
     }
-}
+}