Bläddra i källkod

More modifications during the migration of data see BT#4875

Julio Montoya 12 år sedan
förälder
incheckning
29c81a48fa

+ 9 - 15
tests/migrate/migration.class.php

@@ -108,7 +108,7 @@ class Migration {
                 $build_only = true;
             }
             
-            //Create extra fields
+            //Creating extra fields
             if (isset($table['extra_fields']) && in_array($table['dest_table'], array('course', 'user', 'session'))) {
                 error_log('Inserting (if exists) extra fields for : ' . $table['dest_table']." \n");
                 
@@ -166,9 +166,9 @@ class Migration {
                     //error_log('Loading: ');error_log(print_r($row, 1));
                     self::execute_field_match($table, $row, $extra_fields);
                     $percentage = $item / $num_rows*100;
-                    if (round($percentage) % 100 == 0) {     
+                    if (round($percentage) % 10 == 0) {     
                         $percentage = round($percentage, 3);
-                        error_log("Processing item # $item $percentage%") ;
+                        error_log("Processing item {$table['orig_table']} #$item $percentage%") ;
                     }
                     $item++;
                 }                
@@ -178,7 +178,7 @@ class Migration {
             }
             
             //Stop here (only for tests)
-            if ($table['orig_table'] == 'ProgramaAcademico')  {
+            if ($table['orig_table'] == 'Matricula')  {
                 exit;          
             }
         }
@@ -293,6 +293,7 @@ class Migration {
             } else {
                 error_log('Result of calling ' . $table['dest_func'] . ': ' . print_r($item_result, 1));
             }
+            //error_log('Result of calling ' . $table['dest_func'] . ': ' . print_r($item_result, 1));
             //After the function was executed fill the $this->data_list array
             switch ($table['dest_table']) {
                 case 'course':
@@ -319,19 +320,12 @@ class Migration {
                         }                                          
                     } else {
                         global $api_failureList;
-                        error_log(print_r($api_failureList, 1));
-                        //error_log("User can't be generated");
-                    }
-                    //error_log(print_r($dest_row, 1));
-                    //error_log(print_r($this->data_list['users_persona'][$dest_row['uidIdPersona']],1));
-                    //error_log(print_r($item_result, 1));
-                    if (!empty($dest_row) && $table['orig_table'] == 'Persona' && !empty($dest_row['username'])) {
-                        //exit;
-                    }
+                        error_log(print_r($api_failureList, 1));                        
+                    }       
                     break;
                 case 'session':                     
-                    $this->data_list['sessions'][$dest_row['uidIdCabProgramaAcademico']] = $item_result;
-                    $handler_id = $item_result['session_id'];
+                    $this->data_list['sessions'][$dest_row['uidIdPrograma']] = $item_result;                    
+                    $handler_id = $item_result; //session_id
                     break;
             }
             

+ 57 - 13
tests/migrate/migration.custom.class.php

@@ -21,6 +21,10 @@ class MigrationCustom {
     public function none($data) {
         return $data;
     }
+    
+     public function join_horario($data, &$omigrate, $row_data) {
+         return $row_data['chrHoraInicial'].' '.$row_data['chrHoraFinal'];
+     }
 
     /**
      * Transform the uid identifiers from MSSQL to a string
@@ -49,6 +53,10 @@ class MigrationCustom {
         return utf8_encode($value);        
     }
     
+    public function clean_session_name($value, &$omigrate, $row_data) {
+        return self::clean_utf8($row_data['session_name']);        
+    }
+    
     public function log_original_persona_unique_id($data, &$omigrate, $row_data) {  
         if (isset($omigrate['users_persona'][$row_data['uidIdPersona']])) {
             $omigrate['users_persona'][$row_data['uidIdPersona']][] = $omigrate['users_persona'][$row_data['uidIdPersona']];
@@ -79,7 +87,7 @@ class MigrationCustom {
      * Log data from the original users table
      */
     public function log_original_session_unique_id($data, &$omigrate, $row_data) {
-        $omigrate['sessions'][$row_data['uidIdCabProgramaAcademico']] = $row_data;
+        $omigrate['sessions'][$row_data['uidIdPrograma']] = $row_data;
         return $data;
     }
     
@@ -98,7 +106,7 @@ class MigrationCustom {
         error_log($omigrate['sessions'][$data]);*/
         if (!isset($omigrate['sessions'][$data])) {
             error_log(print_r($omigrate['sessions'], 1));
-            error_log("sessions not found in data_list array ");
+            error_log("Sessions not found in data_list array ");
             exit;
         }
         return $omigrate['sessions'][$data];        
@@ -130,22 +138,23 @@ class MigrationCustom {
         //error_log('get_real_teacher_id');
         //error_log($data);             
         if (empty($data)) {
-            error_log('No teacher provided');
+            //error_log('No teacher provided');
             return $default_teacher_id;
         }
         
         if (!isset($omigrate['users_empleado'][$data])) {
-            error_log('Teacher not found big problem!');    
-            echo $data;
-            print_r($omigrate['users_empleado'][$data]);
+            //error_log(' Teacher not found big problem! ');    
+            //echo $data;
+            //print_r($omigrate['users_empleado'][$data]);
             //echo $data;exit;
             return $default_teacher_id;            
         } else {
+            //error_log('Teacher found: '.$omigrate['users_empleado'][$data]['extra']['user_id']);
             return isset($omigrate['users_empleado'][$data]['extra']) ? $omigrate['users_empleado'][$data]['extra']['user_id'] : $default_teacher_id;        
         }        
     }
-     
-    public function create_user($data, $omigrate) {       
+    
+    public function create_user($data, $omigrate) {
         //error_log(print_r($data, 1));  
         
         if (empty($data['uidIdPersona'])) {
@@ -182,8 +191,9 @@ class MigrationCustom {
             $extra_data = UserManager::get_extra_user_data_by_value('uidIdPersona', $data['uidIdPersona']);
             
             if ($extra_data) {
-                $user_info = api_get_user_info($extra_data['user_id']);
-                error_log("User_already_added {$user_info['username']}");
+                $user_info = api_get_user_info($extra_data[0]);
+                //print_r($extra_data);
+                //error_log("User_already_added - {$user_info['user_id']}  - {$user_info['username']} - {$user_info['firstname']} - {$user_info['lastname']}");
                 return $user_info;
             }
             
@@ -194,14 +204,16 @@ class MigrationCustom {
                 //the user already exists?
                 $user_info = UserManager::get_user_info_simple($wanted_user_name);
                 $user_persona = UserManager::get_extra_user_data_by_field($user_info['user_id'], 'uidIdPersona');
+                
                 if (isset($user_persona['uidIdPersona']) && $data['uidIdPersona'] == $user_persona['uidIdPersona']) {
                     error_log("Skip user already added: {$user_info['username']}");                    
                     return $user_info;
                 } else {
-                    error_log("homonym $wanted_user_name - {$user_persona['uidIdPersona']} - {$user_info['username']}");       
+                    error_log("homonym - wanted_username: $wanted_user_name - uidIdPersona: {$user_persona['uidIdPersona']} - username: {$user_info['username']}");       
                     print_r($data);
                      //The user has the same firstname and lastname but it has another uiIdPersona could by an homonym  
-                    $data['username'] = UserManager::create_unique_username($data['firstname'], $data['lastname']);                    
+                    $data['username'] = UserManager::create_unique_username($data['firstname'], $data['lastname']);       
+                    error_log("homonym username created ". $data['username']);
                 }
             }
             
@@ -209,8 +221,31 @@ class MigrationCustom {
                 //Last chance to have a nice username   
                 if (empty($data['firstname']) && empty($data['lastname'])) {
                     $data['username'] = UserManager::create_unique_username(uniqid());
+                    error_log("username empty 1". $data['username']);
                 } else {
                     $data['username'] = UserManager::create_unique_username($data['firstname'], $data['lastname']);
+                    error_log("username empty 2". $data['username']);
+                }
+            }
+        } else {
+             if (UserManager::is_username_available($data['username'])) {
+                //error_log("username available {$data['username']} ");
+            } else {
+                //the user already exists?
+                $user_info = UserManager::get_user_info_simple($data['username']);
+                $user_persona = UserManager::get_extra_user_data_by_field($user_info['user_id'], 'uidIdPersona');
+               
+                
+                if (isset($user_persona['uidIdPersona']) && (string)$data['uidIdPersona'] == (string)$user_persona['uidIdPersona']) {
+                    //error_log("2 Skip user already added: {$user_info['username']}");                    
+                    return $user_info;
+                } else {
+                    //print_r($user_persona);
+                    //error_log("2 homonym - wanted_username: {$data['username']} - uidIdPersona: {$user_persona['uidIdPersona']} - username: {$user_info['username']}");       
+                    //print_r($data);
+                     //The user has the same firstname and lastname but it has another uiIdPersona could by an homonym  
+                    $data['username'] = UserManager::create_unique_username($data['firstname'], $data['lastname']);       
+                    //error_log("2 homonym username created ". $data['username']);                    
                 }
             }
         }
@@ -237,9 +272,18 @@ class MigrationCustom {
     
     public function create_course($data) {
         //Fixes wrong wanted codes
-        $data['wanted_code'] = str_replace(array('-', '_'), '000', $data['wanted_code']);
+        $data['wanted_code'] = str_replace(array('-', '_'), '000', $data['wanted_code']);        
         return CourseManager::create_course($data);
     }
+    public function create_session($data) {
+        $session_id = SessionManager::add($data);
+        if (!$session_id) {
+            print_r($data);
+            exit;
+        }
+        return $session_id;
+    }
+    
     public function add_user_to_session($data, $data_list) {
         error_log('add_user_to_session');
         

+ 11 - 6
tests/migrate/migration.mssql.class.php

@@ -32,13 +32,15 @@ class MigrationMSSQL extends Migration {
         }
         //In order to process X item of each table add TOP X
         
-        $top = " TOP 1000 ";
+        $top = " TOP 50000 ";
         if (in_array($table, array('Empleado', 'Alumno'))) {
-            $top = " TOP 5000 ";            
+            $top = " TOP 2000 ";            
         }
-        if ($table == 'ProgramaAcademico') {
-            $top = "  TOP 1000 ";    
+        
+        if (in_array($table, array('ProgramaAcademico', 'Matricula'))) {
+            $top = "  ";
         }
+      
        //$top = null;
         //$top = " TOP 2500 ";  
         $extra = null;
@@ -46,13 +48,16 @@ class MigrationMSSQL extends Migration {
             $extra = ' '.$options['alias_orig_table'].' INNER JOIN '.$options['inner_join'].' '.$options['alias_join_table'].' ON '.$options['on'];
         }
         $order = isset($options['order']) ? $options['order'] : null;
-        $sql = "SELECT $top $fields_sql FROM $table $extra $order";
+        
+        $sql = "SELECT $top $fields_sql FROM $table $extra $order";        
+        $sql = isset($options['query']) ? sprintf($options['query'], "$top $fields_sql") : $sql;
+        
         if (!empty($extra)) {
             error_log(print_r($options,1));
             error_log($sql);
         }
-        //remove
         
+        //Remove        
         $this->rows_iterator = mssql_query($sql, $this->c);
         
         if ($this->rows_iterator  === false) {