Browse Source

Adding new changes in order to load transactions see BT#4882

Julio Montoya 12 years ago
parent
commit
b146696120

+ 3 - 4
main/inc/lib/database.lib.php

@@ -1148,7 +1148,7 @@ class Database {
      * @example array('where'=> array('name = "Julio" AND lastname = "montoya"))
     */
     public static function select($columns, $table_name, $conditions = array(), $type_result = 'all', $option = 'ASSOC') {        
-        $conditions = self::parse_conditions($conditions);        
+        $conditions = self::parse_conditions($conditions);
         
         //@todo we could do a describe here to check the columns ...
         $clean_columns = '';
@@ -1161,8 +1161,7 @@ class Database {
                 $clean_columns = (string)$columns;
             }
         }
-        $sql    = "SELECT $clean_columns FROM $table_name $conditions";
-        //var_dump($sql);
+        $sql    = "SELECT $clean_columns FROM $table_name $conditions";        
         $result = self::query($sql);
         $array = array();
         //if (self::num_rows($result) > 0 ) {
@@ -1183,7 +1182,7 @@ class Database {
     /**
      * Parses WHERE/ORDER conditions i.e array('where'=>array('id = ?' =>'4'), 'order'=>'id DESC'))
      * @todo known issues, it doesn't work when using LIKE conditions example: array('where'=>array('course_code LIKE "?%"'))
-     * @param   array
+     * @param array
      * @todo lot of stuff to do here
     */
     static function parse_conditions($conditions) {        

+ 2 - 2
main/inc/lib/database.mysqli.lib.php

@@ -1126,7 +1126,7 @@ class Database {
         $return_value = '';
         foreach ($conditions as $type_condition => $condition_data) {
             $type_condition = strtolower($type_condition);
-             switch($type_condition) {
+             switch ($type_condition) {
                 case 'where':
                     foreach ($condition_data as $condition => $value_array) {
                         if (is_array($value_array)) {
@@ -1157,7 +1157,7 @@ class Database {
                     if (!empty($where_return)) {
                         $return_value = " WHERE $where_return" ;
                     }
-                break;
+                    break;
                 case 'order':
                     $order_array = $condition_data;
                     

+ 0 - 2
main/inc/lib/sessionmanager.lib.php

@@ -805,8 +805,6 @@ class SessionManager {
             $update_sql = "UPDATE $tbl_session SET nbr_users = nbr_users + $nbr_users WHERE id='$id_session' ";
             Database::query($update_sql);           
         }
-
-
 	}
     
     function subscribe_users_to_session_course($user_list, $session_id, $course_code, $session_visibility = SESSION_VISIBLE_READ_ONLY ) {

+ 13 - 7
tests/migrate/migrate.php

@@ -42,7 +42,7 @@ 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();
             
             /**
              * Prepare the arrays of matches that will allow for the migration
@@ -50,15 +50,21 @@ if (!empty($servers)) {
             
             $migrate = array();
             include $server_info['filename'];
-            $m->migrate($matches);
-            //$m->load_transactions($matches['transactions']);
-            print_r($m->errors_stack);
+            //Default migration from MSSQL to Chamilo MySQL
+            //$m->migrate($matches);
+            
+            //Getting transactions from MSSQL (via webservices)
+            $m->search_transactions($matches['web_service_calls']['url'], $matches['web_service_calls']['params']);
+            
+            //Load transactions saved before
+            
+            $m->load_transactions($matches['actions']);            
+            
+            //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']}");
         }        
     }
-}
-
-
+}

+ 281 - 79
tests/migrate/migration.class.php

@@ -92,62 +92,263 @@ class Migration {
      * tables and fields matches defined in the given array.
      * @param array Structured array of matches (see migrate.php)
      */
-    public function migrate($matches) { 
-        error_log("\n".'------------ Migration->migrate function called ------------'."\n");        
+    public function migrate($matches) {
+        error_log("\n" . '------------ Migration->migrate function called ------------' . "\n");
         $extra_fields = array();
         // Browsing through 1st-level arrays in db_matches.php
         foreach ($matches as $table) {
             error_log('Found table ' . $table['orig_table'] . ' in db_matches');
             $build_only = false;
-            
+
             if (empty($table['dest_table'])) {
                 //If there is no destination for this table, report
                 error_log(' ... which is just for data collection');
                 $build_only = true;
             }
-            
+
             // Creating extra fields if necessary inside Chamilo (to store 
             // original fields)
             if (isset($table['extra_fields']) && in_array($table['dest_table'], array('course', 'user', 'session'))) {
                 $extra_fields = self::_create_extra_fields($table);
             }
-            
+
             // Process the migration of fields from the given table
             $sql_select_fields = self::prepare_field_match($table);
             $this->select_all($table['orig_table'], $sql_select_fields, $table);
-       
+
             if (count($table['fields_match']) == 0) {
                 error_log('No fields found');
                 continue;
-            }            
+            }
             $num_rows = $this->num_rows();
-            
-            if ($num_rows) {            
-                error_log('Records found: '.$num_rows);
+
+            if ($num_rows) {
+                error_log('Records found: ' . $num_rows);
                 $item = 1;
                 while ($row = $this->fetch_array()) {
                     //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) % 10 == 0) {     
+                    $percentage = $item / $num_rows * 100;
+                    if (round($percentage) % 10 == 0) {
                         $percentage = round($percentage, 3);
-                        error_log("Processing item {$table['orig_table']} #$item $percentage%") ;
+                        error_log("Processing item {$table['orig_table']} #$item $percentage%");
                     }
                     $item++;
-                }                
-                error_log('Finished processing table ' . $table['orig_table']." \n\n");
+                }
+                error_log('Finished processing table ' . $table['orig_table'] . " \n\n");
             } else {
                 error_log('No records found');
             }
-            
+
             //Stop here (only for tests)
-            if ($table['orig_table'] == 'gradebook_evaluation_type')  {
+            if ($table['orig_table'] == 'gradebook_evaluation_type') {
                 exit;
             }
         }
     }
+
+    function search_transactions($url, $params) {
+        $libpath = api_get_path(LIBRARY_PATH);
+        error_log('search_transactions');     
+
+        // Create the client instance        
+        error_log("Looking $url");
+
+        try {
+            $client = new SoapClient($url);
+        } catch (SoapFault $fault) {
+            $error = 1;
+            die('Error connecting');
+        }        
+        $client->debug_flag = true;     
+        try {
+            $user_details = $client->retornaDatos($params);
+        } catch (SoapFault $fault) {
+            $error = 2;
+            die('Problem querying service');
+        }
+
+        if (!empty($user_details)) {
+            $xml = $user_details->retornaDatosResult->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);
+            //print_r($xml);
+            foreach ($xml->NewDataSet as $user) { //this is a "Table" object
+                $u = $user->Table;
+                //here we have the data, so if this whole block is integrated into a funcion, return
+                echo 'firstname: ' . $u->vchprimernombre . ' ' . $u->vchsegundonombre . "\n" . 'lastname: ' . $u->vchpaterno . ' ' . $u->vchmaterno . "\n";
+            }
+        } else {
+            //echo 'User was not recovered, activate the debug=true in the registration.soap.php file and see the error logs'."\n";
+        }
+        
+        //Called transactions from Web service
+        //transacciones_detalles(id_last_transaction=0, transactions_number=10)
+            
+        //Add transactions here
+        $params = array(
+            'action' => 'usuario_agregar',
+            'item_id' =>  '1',
+            'orig_id' => '0',
+            'branch_id' => '1',
+            'dest_id' => null,
+            'status_id' => 0
+        );        
+        self::add_transaction($params);        
+    }
+    
+    function add_transaction($params) {
+        $table = Database::get_main_table(TABLE_MIGRATION_TRANSACTION);
+        if (isset($params['id'])) {
+            unset($params['id']);
+        }
+        $params['time_update'] = $params['time_insert'] = api_get_utc_datetime();        
+        
+        $inserted_id = Database::insert($table, $params);
+        if ($inserted_id) {
+            error_log("Transaction added #$inserted_id");
+        }
+        return $inserted_id;        
+    }
+        
+    function get_branches() {
+        $table = Database::get_main_table(TABLE_MIGRATION_TRANSACTION);
+        $sql = "SELECT DISTINCT branch_id FROM $table ORDER BY branch_id";
+        $result = Database::query($sql);
+        return Database::store_result($result, 'ASSOC');
+    }
+    
+    /** Get unprocesses */
+    function get_transactions($status_id = 0, $branch_id = null) {
+        $table = Database::get_main_table(TABLE_MIGRATION_TRANSACTION);
+        $branch_id = intval($branch_id);
+        $status_id = intval($status_id);
+        
+        $extra_conditions = null;
+        if (!empty($branch_id)) {
+            $extra_conditions = " AND branch_id = $branch_id ";
+        }
+        $sql = "SELECT * FROM $table WHERE status_id = $status_id $extra_conditions ORDER BY id ";
+        $result = Database::query($sql);        
+        return Database::store_result($result, 'ASSOC');
+    }
+    
+    function get_latest_completed_transaction_by_branch($branch_id) {
+        $table = Database::get_main_table(TABLE_MIGRATION_TRANSACTION);
+        $branch_id = intval($branch_id);
+        $sql = "SELECT id FROM $table WHERE status_id = 2 AND branch_id = $branch_id ORDER BY id DESC  LIMIT 1";
+        $result = Database::query($sql);
+        if (Database::num_rows($result)) {
+            $row = Database::fetch_array($result);
+            return $row['id'];
+        }
+        return 0;
+    }
     
-    function load_transactions($transactions) {        
+    function get_latest_transaction_by_branch($branch_id) {
+        $table = Database::get_main_table(TABLE_MIGRATION_TRANSACTION);
+        $branch_id = intval($branch_id);
+        $sql = "SELECT id FROM $table WHERE branch_id = $branch_id ORDER BY id DESC  LIMIT 1";
+        $result = Database::query($sql);
+        if (Database::num_rows($result)) {
+            $row = Database::fetch_array($result);
+            return $row['id'];
+        }
+        return 0;
+    }
+    function get_transaction_by_params($params, $type_result = 'all') {
+        $table = Database::get_main_table(TABLE_MIGRATION_TRANSACTION);
+        return Database::select('*', $table, $params, $type_result);
+    }
+    
+    function update_transaction($params) {
+        $table = Database::get_main_table(TABLE_MIGRATION_TRANSACTION);
+        if (empty($params['id'])) {
+            error_log('No transaction id provided during update_transaction');
+            return false;
+        }
+        $params['time_update'] = api_get_utc_datetime();
+        error_log("Transaction updated #{$params['id']}");
+        
+        //Failed - do something else
+        if ($params['status_id'] == 3) {
+            //event_system($event_type, $event_value_type, $event_value, $datetime = null, $user_id = null, $course_code = null) {
+            event_system('transaction_error', 'transaction_id', $params['id'], $params['time_update']);
+        }
+        return Database::update($table, $params, array('id = ?' => $params['id']));
+    }    
+
+    /* Load transactions */
+
+    function load_transactions($actions) {
+        
+        //Getting transactions of the migration_transaction table
+        $branches = self::get_branches();
+        if (!empty($branches)) {
+            foreach ($branches as $branch_info) {
+                //Get uncompleted transactions                
+                $transactions = self::get_transactions(0, $branch_info['branch_id']);                
+         
+                $options = array('where' => array('branch_id = ? and status_id <> ?' => array($branch_info['branch_id'], 0)), 'order' => 'id desc', 'limit' => '1');
+                $transaction_info = self::get_transaction_by_params($options, 'first');               
+                $latest_id = $transaction_info['id'];
+                
+                $latest_id_attempt = $latest_id + 1;
+                
+                $item = 1;
+
+                if (!empty($transactions)) {
+                    $count = count($transactions);
+                    error_log("\nTransactions found: $count");
+
+                    //Looping transactions
+                    foreach ($transactions as $transaction) {
+                        //Calculating percentage
+                        $percentage = $item / $count * 100;
+                        if (round($percentage) % 10 == 0) {
+                            $percentage = round($percentage, 3);
+                            error_log("\nProcessing transaction #{$transaction['id']} $percentage%");
+                        }
+                        $item++;
+                        //--
+                        
+                        //Checking "huecos"
+                        //Waiting transaction is fine continue:
+                        if ($transaction['id'] == $latest_id_attempt) {
+                            $latest_id_attempt++;
+                        } else {
+                            error_log("Transaction #$latest_id_attempt is missing in branch #{$branch_info['branch_id']}");
+                            exit;
+                        }
+                        
+                        //Loading function
+                        $function_to_call = "transaction_" . $transaction['action'];
+                        if (method_exists('MigrationCustom', $function_to_call)) {
+                            $result = MigrationCustom::$function_to_call($transaction);
+                            error_log("Calling function $function_to_call");
+                            if ($result) {
+                                //Updating transaction
+                                self::update_transaction(array('id' => $transaction['id'] , 'status_id' => $result['status']));                        
+                            } else {
+                                //failed
+                                self::update_transaction(array('id' => $transaction['id'] , 'status_id' => 3));
+                            }
+                        } else {
+                            //	method does not exist
+                            error_log("Function does $function_to_call not exists");
+                            //Failed
+                            self::update_transaction(array('id' => $transaction['id'] , 'status_id' => 3));
+                        }
+                    }
+                } else {
+                    error_log('No transactions to load');
+                }
+            }
+        } else {
+            error_log('No branches found');
+        }
+
         $actions = array(); //load actions from Mysql
         foreach ($actions as $action_data) {
             if (in_array($action_data['action'], $transactions)) {
@@ -156,8 +357,8 @@ class Migration {
             }
         }
     }
-    
-    function prepare_field_match($table) {        
+
+    function prepare_field_match($table) {
         $sql_select_fields = array();
         if (!empty($table['fields_match'])) {
             foreach ($table['fields_match'] as $details) {
@@ -175,24 +376,24 @@ class Migration {
                 //error_log('Found field ' . $details['orig'] . ' to be selected as ' . $sql_select_fields[$details['orig']]);
             }
         }
-        return $sql_select_fields;     
+        return $sql_select_fields;
     }
-    
-    function execute_field_match($table, $row, $extra_fields = array()) {        
+
+    function execute_field_match($table, $row, $extra_fields = array()) {
         //error_log('execute_field_match');
         $dest_row = array();
         $first_field = '';
-        
+
         $my_extra_fields = isset($table['dest_table']) && isset($extra_fields[$table['dest_table']]) ? $extra_fields[$table['dest_table']] : null;
         $extra_field_obj = null;
         $extra_field_value_obj = null;
-        
+
         if (!empty($table['dest_table'])) {
-            $extra_field_obj = new Extrafield($table['dest_table']);        
+            $extra_field_obj = new Extrafield($table['dest_table']);
             $extra_field_value_obj = new ExtraFieldValue($table['dest_table']);
         }
-                
-        $extra_fields_to_insert = array();        
+
+        $extra_fields_to_insert = array();
         foreach ($table['fields_match'] as $id_field => $details) {
             if ($id_field == 0) {
                 $first_field = $details['dest'];
@@ -203,20 +404,20 @@ class Migration {
                     $details['orig'] = $field_exploded[1];
                 }
             }
-            
+
             // process the fields one by one
             if ($details['func'] == 'none' || empty($details['func'])) {
                 $dest_data = $row[$details['orig']];
-            } else {                
+            } else {
                 $dest_data = MigrationCustom::$details['func']($row[$details['orig']], $this->data_list, $row);
             }
-            
+
             if (isset($dest_row[$details['dest']])) {
-                $dest_row[$details['dest']] .= ' '.$dest_data;
+                $dest_row[$details['dest']] .= ' ' . $dest_data;
             } else {
                 $dest_row[$details['dest']] = $dest_data;
             }
-                        
+
             //Extra field values
             $extra_field = isset($my_extra_fields) && isset($my_extra_fields[$details['dest']]) ? $my_extra_fields[$details['dest']] : null;
             //error_log('-----');
@@ -225,44 +426,44 @@ class Migration {
                 if (isset($extra_field['options'])) {
                     $options = $extra_field['options'];
                     $field_type = $extra_field['field_type'];
-                                        
+
                     if (!empty($options)) {
                         foreach ($options as $option) {
                             foreach ($option as $key => $value) {
                                 //error_log("$key $value --> {$dest_row[$details['dest']]} ");
                                 if ($key == 'option_value' && $value == $dest_row[$details['dest']]) {
-                                    $value = $option['option_display_text'];                                    
+                                    $value = $option['option_display_text'];
                                     if ($field_type == Extrafield::FIELD_TYPE_SELECT) {
-                                        $value = $option['option_value']; 
-                                    }                                    
-                                    $params = array(                
-                                        'field_id'      => $option['field_id'],
-                                        'field_value'   => $value,
+                                        $value = $option['option_value'];
+                                    }
+                                    $params = array(
+                                        'field_id' => $option['field_id'],
+                                        'field_value' => $value,
                                     );
-                                   break(2);
-                                }       
+                                    break(2);
+                                }
                             }
                         }
-                    }              
+                    }
                 } else {
                     $params = array(
-                        'field_id'      => $extra_field,
-                        'field_value'   => $dest_row[$details['dest']],
+                        'field_id' => $extra_field,
+                        'field_value' => $dest_row[$details['dest']],
                     );
                 }
                 if (!empty($params)) {
-                    $extra_fields_to_insert[] = $params;                
+                    $extra_fields_to_insert[] = $params;
                 }
                 unset($dest_row[$details['dest']]);
-            }            
-        }  
-        
+            }
+        }
+
         if (!empty($table['dest_func'])) {
             //error_log('Calling '.$table['dest_func'].' on data recovered: '.print_r($dest_row, 1));            
             $dest_row['return_item_if_already_exists'] = true;
-            
+
             $item_result = call_user_func_array($table['dest_func'], array($dest_row, $this->data_list));
-            
+
             if (isset($table['show_in_error_log']) && $table['show_in_error_log'] == false) {
                 
             } else {
@@ -273,17 +474,17 @@ class Migration {
             switch ($table['dest_table']) {
                 case 'course':
                     //Saving courses in array
-                    if ($item_result) {                  
+                    if ($item_result) {
                         //$this->data_list['courses'][$dest_row['uidIdCurso']] = $item_result;        
                     } else {
-                        error_log('Course Not FOUND');                        
+                        error_log('Course Not FOUND');
                         error_log(print_r($item_result, 1));
                         exit;
                     }
-                    $handler_id = $item_result['code'];                  
+                    $handler_id = $item_result['code'];
                     break;
                 case 'user':
-                    if (!empty($item_result)) {                        
+                    if (!empty($item_result)) {
                         $handler_id = $item_result['user_id'];
                         //error_log($dest_row['email'].' '.$dest_row['uidIdPersona']);
                         if (isset($dest_row['uidIdAlumno'])) {
@@ -292,32 +493,32 @@ class Migration {
                         if (isset($dest_row['uidIdEmpleado'])) {
                             //print_r($dest_row['uidIdEmpleado']);exit;                           
                             //$this->data_list['users_empleado'][$dest_row['uidIdEmpleado']]['extra'] = $item_result;
-                        }                                          
+                        }
                     } else {
                         global $api_failureList;
-                        error_log(print_r($api_failureList, 1));                        
-                    }       
+                        error_log(print_r($api_failureList, 1));
+                    }
                     break;
-                case 'session':                     
+                case 'session':
                     //$this->data_list['sessions'][$dest_row['uidIdPrograma']] = $item_result;                    
                     $handler_id = $item_result; //session_id
                     break;
             }
-            
+
             //Saving extra fields of the element
             if (!empty($extra_fields_to_insert)) {
-                foreach ($extra_fields_to_insert as $params) {                    
-                    $params[$extra_field_value_obj->handler_id] =  $handler_id;                                             
-                    $extra_field_value_obj->save($params);    
+                foreach ($extra_fields_to_insert as $params) {
+                    $params[$extra_field_value_obj->handler_id] = $handler_id;
+                    $extra_field_value_obj->save($params);
                 }
             }
         } else {
-           // $this->errors_stack[] = "No destination data dest_func found. Abandoning data with first field $first_field = " . $dest_row[$first_field];
+            // $this->errors_stack[] = "No destination data dest_func found. Abandoning data with first field $first_field = " . $dest_row[$first_field];
         }
         unset($extra_fields_to_insert); //remove to free up memory
         return $dest_row;
     }
-    
+
     /**
      * Helper function to create extra fields in the Chamilo database
      * @param Array An array containing an 'extra_fields' entry with details about the required extra fields
@@ -325,43 +526,44 @@ class Migration {
      */
     private function _create_extra_fields(&$table) {
         $extra_fields = array();
-        
-        error_log('Inserting (if exists) extra fields for : ' . $table['dest_table']." \n");
+
+        error_log('Inserting (if exists) extra fields for : ' . $table['dest_table'] . " \n");
         foreach ($table['extra_fields'] as $extra_field) {
-            error_log('Preparing for insertion of extra field '.$extra_field['field_display_text']."\n");
+            error_log('Preparing for insertion of extra field ' . $extra_field['field_display_text'] . "\n");
             $options = isset($extra_field['options']) ? $extra_field['options'] : null;
             unset($extra_field['options']);
-            
+
             $extra_field_obj = new ExtraField($table['dest_table']);
             $extra_field_id = $extra_field_obj->save($extra_field);
-                    
+
             $selected_fields = self::prepare_field_match($options);
-                        
+
             //Adding options
-            if (!empty($options)) {       
+            if (!empty($options)) {
                 $extra_field_option_obj = new ExtraFieldOption($table['dest_table']);
-                $this->select_all($options['orig_table'], $selected_fields);                        
+                $this->select_all($options['orig_table'], $selected_fields);
                 $num_rows = $this->num_rows();
 
                 if ($num_rows) {
                     $data_to_insert = array();
                     $data_to_insert['field_id'] = $extra_field_id;
 
-                    while ($row = $this->fetch_array()) { 
-                        $data = self::execute_field_match($options, $row);                                
-                        $data_to_insert = array_merge($data_to_insert, $data);                                                              
+                    while ($row = $this->fetch_array()) {
+                        $data = self::execute_field_match($options, $row);
+                        $data_to_insert = array_merge($data_to_insert, $data);
                         $extra_field_option_obj->save_one_item($data_to_insert, false, false);
                         //error_log(print_r($extra_fields[$table['dest_table']]['extra_field_'.$extra_field['field_variable']], 1));
-                        $extra_fields[$table['dest_table']]['extra_field_'.$extra_field['field_variable']]['options'][] = $data_to_insert;                                
-                        $extra_fields[$table['dest_table']]['extra_field_'.$extra_field['field_variable']]['field_type'] = $extra_field['field_type'];
+                        $extra_fields[$table['dest_table']]['extra_field_' . $extra_field['field_variable']]['options'][] = $data_to_insert;
+                        $extra_fields[$table['dest_table']]['extra_field_' . $extra_field['field_variable']]['field_type'] = $extra_field['field_type'];
                     }
                     //$extra_fields[$table['dest_table']]['extra_field_'.$extra_field['field_variable']]['selected_option'] = 
                     //error_log('$data: ' . print_r($data_to_insert, 1));
                 }
             } else {
-                $extra_fields[$table['dest_table']]['extra_field_'.$extra_field['field_variable']] = $extra_field_id;
+                $extra_fields[$table['dest_table']]['extra_field_' . $extra_field['field_variable']] = $extra_field_id;
             }
         }
         return $extra_fields;
     }
+
 }

+ 134 - 55
tests/migrate/migration.custom.class.php

@@ -49,13 +49,6 @@ class MigrationCustom {
         }
         return " cast( $field  as varchar(50)) as $as_field ";
     }
- 
-    /**
-     * Log data from the original users table
-     */
-    static function log_original_user_unique_id($data, &$omigrate, $row_data) {        
-        //return $row_data['uidIdAlumno'];
-    }
     
     static function clean_utf8($value) {
         return utf8_encode($value);        
@@ -65,49 +58,7 @@ class MigrationCustom {
         return self::clean_utf8($row_data['session_name']);        
     }
     
-    /** @deprecated */
-    static function log_original_persona_unique_id($data, &$omigrate, $row_data) {  
-/* Temporarily commented
-        if (isset($omigrate['users_persona'][$row_data['uidIdPersona']])) {
-            $omigrate['users_persona'][$row_data['uidIdPersona']][] = $omigrate['users_persona'][$row_data['uidIdPersona']];
-            //$omigrate['users_persona'][$row_data['uidIdPersona']][] = $row_data;
-            //error_log(print_r($row_data, 1));
-            //error_log(print_r($omigrate['users_persona'][$row_data['uidIdPersona']], 1));            
-            error_log('WHAT??');
-        } else {
-            //$omigrate['users_persona'][$row_data['uidIdPersona']] = $row_data;
-            $omigrate['users_persona'][$row_data['uidIdPersona']] = $row_data['uidIdPersona'];
-        }
-*/
-        return $data;
-    }
-    
-    /** @deprecated */
-    static function log_original_teacher_unique_id($data, &$omigrate, $row_data) {        
-        $row = array('uidIdPersona' => $row_data['uidIdPersona'], 'uidIdEmpleado' => $row_data['uidIdEmpleado']);
-        $omigrate['users_empleado'][$row_data['uidIdEmpleado']] = $row;
-        return $row_data['uidIdEmpleado'];               
-    }
-
-    /**
-     * Log data from the original users table
-      @deprecated
-     */
-    static function log_original_course_unique_id($data, &$omigrate) {
-        $omigrate['courses'][$data] = 0; 
-        return $data;
-    }
-
-    /**
-     * Log data from the original users table
-     * @deprecated
-     */
-    static function log_original_session_unique_id($data, &$omigrate, $row_data) {
-        $omigrate['sessions'][$row_data['uidIdPrograma']] = $row_data;
-        return $data;
-    }
-    
-    static function get_real_course_code($data, &$omigrate, $row_data) {        
+    static function get_real_course_code($data) {        
         $extra_field = new ExtraFieldValue('course');
         $values = $extra_field->get_item_id_from_field_variable_and_field_value('uidIdCurso', $data);        
         if ($values) {
@@ -117,9 +68,9 @@ class MigrationCustom {
         }
     }
     
-    static function get_session_id_by_programa_id($data, &$omigrate, $row_data) {        
+    static function get_session_id_by_programa_id($uidIdProgram) {        
         $extra_field = new ExtraFieldValue('session');
-        $values = $extra_field->get_item_id_from_field_variable_and_field_value('uidIdPrograma', $data);        
+        $values = $extra_field->get_item_id_from_field_variable_and_field_value('uidIdPrograma', $uidIdProgram);        
         if ($values) {
             return $values['session_id'];
         } else {
@@ -128,7 +79,7 @@ class MigrationCustom {
     }
     
     /* Not used */
-    static function get_user_id_by_persona_id($uidIdPersona, &$omigrate, $row_data) {        
+    static function get_user_id_by_persona_id($uidIdPersona) {
         //error_log('get_user_id_by_persona_id');
         $extra_field = new ExtraFieldValue('user');
         $values = $extra_field->get_item_id_from_field_variable_and_field_value('uidIdPersona', $uidIdPersona);        
@@ -138,9 +89,8 @@ class MigrationCustom {
             return 0;
         }
     }
-
     
-    static function get_real_teacher_id($uidIdPersona, &$omigrate, $row_data) {
+    static function get_real_teacher_id($uidIdPersona) {
         $default_teacher_id = self::default_admin_id;       
         if (empty($uidIdPersona)) {
             //error_log('No teacher provided');
@@ -695,4 +645,133 @@ class MigrationCustom {
             error_log("NO session id found: $session_id");
         }
     }
+    
+    //añadir usuario: usuario_agregar UID
+    static function transaction_usuario_agregar($data) {
+         $uidIdPersonaId = $data['item_id'];
+         $orig_uidIdPersonaId = $data['orig_id'];
+         $dest_uidIdPersonaId = $data['dest_id'];         
+         //Add user call the webservice
+    }
+    
+    //eliminar usuario usuario_eliminar UID
+    static function transaction_usuario_eliminar($data) {
+        $uidIdPersonaId = $data['item_id'];
+        $user_id = self::get_user_id_by_persona_id($uidIdPersonaId);
+        if ($user_id) {
+            UserManager::delete_user($user_id);
+        }        
+    }
+    
+    //editar detalles de usuario (nombre/correo/contraseña) usuario_editar UID
+    static function transaction_usuario_editar($data) {
+        $uidIdPersonaId = $data['item_id'];
+        $user_id = self::get_user_id_by_persona_id($uidIdPersonaId);
+        if ($user_id) {
+            //Edit user
+        }   
+    }
+    
+    //cambiar usuario de progr. académ. (de A a B, de A a nada, de nada a A) (como estudiante o profesor) usuario_matricula UID ORIG DEST
+    static function transaction_usuario_matricula($data) {
+        
+    }
+    
+    //Cursos
+    //añadir curso curso_agregar CID
+    static function transaction_curso_agregar($data) {
+        
+    }
+    //eliminar curso curso_eliminar CID
+    static function transaction_curso_eliminar($data) {
+        
+    }
+    //editar detalles de curso curso_editar CID
+    static function transaction_curso_editar($data) {
+        
+    }
+    
+    //cambiar curso de progr. académ. (de nada a A) curso_matricula CID ORIG DEST
+    static function transaction_curso_matricula($data) {
+        
+    }
+    //cambiar intensidad pa_cambiar_fase_intensidad CID ORIG DEST (id de "intensidadFase")
+    static function transaction_pa_cambiar_fase_intensidad($data) {
+        
+    }
+    
+    //Programas académicos
+    //añadir p.a. pa_agregar PID
+    //eliminar p.a. pa_eliminar PID
+    //editar detalles de p.a. pa_editar PID
+    //cambiar aula pa_cambiar_aula PID ORIG DEST
+    //cambiar horario pa_cambiar_horario PID ORIG DEST
+    //cambiar sede pa_cambiar_sede PID ORIG DEST
+
+    //        Horario
+    //            añadir horario_agregar HID
+    static function transaction_horario_agregar($data) {
+        
+    }
+    //            eliminar horario_eliminar HID
+    static function transaction_horario_eliminar($data) {
+        
+    }
+    //            editar horario_editar HID
+    static function transaction_horario_editar($data) {
+        
+    }
+    // Aula
+    //            añadir aula_agregar AID
+    static function transaction_aula_agregar($data) {
+        
+    }
+    //            eliminar aula_eliminar AID
+    static function transaction_aula_eliminar($data) {
+        
+    }
+    //            editar aula_editor AID
+    static function transaction_aula_editar($data) {
+        
+    }
+    //        Sede
+    //            añadir aula_agregar SID
+    static function transaction_sede_agregar($data) {
+        
+    }
+    //            eliminar aula_eliminar SID
+    static function transaction_sede_eliminar($data) {
+        
+    }
+    //            editar aula_editar SID
+    static function transaction_sede_editar($data) {
+        
+    }
+    //
+    //        Frecuencia
+    //            añadir frec FID
+    static function transaction_frecuencia_agregar($data) {
+        
+    }
+    //            eliminar Freca_eliminar FID
+    static function transaction_frecuencia_eliminar($data) {
+        
+    }
+    //             editar aula_editar FID
+    static function transaction_frecuencia_editar($data) {
+        
+    }
+    //
+    //        Intensidad/Fase
+    //            añadir intfase_agregar IID
+    static function transaction_intfase_agregar($data) {
+        
+    }
+    //            eliminar intfase_eliminar IID
+    static function transaction_intfase_eliminar($data) {
+        
+    }
+    //            editar intfase_editar IID
+    static function transaction_intfase_editar($data) {
+    }
 }