Browse Source

Adding multiple server support in migrate.php in order different matches files

Julio Montoya 12 years ago
parent
commit
bdbbf660a3
3 changed files with 123 additions and 23 deletions
  1. 35 0
      tests/migrate/config.dist.php
  2. 43 19
      tests/migrate/migrate.php
  3. 45 4
      tests/migrate/migration.custom.class.php

+ 35 - 0
tests/migrate/config.dist.php

@@ -40,6 +40,41 @@ $db_pass = 'password';
  * Defaults to: master
  */
 $db_name = 'master';
+//second DB 
+$db_name2 = 'master2';
+
+
+$config = array(    
+    'type' => $db_type,
+    'host' => $db_host,
+    'port' => $db_port,
+    'db_user' => $db_user,
+    'db_pass' => $db_pass,
+    'db_name' => $db_name,    
+);
+
+$config2 = array(    
+    'type' => $db_type,
+    'host' => $db_host,
+    'port' => $db_port,
+    'db_user' => $db_user,
+    'db_pass' => $db_pass,
+    'db_name' => $db_name2,    
+);
+
+$servers = array(
+    array(  'name'          => 'Old ms',
+            'filename'      => 'db_matches.php',   
+            'connection'    => $config,
+            'active'        => false
+    ),
+    array(  'name' => 'with e class stuff',
+            'filename'      => 'db_matches_2.php',   
+            'connection'    => $config2,
+            'active'        => true
+    ),    
+);
+
 
 /**
  * Load the real configuration file (except if we're already in config.php)

+ 43 - 19
tests/migrate/migrate.php

@@ -3,7 +3,7 @@
 /**
  * Load required classes
  */
-require_once '../../main/inc/global.inc.php';
+require_once dirname(__FILE__).'/../../main/inc/global.inc.php';
 require_once 'config.php';
 
 require_once api_get_path(LIBRARY_PATH).'attendance.lib.php';
@@ -17,23 +17,47 @@ if (is_file(dirname(__FILE__) . '/migration.custom.class.php')) {
 }
 require_once 'migration.class.php';
 
-if (empty($db_type)) {
-    die("This script requires a DB type to work. Please update orig_db_conn.inc.php\n");
+if (empty($servers)) {
+    die("This script requires a servers array with the connection settings and the file to parse\n");
 }
-$file = dirname(__FILE__) . '/migration.' . $db_type . '.class.php';
-if (!is_file($file)) {
-    die("Could not find db type file " . $file . "\n");
+
+if (!empty($servers)) {
+    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'];            
+            $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");
+            }
+            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();
+            
+            /**
+             * Prepare the arrays of matches that will allow for the migration
+             */
+            
+            $migrate = array();
+            include $server_info['filename'];
+            $m->migrate($matches);
+            //$m->load_transactions($matches['transactions']);
+            print_r($m->errors_stack);
+            echo "OK so far\n";
+            echo "---- End loading server-----";
+        } else {
+            error_log("db_matches not activated: {$server_info['name']} {$server_info['filename']}");
+        }        
+    }
 }
-require_once $file;
-$class = 'Migration' . strtoupper($db_type);
-$m = new $class($db_host, $db_port, $db_user, $db_pass, $db_name);
-$m->connect();
-/**
- * Prepare the arrays of matches that will allow for the migration
- */
-$migrate = array();
-include 'db_matches_2.php';
-$m->migrate($matches);
-//$m->load_transactions($matches['transactions']);
-print_r($m->errors_stack);
-echo "OK so far\n";
+
+

+ 45 - 4
tests/migrate/migration.custom.class.php

@@ -173,7 +173,7 @@ class MigrationCustom {
      * @param object List of migrated things
      * @return array User info (from Chamilo DB)
      */
-    public function create_user($data, $omigrate) {
+    static function create_user($data, $omigrate) {
         //error_log('In create_user, receiving '.print_r($data,1));
         if (empty($data['uidIdPersona'])) {
             error_log('User does not have a uidIdPersona');
@@ -437,15 +437,56 @@ class MigrationCustom {
                         error_log("Thematic saved: $thematic_id");
                     } else {
                         error_log("Thematic NOT saved");
-                    }                    
+                    }
                 }                
-                
             } else {
                 error_log("No courses in session $session_id ");
+            }            
+        }        
+    }
+    
+    static function add_evaluation_type($params) {
+        $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION_TYPE);
+        if (!empty($params['name']) && !empty($params['external_id'])) {
+            Database::insert($table, $params);
+        }        
+    }
+    
+    static function get_evaluation_type($external_id) {
+        $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION_TYPE);
+        $external_id = intval($external_id);
+        $sql = "SELECT * FROM $table WHERE external_id = $external_id";
+        $result = Database::query($sql);        
+        if (Database::num_rows($result)) {
+            $result = Database::store_result($sql);    
+            return $result['id'];
+        }
+        return false;        
+    }
+    
+    static function create_gradebook_links($data){
+        error_log('create_gradebook_links');
+        
+        $session_id = $data['session_d'];
+        if (!empty($session_id)) {
+            $course_list = SessionManager::get_course_list_by_session_id($session_id);
+            if (!empty($course_list)) {
+                $course_data = current($course_list);
+                if (isset($course_data['code'])) {
+                    //Get gradebook
+                    $gradebook = new Gradebook();
+                    $gradebooks = $gradebook->get_all(array('where' => array('course_code = ? AND session_id = ?' => array($course_data['code'], $session_id))));
+                } else {
+                    error_log("Something is wrong with the course ");    
+                }
+                
+            } else {
+                error_log("NO course found for session id: $session_id");    
             }
             
+        } else {
+            error_log("NO session id found: $session_id");
         }
         
     }
-    
 }