Преглед на файлове

Removing client_name.custom.class.php file an added into migration.custom.class.php

Julio Montoya преди 12 години
родител
ревизия
a5e661c5d7
променени са 3 файла, в които са добавени 321 реда и са изтрити 27 реда
  1. 13 12
      tests/migrate/migrate.php
  2. 11 14
      tests/migrate/migration.class.php
  3. 297 1
      tests/migrate/migration.custom.class.php

+ 13 - 12
tests/migrate/migrate.php

@@ -62,20 +62,21 @@ if (!empty($servers)) {
                 error_log('Starting Migration');
                 //Default migration from MSSQL to Chamilo MySQL
                 $m->migrate($matches);
-            } else {
-                error_log('Starting Synchronization');
+            } else {                
                 //Getting transactions from MSSQL (via webservices)
-             
-                if (isset($matches['web_service_calls']['filename'])) {                
-                    require_once $matches['web_service_calls']['filename'];    
+                if (!empty($matches['web_service_calls'])) {
+                    error_log('Starting Synchronization');
+                    
+                    //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);
+                } else {
+                    error_log('Make sure you define the web_service_calls array in your db_matches.php file');
                 }
-                //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);
             }

+ 11 - 14
tests/migrate/migration.class.php

@@ -196,14 +196,14 @@ class Migration {
         }
         
         if (!empty($data)) {
-            error_log("Calling {$web_service_params['class']}::$function_name  $url with params: ".print_r($params,1));
-            return $web_service_params['class']::$function_name($data, $params);           
+            error_log("Calling MigrationCustom::$function_name  $url with params: ".print_r($params,1));
+            return MigrationCustom::$function_name($data, $params);           
         } else {
             return array(
                 'error' => true,
                 'message' => 'No Data found',
                 'status_id' => 0
-            );            
+            );
         }        
     }
     
@@ -510,7 +510,7 @@ class Migration {
         );
         
         foreach( $transaction_harcoded as  $transaction) {        
-            $transaction_id = self::add_transaction($transaction);
+            self::add_transaction($transaction);
         }        
     }
 
@@ -533,6 +533,7 @@ class Migration {
         }
         return $inserted_id;        
     }
+    
     /**
      * Get all available branches (the migration system supports multiple origin databases, the branch identifies which database it comes from)
      * @return array Branches IDs (int)
@@ -572,6 +573,7 @@ class Migration {
         $result = Database::query($sql);        
         return Database::store_result($result, 'ASSOC');
     }
+    
     /**
      * Gets the latest completed transaction for a specific branch (allows the building of a request to the branch to get new transactions)
      * @param int The ID of the branch
@@ -588,6 +590,7 @@ class Migration {
         }
         return 0;
     }
+    
     /**
      * Gets the latest locally-recorded transaction for a specific branch
      * @param int The ID of the branch
@@ -604,6 +607,7 @@ class Migration {
         }
         return 376011;
     }
+    
     /**
      * Gets a specific transaction using select parameters
      * @param array Select parameters (associative array)
@@ -614,6 +618,7 @@ class Migration {
         $table = Database::get_main_table(TABLE_MIGRATION_TRANSACTION);
         return Database::select('*', $table, $params, $type_result);
     }
+    
     /**
      * Updates a transaction using the given query parameters
      * @param array Query parameters
@@ -665,7 +670,7 @@ class Migration {
             $last = self::get_latest_transaction_by_branch($branch['branch_id']);
             $result = self::soap_call($web_service_params, 'transacciones', array('ultimo' => $last, 'cantidad' => 1));
             //Calling a process to save transactions
-            $web_service_params['class']::process_transactions($web_service_params, array('ultimo' => $last, 'cantidad' => 1));
+            MigrationCustom::process_transactions($web_service_params, array('ultimo' => $last, 'cantidad' => 1));
         }
     }   
 
@@ -732,15 +737,7 @@ class Migration {
                             $result = MigrationCustom::$function_to_call($transaction, $matches['web_service_calls']);
                             error_log('Reponse: '.$result['message']);
                             
-                            self::update_transaction(array('id' => $transaction['id'] , 'status_id' => $result['status_id']));
-                            /*
-                            if ($result['error'] == false) {
-                                //Updating transaction
-                                //self::update_transaction(array('id' => $transaction['id'] , 'status_id' => MigrationCustom::TRANSACTION_STATUS_SUCCESSFUL));
-                            } else {
-                                //failed
-                                //self::update_transaction(array('id' => $transaction['id'] , 'status_id' => MigrationCustom::TRANSACTION_STATUS_FAILED));
-                            }*/
+                            self::update_transaction(array('id' => $transaction['id'] , 'status_id' => $result['status_id']));                  
                         } else {
                             //	method does not exist
                             error_log("Function does $function_to_call not exists");

+ 297 - 1
tests/migrate/migration.custom.class.php

@@ -302,7 +302,7 @@ class MigrationCustom {
         //Fixes wrong wanted codes
         $data['wanted_code'] = str_replace(array('-', '_'), '000', $data['wanted_code']);
         
-        //Specific to ICPNA, set the default language to English
+        //Specific to customer, set the default language to English
         $data['language'] = 'english';
         $data['visibility'] = COURSE_VISIBILITY_REGISTERED;
         
@@ -1364,4 +1364,300 @@ class MigrationCustom {
     static function transaction_27($data, $web_service_details) {
         return self::transaction_extra_field_editar_generic('intensidad', $data, $web_service_details);
     }
+    
+    
+    //custom class moved here
+    
+    static function transacciones($data) {   
+        if ($data) {
+            $xml = $data->transaccionesResult->any;                        
+            // Cut the invalid XML and extract the valid chunk with the data
+            $stripped_xml = strstr($xml, '<diffgr:diffgram');
+            $xml = simplexml_load_string($stripped_xml);
+            if (!empty($xml->NewDataSet)) {                
+                $transaction_list = array();
+                foreach ($xml->NewDataSet->Table as $item) { //this is a "Table" object
+                    $item = (array) $item;                    
+                    $transaction_list[] = $item;
+                }
+                return $transaction_list;
+            } else {
+                error_log('No transactions found');
+            }        
+        } else {
+            error_log('Data is not valid');
+        }
+    }
+    
+    /*  object(SimpleXMLElement)#11 (5) {
+      ["idt"]=>
+      string(6) "354913"
+      ["idsede"]=>
+      string(1) "2"
+      ["ida"]=>
+      string(2) "10"
+      ["id"]=>
+      string(36) "cf0f2c9b-3e79-4960-8dec-b1a02b367921"
+      ["timestamp"]=>
+      string(12) "AAAAATbYxkg="
+    }
+    */
+    static function process_transactions($web_service_params, $params) {
+        $transactions = Migration::soap_call($web_service_params, 'transacciones', $params);
+        if (!empty($transactions)) {
+             foreach ($transactions as $transaction_info) {
+                /*
+                id transaccion
+                id sede
+                id accion
+                id
+                origen
+                destino
+                timestamp                 
+                 */
+                //Add transactions here
+               if ($transaction_info) {
+                    $params = array(
+                        'action'    => $transaction_info['idt'],
+                        'item_id'   => $transaction_info['idt'],
+                        'orig_id'   => $transaction_info['idt'],
+                        'branch_id' => $transaction_info['idsede'],
+                        'dest_id'   => $transaction_info['idt'],
+                        'status_id' => 0
+                    );        
+                    Migration::add_transaction($params);             
+                }
+            }
+        }
+    }
+    
+    static function genericDetalles($data, $result_name, $params = array()) {
+        error_log("Calling $result_name ");
+        $result_name = $result_name.'Result';
+        $xml = $data->$result_name->any;
+        
+        // Cut the invalid XML and extract the valid chunk with the data
+        $stripped_xml = strstr($xml, '<diffgr:diffgram');        
+        $xml = simplexml_load_string($stripped_xml);
+        
+        if (!empty($xml->NewDataSet)) {
+            $item = (array)$xml->NewDataSet->Table;            
+            var_dump($item);
+            $item['error'] = false;
+            return $item;            
+        } else {            
+            return array(
+                'error' => true,
+                'message' => "No data when calling $result_name",
+                'status_id' => MigrationCustom::TRANSACTION_STATUS_FAILED,
+            );
+        }
+    }
+    
+    /* Returns an obj with this params
+    object(SimpleXMLElement)#11 (7) {
+      ["rol"]=>
+      string(8) "profesor"
+      ["username"]=>
+      string(4) "3525"
+      ["lastname"]=>
+      string(15) "Zegarra Acevedo"
+      ["firstname"]=>
+      string(10) "Allen Juan"
+      ["phone"]=>
+      object(SimpleXMLElement)#13 (0) {
+      }
+      ["email"]=>
+      string(17) "3525@aaa.com"
+      ["password"]=>
+      string(6) "xxx"
+    }
+    **/
+    static function usuarioDetalles($result, $params) {
+        $result = self::genericDetalles($result, __FUNCTION__, $params);
+        if ($result['error'] == true) {
+            return $result;
+        }
+        
+        $result['status'] = $result['rol']  == 'profesor' ? COURSEMANAGER : STUDENT;        
+        $result['phone'] = (string)$result['phone'];
+        $result['extra_uidIdPersona'] = $params['uididpersona'];
+        unset($result['rol']);
+        return $result;
+    }
+    
+    /*
+    ["uididsede"]=>
+    string(36) "7379a7d3-6dc5-42ca-9ed4-97367519f1d9"
+    ["uididhorario"]=>
+    string(36) "cdce484b-a564-4499-b587-bc32b3f82810"
+    ["chrperiodo"]=>
+    string(6) "200910"
+    ["display_start_date"]=>
+    string(25) "2009-09-30T00:00:00-05:00"
+    ["display_end_date"]=>
+    string(25) "2009-10-26T00:00:00-05:00"
+    ["access_start_date"]=>
+    string(25) "2009-09-30T00:00:00-05:00"
+    ["access_end_date"]=>
+    string(25) "2009-10-26T00:00:00-05:00"
+    
+    ["course_code"]=>
+    string(36) "5b7e9b5a-5145-4a42-be48-223a70d9ad52"
+    ["id_coach"]=>
+    string(36) "26dbb1c1-32b7-4cf8-a81f-43d1cb231abe"
+     * 
+     */
+    static function programaDetalles($data, $params) {  
+        $result = self::genericDetalles($data, __FUNCTION__);
+        if ($result['error'] == true) {
+            return $result;
+        }
+        
+        $result['extra_uidIdPrograma']  = $params['uididprograma'];
+        $result['extra_sede']           = $result['uididsede'];
+        $result['extra_horario']        = $result['uididhorario'];
+        $result['extra_periodo']        = $result['chrperiodo'];
+        
+        $result['display_start_date']   = MigrationCustom::clean_date_time_from_ws($result['display_start_date']);
+        $result['display_end_date']     = MigrationCustom::clean_date_time_from_ws($result['display_end_date']);
+        $result['access_start_date']    = MigrationCustom::clean_date_time_from_ws($result['access_start_date']);
+        $result['access_end_date']      = MigrationCustom::clean_date_time_from_ws($result['access_end_date']);
+        
+        //Searching course code
+        $course_code = MigrationCustom::get_real_course_code($result['course_code']);
+        $result['course_code'] = $course_code;
+        
+        //Searching id_coach
+        $result['id_coach'] = MigrationCustom::get_user_id_by_persona_id($result['id_coach']);
+        
+        unset($result['uididprograma']);
+        unset($result['uididsede']);
+        unset($result['uididhorario']);
+        unset($result['chrperiodo']);
+        
+        return $result;
+    }
+     
+    /**
+       ["name"]=>
+       string(42) "(A02SA) Pronunciacion Two Sabado Acelerado"
+       ["frecuencia"]=>
+       string(36) "0091cd3b-f042-11d7-b338-0050dab14015"
+       ["intensidad"]=>
+       string(36) "0091cd3d-f042-11d7-b338-0050dab14015"
+       ["fase"]=>
+       string(36) "90854fc9-f748-4e85-a4bd-ace33598417d"
+       ["meses"]=>
+       string(3) "2  "
+   */
+    static function cursoDetalles($data, $params) {  
+        $result = self::genericDetalles($data, __FUNCTION__);
+        if ($result['error'] == true) {
+            return $result;
+        }
+        
+        $result['title']            = $result['name'];
+        $result['extra_frecuencia'] = $result['frecuencia'];
+        $result['extra_intensidad'] = $result['intensidad'];
+        $result['extra_fase']       = $result['fase'];
+        $result['extra_meses']       = $result['meses'];
+        $result['extra_uidIdCurso'] = $params['uididcurso'];
+        
+        unset($result['frecuencia']);
+        unset($result['intensidad']);
+        unset($result['fase']);
+        unset($result['name']);
+        unset($result['meses']);
+        
+        return $result;
+    }
+    
+    /*Calling frecuenciaDetalles 
+    array(1) {
+      ["name"]=>
+      string(8) "Sabatino"
+    }*/
+    static function faseDetalles($data) {
+        $result = self::genericDetalles($data, __FUNCTION__);
+        if ($result['error'] == true) {
+            return $result;
+        }        
+        return $result;        
+    }
+    
+    static function frecuenciaDetalles($data, $params) {
+        $result = self::genericDetalles($data, __FUNCTION__); 
+        if ($result['error'] == true) {
+            return $result;
+        }        
+        return $result;
+    }
+    
+    /*Calling intensidadDetalles 
+    array(1) {
+      ["name"]=>
+      string(6) "Normal"
+    }*/
+
+    static function intensidadDetalles($data, $params) {
+        $result = self::genericDetalles($data, __FUNCTION__);
+        if ($result['error'] == true) {
+            return $result;
+        }        
+        //$result['option_value'] = $params['uididintensidad'];
+        return $result;
+    }
+    
+    /*Calling mesesDetalles
+    Calling mesesDetalles 
+    array(1) {
+      ["name"]=>
+      string(3) "4  "
+    }*/
+    static function mesesDetalles($data, $params) {
+        $result = self::genericDetalles($data, __FUNCTION__);
+        if ($result['error'] == true) {
+            return $result;
+        }        
+        return $result;
+    }
+    
+    /*Calling sedeDetalles 
+    array(1) {
+      ["name"]=>
+      string(23) "Sede Miraflores"
+    }*/
+
+    static function sedeDetalles($data, $params) {
+        $result = self::genericDetalles($data, __FUNCTION__);
+        if ($result['error'] == true) {
+            return $result;
+        }        
+        return $result;
+    }
+    
+    /*
+    Calling horarioDetalles 
+    array(3) {
+      ["start"]=>
+      string(5) "08:45"
+      ["end"]=>
+      string(5) "10:15"
+      ["id"]=>
+      string(2) "62"
+    }*/
+    static function horarioDetalles($data, $params) {         
+        $result = self::genericDetalles($data, __FUNCTION__);        
+        if ($result['error'] == true) {
+            return $result;
+        }
+        
+        $result['name'] = $result['id'].' '.$result['start'].' '.$result['end'];
+        //$result['option_value'] = $params['uididhorario'];        
+        unset($result['id']);
+        unset($result['start']);
+        unset($result['end']);
+        return $result;
+    }
 }