|
|
|
|
@ -48,10 +48,10 @@ class Migration { |
|
|
|
|
/** |
|
|
|
|
* Temporary handler for SQL result |
|
|
|
|
*/ |
|
|
|
|
public $odbrows = null; |
|
|
|
|
public $odbrows = null; |
|
|
|
|
|
|
|
|
|
public $web_service_connection_info = array(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* The constructor assigns all database connection details to the migration |
|
|
|
|
* object |
|
|
|
|
@ -73,7 +73,7 @@ class Migration { |
|
|
|
|
$this->odbuser = $dbuser; |
|
|
|
|
$this->odbpass = $dbpass; |
|
|
|
|
$this->odbname = $dbname; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set the boost level if set in config.php |
|
|
|
|
if (!empty($boost) && is_array($boost)) { |
|
|
|
|
global $data_list; |
|
|
|
|
@ -91,8 +91,8 @@ class Migration { |
|
|
|
|
public function connect() { |
|
|
|
|
//extend in child class |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function set_web_service_connection_info($matches) { |
|
|
|
|
|
|
|
|
|
public function set_web_service_connection_info($matches) { |
|
|
|
|
$this->web_service_connection_info = $matches['web_service_calls']; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -117,7 +117,7 @@ class Migration { |
|
|
|
|
$build_only = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Creating extra fields if necessary inside Chamilo (to store |
|
|
|
|
// 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); |
|
|
|
|
@ -160,7 +160,7 @@ class Migration { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Call the SOAP web service as detailed in the parameters |
|
|
|
|
* @param array Settings for the WS call |
|
|
|
|
@ -168,18 +168,18 @@ class Migration { |
|
|
|
|
* @param array Variables to be passed as params to the function |
|
|
|
|
* @return array Results as returned by the SOAP call |
|
|
|
|
*/ |
|
|
|
|
static function soap_call($web_service_params, $function_name, $params = array()) { |
|
|
|
|
static function soap_call($web_service_params, $function_name, $params = array()) { |
|
|
|
|
// Create the client instance |
|
|
|
|
$url = $web_service_params['url']; |
|
|
|
|
$url = $web_service_params['url']; |
|
|
|
|
try { |
|
|
|
|
$client = new SoapClient($url); |
|
|
|
|
} catch (SoapFault $fault) { |
|
|
|
|
$error = 1; |
|
|
|
|
die('Error connecting'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$client->debug_flag = true; |
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
$client->debug_flag = true; |
|
|
|
|
try { |
|
|
|
|
$data = $client->$function_name($params); |
|
|
|
|
} catch (SoapFault $fault) { |
|
|
|
|
$error = 2; |
|
|
|
|
@ -190,25 +190,25 @@ class Migration { |
|
|
|
|
'status_id' => 0 |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($data)) { |
|
|
|
|
error_log("Calling MigrationCustom::$function_name $url with params: ".print_r($params,1)); |
|
|
|
|
return MigrationCustom::$function_name($data, $params); |
|
|
|
|
return MigrationCustom::$function_name($data, $params); |
|
|
|
|
} else { |
|
|
|
|
return array( |
|
|
|
|
'error' => true, |
|
|
|
|
'message' => "No data found when calling $function_name in URL $url with params: ".print_r($params, 1), |
|
|
|
|
'status_id' => 0 |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function clean_all_transactions() { |
|
|
|
|
$table = Database::get_main_table(TABLE_MIGRATION_TRANSACTION); |
|
|
|
|
$table = Database::get_main_table(TABLE_BRANCH_TRANSACTION); |
|
|
|
|
$sql = "TRUNCATE $table"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Test a series of hand-crafted transactions |
|
|
|
|
* @param array of parameters that would usually get passed to the web service |
|
|
|
|
@ -218,12 +218,12 @@ class Migration { |
|
|
|
|
function insert_test_transactions($truncate = false) { |
|
|
|
|
error_log('insert_test_transactions'); |
|
|
|
|
//Just for tests |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Cleaning transaction table |
|
|
|
|
if ($truncate) { |
|
|
|
|
$this->clean_all_transactions(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$transaction_harcoded = array( |
|
|
|
|
array( |
|
|
|
|
//'action' => 'usuario_agregar', |
|
|
|
|
@ -244,7 +244,7 @@ class Migration { |
|
|
|
|
'branch_id' => 1, |
|
|
|
|
'dest_id' => null, |
|
|
|
|
'status_id' => 0 |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
array( |
|
|
|
|
'transaction_id' => 1002, |
|
|
|
|
//'action' => 'usuario_eliminar', |
|
|
|
|
@ -254,15 +254,15 @@ class Migration { |
|
|
|
|
'branch_id' => 1, |
|
|
|
|
'dest_id' => null, |
|
|
|
|
'status_id' => 0 |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
array( |
|
|
|
|
'transaction_id' => 1003, |
|
|
|
|
//'action' => 'usuario_matricula', |
|
|
|
|
'action' => 4, |
|
|
|
|
'item_id' => '95EDA88F-D729-450F-95FF-4A3989244F53', //usuario - Abel |
|
|
|
|
'item_id' => '95EDA88F-D729-450F-95FF-4A3989244F53', //usuario - Abel |
|
|
|
|
'orig_id' => null, //session orig |
|
|
|
|
'dest_id' => 'C3671999-095E-4018-9826-678BAFF595DF', //session dest |
|
|
|
|
'branch_id' => 1, |
|
|
|
|
'branch_id' => 1, |
|
|
|
|
'status_id' => 0 |
|
|
|
|
), |
|
|
|
|
array( |
|
|
|
|
@ -272,7 +272,7 @@ class Migration { |
|
|
|
|
'item_id' => 'E2334974-9D55-4BB4-8B57-FCEFBE2510DC', |
|
|
|
|
'orig_id' => null, |
|
|
|
|
'dest_id' => null, |
|
|
|
|
'branch_id' => 1, |
|
|
|
|
'branch_id' => 1, |
|
|
|
|
'status_id' => 0 |
|
|
|
|
), |
|
|
|
|
array( |
|
|
|
|
@ -282,7 +282,7 @@ class Migration { |
|
|
|
|
'item_id' => 'E2334974-9D55-4BB4-8B57-FCEFBE2510DC', |
|
|
|
|
'orig_id' => null, |
|
|
|
|
'dest_id' => null, |
|
|
|
|
'branch_id' => 1, |
|
|
|
|
'branch_id' => 1, |
|
|
|
|
'status_id' => 0 |
|
|
|
|
), |
|
|
|
|
array( |
|
|
|
|
@ -300,7 +300,7 @@ class Migration { |
|
|
|
|
'item_id' => 'E2334974-9D55-4BB4-8B57-FCEFBE2510DC', //course |
|
|
|
|
'orig_id' => null, |
|
|
|
|
'dest_id' => 'C3671999-095E-4018-9826-678BAFF595DF', //session |
|
|
|
|
'branch_id' => 1, |
|
|
|
|
'branch_id' => 1, |
|
|
|
|
'status_id' => 0 |
|
|
|
|
), |
|
|
|
|
*/ |
|
|
|
|
@ -311,7 +311,7 @@ class Migration { |
|
|
|
|
'item_id' => 'C3671999-095E-4018-9826-678BAFF595DF', |
|
|
|
|
'orig_id' => null, |
|
|
|
|
'dest_id' => null, |
|
|
|
|
'branch_id' => 1, |
|
|
|
|
'branch_id' => 1, |
|
|
|
|
'status_id' => 0 |
|
|
|
|
), |
|
|
|
|
array( |
|
|
|
|
@ -321,7 +321,7 @@ class Migration { |
|
|
|
|
'item_id' => 'C3671999-095E-4018-9826-678BAFF595DF', |
|
|
|
|
'orig_id' => '0', |
|
|
|
|
'dest_id' => null, |
|
|
|
|
'branch_id' => 1, |
|
|
|
|
'branch_id' => 1, |
|
|
|
|
'status_id' => 0 |
|
|
|
|
), |
|
|
|
|
array( |
|
|
|
|
@ -334,7 +334,7 @@ class Migration { |
|
|
|
|
'dest_id' => null, |
|
|
|
|
'status_id' => 0 |
|
|
|
|
), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* seems not to be used |
|
|
|
|
array( |
|
|
|
|
//'action' => 'pa_cambiar_aula', |
|
|
|
|
@ -342,7 +342,7 @@ class Migration { |
|
|
|
|
'item_id' => 'C3671999-095E-4018-9826-678BAFF595DF', |
|
|
|
|
'orig_id' => '0', |
|
|
|
|
'dest_id' => '', |
|
|
|
|
'branch_id' => 1, |
|
|
|
|
'branch_id' => 1, |
|
|
|
|
'status_id' => 0 |
|
|
|
|
),*/ |
|
|
|
|
array( |
|
|
|
|
@ -361,7 +361,7 @@ class Migration { |
|
|
|
|
'item_id' => 'C3671999-095E-4018-9826-678BAFF595DF',//session id |
|
|
|
|
'orig_id' => '0', |
|
|
|
|
'dest_id' => null, |
|
|
|
|
'branch_id' => 1, |
|
|
|
|
'branch_id' => 1, |
|
|
|
|
'status_id' => 0 |
|
|
|
|
), |
|
|
|
|
array( |
|
|
|
|
@ -369,7 +369,7 @@ class Migration { |
|
|
|
|
'item_id' => 'C3671999-095E-4018-9826-678BAFF595DF',//session id |
|
|
|
|
'orig_id' => '0', |
|
|
|
|
'dest_id' => null, |
|
|
|
|
'branch_id' => 1, |
|
|
|
|
'branch_id' => 1, |
|
|
|
|
'status_id' => 0 |
|
|
|
|
), |
|
|
|
|
array( |
|
|
|
|
@ -398,17 +398,17 @@ class Migration { |
|
|
|
|
'item_id' => 'E395895A-B480-456F-87F2-36B3A1EBB81C', |
|
|
|
|
'orig_id' => '0', |
|
|
|
|
'dest_id' => null, |
|
|
|
|
'branch_id' => 1, |
|
|
|
|
'branch_id' => 1, |
|
|
|
|
'status_id' => 0 |
|
|
|
|
), |
|
|
|
|
array( |
|
|
|
|
//'action' => 'horario_eliminar', |
|
|
|
|
//'action' => 'horario_eliminar', |
|
|
|
|
'action' => 14, |
|
|
|
|
'transaction_id' => 1012, |
|
|
|
|
'item_id' => 'E395895A-B480-456F-87F2-36B3A1EBB81C', |
|
|
|
|
'orig_id' => '0', |
|
|
|
|
'dest_id' => null, |
|
|
|
|
'branch_id' => 1, |
|
|
|
|
'branch_id' => 1, |
|
|
|
|
'status_id' => 0 |
|
|
|
|
), |
|
|
|
|
/* |
|
|
|
|
@ -441,7 +441,7 @@ class Migration { |
|
|
|
|
), |
|
|
|
|
* */ |
|
|
|
|
array( |
|
|
|
|
//'action' => 'sede_agregar', |
|
|
|
|
//'action' => 'sede_agregar', |
|
|
|
|
'action' => 19, |
|
|
|
|
'transaction_id' => 1013, |
|
|
|
|
'item_id' => '7379A7D3-6DC5-42CA-9ED4-97367519F1D9', |
|
|
|
|
@ -451,7 +451,7 @@ class Migration { |
|
|
|
|
'status_id' => 0 |
|
|
|
|
), |
|
|
|
|
array( |
|
|
|
|
//'action' => 'sede_editar', |
|
|
|
|
//'action' => 'sede_editar', |
|
|
|
|
'action' => 21, |
|
|
|
|
'transaction_id' => 1014, |
|
|
|
|
'item_id' => '7379A7D3-6DC5-42CA-9ED4-97367519F1D9', |
|
|
|
|
@ -471,7 +471,7 @@ class Migration { |
|
|
|
|
'status_id' => 0 |
|
|
|
|
), |
|
|
|
|
array( |
|
|
|
|
//'action' => 'frecuencia_agregar', |
|
|
|
|
//'action' => 'frecuencia_agregar', |
|
|
|
|
'action' => 22, |
|
|
|
|
'transaction_id' => 1016, |
|
|
|
|
'item_id' => '0091CD3B-F042-11D7-B338-0050DAB14015', |
|
|
|
|
@ -531,14 +531,14 @@ class Migration { |
|
|
|
|
'status_id' => 0 |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach( $transaction_harcoded as $transaction) { |
|
|
|
|
$transaction['branch_id'] = 2; |
|
|
|
|
if ($transaction['action'] != 21) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
self::add_transaction($transaction); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -548,25 +548,25 @@ class Migration { |
|
|
|
|
*/ |
|
|
|
|
static function add_transaction($params) { |
|
|
|
|
//error_log('Requested add_transaction of : '.print_r($params,1)); |
|
|
|
|
$table = Database::get_main_table(TABLE_MIGRATION_TRANSACTION); |
|
|
|
|
$table = Database::get_main_table(TABLE_BRANCH_TRANSACTION); |
|
|
|
|
if (isset($params['id'])) { |
|
|
|
|
unset($params['id']); |
|
|
|
|
} |
|
|
|
|
$params['time_update'] = $params['time_insert'] = api_get_utc_datetime(); |
|
|
|
|
|
|
|
|
|
$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; |
|
|
|
|
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) |
|
|
|
|
*/ |
|
|
|
|
static function get_branches() { |
|
|
|
|
$table = Database::get_main_table(TABLE_MIGRATION_TRANSACTION); |
|
|
|
|
$table = Database::get_main_table(TABLE_BRANCH_TRANSACTION); |
|
|
|
|
$sql = "SELECT DISTINCT branch_id FROM $table ORDER BY branch_id"; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
if (Database::num_rows($result) > 0) { |
|
|
|
|
@ -580,7 +580,7 @@ class Migration { |
|
|
|
|
4=>array('branch_id' => 5), |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Gets transactions in a specific state (for example to get all non-processed transactions) from the Chamilo transactions table |
|
|
|
|
* @param int State ID (0=unprocessed (default), 2=completed) |
|
|
|
|
@ -588,49 +588,49 @@ class Migration { |
|
|
|
|
* @return array Associative array containing the details of the transactions requested |
|
|
|
|
*/ |
|
|
|
|
static function get_transactions($status_id = 0, $branch_id = 0) { |
|
|
|
|
$table = Database::get_main_table(TABLE_MIGRATION_TRANSACTION); |
|
|
|
|
$table = Database::get_main_table(TABLE_BRANCH_TRANSACTION); |
|
|
|
|
$branch_id = intval($branch_id); |
|
|
|
|
$status_id = intval($status_id); |
|
|
|
|
|
|
|
|
|
$extra_conditions = " AND branch_id = $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'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static function get_transaction_by_transaction_id($transaction_id, $branch_id) { |
|
|
|
|
$table = Database::get_main_table(TABLE_MIGRATION_TRANSACTION); |
|
|
|
|
$table = Database::get_main_table(TABLE_BRANCH_TRANSACTION); |
|
|
|
|
$transaction_id = intval($transaction_id); |
|
|
|
|
$branch_id = intval($branch_id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($transaction_id) && !empty($branch_id)) { |
|
|
|
|
$sql = "SELECT * FROM $table WHERE transaction_id = $transaction_id AND branch_id = $branch_id"; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
if (Database::num_rows($result)) { |
|
|
|
|
return Database::fetch_array($result, 'ASSOC'); |
|
|
|
|
return Database::fetch_array($result, 'ASSOC'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static function delete_transaction_by_transaction_id($transaction_id, $branch_id) { |
|
|
|
|
$table = Database::get_main_table(TABLE_MIGRATION_TRANSACTION); |
|
|
|
|
$table = Database::get_main_table(TABLE_BRANCH_TRANSACTION); |
|
|
|
|
$transaction_id = intval($transaction_id); |
|
|
|
|
$branch_id = intval($branch_id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($transaction_id) && !empty($branch_id)) { |
|
|
|
|
$sql = "DELETE FROM $table WHERE transaction_id = $transaction_id AND branch_id = $branch_id"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 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 |
|
|
|
|
* @return int The ID of the latest transaction |
|
|
|
|
*/ |
|
|
|
|
static function get_latest_completed_transaction_by_branch($branch_id) { |
|
|
|
|
$table = Database::get_main_table(TABLE_MIGRATION_TRANSACTION); |
|
|
|
|
$table = Database::get_main_table(TABLE_BRANCH_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); |
|
|
|
|
@ -640,18 +640,18 @@ class Migration { |
|
|
|
|
} |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Gets the latest locally-recorded transaction for a specific branch |
|
|
|
|
* @param int The ID of the branch |
|
|
|
|
* @return int The ID of the last transaction registered |
|
|
|
|
*/ |
|
|
|
|
static function get_latest_transaction_id_by_branch($branch_id) { |
|
|
|
|
$table = Database::get_main_table(TABLE_MIGRATION_TRANSACTION); |
|
|
|
|
$table = Database::get_main_table(TABLE_BRANCH_TRANSACTION); |
|
|
|
|
$branch_id = intval($branch_id); |
|
|
|
|
$sql = "SELECT transaction_id FROM $table |
|
|
|
|
WHERE branch_id = $branch_id |
|
|
|
|
ORDER BY transaction_id DESC |
|
|
|
|
$sql = "SELECT transaction_id FROM $table |
|
|
|
|
WHERE branch_id = $branch_id |
|
|
|
|
ORDER BY transaction_id DESC |
|
|
|
|
LIMIT 1"; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
if (Database::num_rows($result)) { |
|
|
|
|
@ -660,7 +660,7 @@ class Migration { |
|
|
|
|
} |
|
|
|
|
return 376012; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Gets a specific transaction using select parameters |
|
|
|
|
* @param array Select parameters (associative array) |
|
|
|
|
@ -668,72 +668,72 @@ class Migration { |
|
|
|
|
* @return array Results as requested |
|
|
|
|
*/ |
|
|
|
|
static function get_transaction_by_params($params, $type_result = 'all') { |
|
|
|
|
$table = Database::get_main_table(TABLE_MIGRATION_TRANSACTION); |
|
|
|
|
$table = Database::get_main_table(TABLE_BRANCH_TRANSACTION); |
|
|
|
|
return Database::select('*', $table, $params, $type_result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Updates a transaction using the given query parameters |
|
|
|
|
* @param array Query parameters |
|
|
|
|
* @return bool The result of the transaction row update |
|
|
|
|
*/ |
|
|
|
|
*/ |
|
|
|
|
static function update_transaction($params) { |
|
|
|
|
//return false; |
|
|
|
|
$table = Database::get_main_table(TABLE_MIGRATION_TRANSACTION); |
|
|
|
|
$table = Database::get_main_table(TABLE_BRANCH_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']} with status_id = {$params['status_id']}"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Failed - do something else |
|
|
|
|
if ($params['status_id'] == MigrationCustom::TRANSACTION_STATUS_FAILED) { |
|
|
|
|
//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'])); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Search for new transactions through a web service call. Automatically insert them in the local transactions table. |
|
|
|
|
* @param array The web service parameters |
|
|
|
|
* @param int the branch id optional |
|
|
|
|
* @param int An optional transaction ID to start from. Branch id must be selected if you use this option. |
|
|
|
|
* @param int An optional transaction ID to start from. Branch id must be selected if you use this option. |
|
|
|
|
* If none provided, fetches the latest transaction available and add + 1 |
|
|
|
|
* @return The operation results |
|
|
|
|
*/ |
|
|
|
|
function get_transactions_from_webservice($params = array()) { |
|
|
|
|
error_log("get_transactions_from_webservice() function called \n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$branch_id = isset($params['branch_id']) ? $params['branch_id'] : null; |
|
|
|
|
$transaction_id = isset($params['transaction_id']) ? $params['transaction_id'] : null; |
|
|
|
|
$number_of_transactions = isset($params['number_of_transactions']) ? $params['number_of_transactions'] : 2; |
|
|
|
|
|
|
|
|
|
//Testing transactions |
|
|
|
|
|
|
|
|
|
//Testing transactions |
|
|
|
|
$web_service_params = $this->web_service_connection_info; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*$result = self::soap_call($web_service_params,'usuarioDetalles', array('uididpersona' => 'D236776B-D7A5-47FF-8328-55EBE9A59015')); |
|
|
|
|
$result = self::soap_call($web_service_params,'programaDetalles', array('uididprograma' => 'C3671999-095E-4018-9826-678BAFF595DF')); |
|
|
|
|
$result = self::soap_call($web_service_params,'cursoDetalles', array('uididcurso' => 'E2334974-9D55-4BB4-8B57-FCEFBE2510DC')); |
|
|
|
|
$result = self::soap_call($web_service_params,'cursoDetalles', array('uididcurso' => 'E2334974-9D55-4BB4-8B57-FCEFBE2510DC')); |
|
|
|
|
$result = self::soap_call($web_service_params,'faseDetalles', array('uididfase' => 'EBF63F1C-FBD7-46A5-B039-80B5AF064929')); |
|
|
|
|
$result = self::soap_call($web_service_params,'frecuenciaDetalles', array('uididfrecuencia' => '0091CD3B-F042-11D7-B338-0050DAB14015')); |
|
|
|
|
$result = self::soap_call($web_service_params,'intensidadDetalles', array('uididintensidad' => '0091CD3C-F042-11D7-B338-0050DAB14015')); |
|
|
|
|
$result = self::soap_call($web_service_params,'mesesDetalles', array('uididfase' => 'EBF63F1C-FBD7-46A5-B039-80B5AF064929')); |
|
|
|
|
$result = self::soap_call($web_service_params,'sedeDetalles', array('uididsede' => '7379A7D3-6DC5-42CA-9ED4-97367519F1D9')); |
|
|
|
|
$result = self::soap_call($web_service_params,'horarioDetalles', array('uididhorario' => 'E395895A-B480-456F-87F2-36B3A1EBB81C')); |
|
|
|
|
$result = self::soap_call($web_service_params,'transacciones', array('ultimo' => 354911, 'cantidad' => 2)); |
|
|
|
|
$result = self::soap_call($web_service_params,'sedeDetalles', array('uididsede' => '7379A7D3-6DC5-42CA-9ED4-97367519F1D9')); |
|
|
|
|
$result = self::soap_call($web_service_params,'horarioDetalles', array('uididhorario' => 'E395895A-B480-456F-87F2-36B3A1EBB81C')); |
|
|
|
|
$result = self::soap_call($web_service_params,'transacciones', array('ultimo' => 354911, 'cantidad' => 2)); |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (empty($branch_id)) { |
|
|
|
|
$branches = self::get_branches(); |
|
|
|
|
} else { |
|
|
|
|
$branches = array('branch_id' => $branch_id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
error_log(count($branches)." branches found \n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($branches)) { |
|
|
|
|
foreach ($branches as $branch) { |
|
|
|
|
if (!empty($branch_id) && !empty($transaction_id)) { |
|
|
|
|
@ -747,12 +747,12 @@ class Migration { |
|
|
|
|
'ultimo' => $last_transaction_id, |
|
|
|
|
'cantidad' => isset($number_of_transactions) && !empty($number_of_transactions) ? $number_of_transactions : 2, |
|
|
|
|
'intIdSede' => $branch['branch_id'], |
|
|
|
|
); |
|
|
|
|
); |
|
|
|
|
error_log("Branch #".$branch['branch_id']." - treating $number_of_transactions transaction(s) starting with transaction #$last_transaction_id \n"); |
|
|
|
|
MigrationCustom::process_transactions($params, $web_service_params); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Loads a specific set of transactions from the transactions table and executes them |
|
|
|
|
@ -765,36 +765,36 @@ class Migration { |
|
|
|
|
$branch_id = isset($params['branch_id']) ? $params['branch_id'] : null; |
|
|
|
|
//$transaction_id = isset($params['transaction_id']) ? $params['transaction_id'] : null; |
|
|
|
|
//$number_of_transactions = isset($params['number_of_transactions']) ? $params['number_of_transactions'] : 2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Getting transactions of the migration_transaction table |
|
|
|
|
if (empty($branch_id)) { |
|
|
|
|
$branches = self::get_branches(); |
|
|
|
|
} else { |
|
|
|
|
$branches = array('branch_id' => $branch_id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($branches)) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
error_log(count($branches)." branch(es) found \n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($branches as $branch_info) { |
|
|
|
|
//Get uncompleted transactions |
|
|
|
|
$transactions = self::get_transactions(0, $branch_info['branch_id']); |
|
|
|
|
|
|
|
|
|
//Get uncompleted transactions |
|
|
|
|
$transactions = self::get_transactions(0, $branch_info['branch_id']); |
|
|
|
|
|
|
|
|
|
//Getting latest executed transaction |
|
|
|
|
$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'); |
|
|
|
|
$transaction_info = self::get_transaction_by_params($options, 'first'); |
|
|
|
|
$latest_id_attempt = 1; |
|
|
|
|
if ($transaction_info) { |
|
|
|
|
$latest_id = $transaction_info['id']; |
|
|
|
|
if ($transaction_info) { |
|
|
|
|
$latest_id = $transaction_info['id']; |
|
|
|
|
$latest_id_attempt = $latest_id + 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$count = count($transactions); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$count = count($transactions); |
|
|
|
|
|
|
|
|
|
$item = 1;//counter |
|
|
|
|
if (!empty($transactions)) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
error_log("Branch #".$branch_info['branch_id']." called, $count transaction(s) found starting with transaction #$latest_id_attempt \n"); |
|
|
|
|
|
|
|
|
|
//Looping transactions |
|
|
|
|
@ -807,7 +807,7 @@ class Migration { |
|
|
|
|
error_log("\nProcessing transaction #{$transaction['id']} $percentage%"); |
|
|
|
|
} |
|
|
|
|
$item++; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
error_log("\nWaiting for transaction #$latest_id_attempt ..."); |
|
|
|
|
|
|
|
|
|
//Checking "huecos" |
|
|
|
|
@ -815,9 +815,9 @@ class Migration { |
|
|
|
|
if ($transaction['id'] == $latest_id_attempt) { |
|
|
|
|
$latest_id_attempt++; |
|
|
|
|
} else { |
|
|
|
|
error_log("Transaction #$latest_id_attempt is missing in branch #{$branch_info['branch_id']} \n"); |
|
|
|
|
error_log("Transaction #$latest_id_attempt is missing in branch #{$branch_info['branch_id']} \n"); |
|
|
|
|
} |
|
|
|
|
$result = $this->execute_transaction($transaction); |
|
|
|
|
$result = $this->execute_transaction($transaction); |
|
|
|
|
error_log($result['message']); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -837,10 +837,10 @@ class Migration { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function execute_transaction($transaction_info) { |
|
|
|
|
//Loading function. The action is now numeric, so we call a transaction_1() function, for example |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$validate = MigrationCustom::validate_transaction($transaction_info); |
|
|
|
|
if (isset($validate['error']) && $validate['error']) { |
|
|
|
|
return $validate; |
|
|
|
|
@ -848,26 +848,26 @@ class Migration { |
|
|
|
|
error_log("\n-----------------------------------------------------------------------"); |
|
|
|
|
error_log("Executing transaction ".$transaction_info['id']); |
|
|
|
|
error_log("\n-----------------------------------------------------------------------"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$function_to_call = "transaction_" . $transaction_info['action']; |
|
|
|
|
if (method_exists('MigrationCustom', $function_to_call)) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
error_log("\nCalling function MigrationCustom::$function_to_call()"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$result = MigrationCustom::$function_to_call($transaction_info, $this->web_service_connection_info); |
|
|
|
|
$result['message'] = "\nFunction reponse: ".$result['message']; |
|
|
|
|
$result['message'] = "\nFunction reponse: ".$result['message']; |
|
|
|
|
//error_log('Reponse: '.$result['message']); |
|
|
|
|
if (!empty($transaction_info['id'])) { |
|
|
|
|
self::update_transaction(array('id' => $transaction_info['id'] , 'status_id' => $result['status_id'])); |
|
|
|
|
self::update_transaction(array('id' => $transaction_info['id'] , 'status_id' => $result['status_id'])); |
|
|
|
|
} else { |
|
|
|
|
error_log("Cant update transaction, id was not provided"); |
|
|
|
|
error_log("Cant update transaction, id was not provided"); |
|
|
|
|
} |
|
|
|
|
return $result; |
|
|
|
|
} else { |
|
|
|
|
// method does not exist |
|
|
|
|
$error_message = "Function $function_to_call does not exists"; |
|
|
|
|
error_log($error_message); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Failed |
|
|
|
|
if (!empty($transaction_info['id'])) { |
|
|
|
|
self::update_transaction(array('id' => $transaction_info['id'] , 'status_id' => MigrationCustom::TRANSACTION_STATUS_FAILED)); |
|
|
|
|
@ -875,37 +875,37 @@ class Migration { |
|
|
|
|
return array('message' => $error_message); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* |
|
|
|
|
* @param int Transaction id of the third party |
|
|
|
|
* |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* |
|
|
|
|
* @param int Transaction id of the third party |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
function load_transaction_by_third_party_id($transaction_external_id, $branch_id, $forced = false) { |
|
|
|
|
function load_transaction_by_third_party_id($transaction_external_id, $branch_id, $forced = false) { |
|
|
|
|
//Asking for 2 transactions by getting 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$params = array( |
|
|
|
|
'ultimo' => $transaction_external_id, |
|
|
|
|
'ultimo' => $transaction_external_id, |
|
|
|
|
'cantidad' => 1, |
|
|
|
|
'intIdSede' => $branch_id |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$result = self::soap_call($this->web_service_connection_info, 'transacciones', $params); |
|
|
|
|
|
|
|
|
|
//Hacking webservice default result |
|
|
|
|
|
|
|
|
|
//Hacking webservice default result |
|
|
|
|
if ($result && isset($result[0])) { |
|
|
|
|
//Getting 1 transaction |
|
|
|
|
$result = $result[0]; |
|
|
|
|
|
|
|
|
|
$transaction_external_id++; |
|
|
|
|
$result = $result[0]; |
|
|
|
|
|
|
|
|
|
$transaction_external_id++; |
|
|
|
|
if ($result['idt'] == $transaction_external_id) { |
|
|
|
|
$message = Display::return_message('Transaction id found in third party', 'info'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Adding third party transaction to Chamilo |
|
|
|
|
$transaction_result = MigrationCustom::process_transaction($result, null, $forced); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$transaction_chamilo_info = array(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($transaction_result['error'] == false) { |
|
|
|
|
$chamilo_transaction_id = $transaction_result['id']; |
|
|
|
|
$message .= Display::return_message($transaction_result['message'], 'info'); |
|
|
|
|
@ -914,20 +914,20 @@ class Migration { |
|
|
|
|
$transaction_chamilo_info = $transaction_chamilo_info[$chamilo_transaction_id]; |
|
|
|
|
} else { |
|
|
|
|
$transaction_chamilo_info = null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
$message .= Display::return_message("Transaction NOT added to Chamilo. {$transaction_result['message']}", 'warning'); |
|
|
|
|
//$transaction_chamilo_info = MigrationCustom::process_transaction($result, false); |
|
|
|
|
//$transaction_chamilo_info = MigrationCustom::process_transaction($result, false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($transaction_chamilo_info)) { |
|
|
|
|
$transaction_result = $this->execute_transaction($transaction_chamilo_info); |
|
|
|
|
if ($transaction_result) { |
|
|
|
|
$message .= Display::page_subheader("Transaction result:"); |
|
|
|
|
$message .= nl2br($transaction_result['message']); |
|
|
|
|
$message .= "<br />"; |
|
|
|
|
|
|
|
|
|
if (isset($transaction_result['entity']) && !empty($transaction_result['entity'])) { |
|
|
|
|
|
|
|
|
|
if (isset($transaction_result['entity']) && !empty($transaction_result['entity'])) { |
|
|
|
|
$message .= Display::page_subheader2("Entity {$transaction_result['entity']} before:"); |
|
|
|
|
$message .= "<pre>".print_r($transaction_result['before'], 1)."</pre>"; |
|
|
|
|
$message .= "<br />"; |
|
|
|
|
@ -935,28 +935,28 @@ class Migration { |
|
|
|
|
$message .= Display::page_subheader2("Entity {$transaction_result['entity']} after:"); |
|
|
|
|
$message .= "<pre>".print_r($transaction_result['after'], 1)."</pre>"; |
|
|
|
|
$message .= "<br />"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
$message .= Display::return_message("Transaction failed", 'error'); |
|
|
|
|
$message .= Display::return_message("Transaction failed", 'error'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return array( |
|
|
|
|
'message' => $message, |
|
|
|
|
'raw_reponse' => |
|
|
|
|
//Display::page_subheader2("Transactions:"). |
|
|
|
|
'raw_reponse' => |
|
|
|
|
//Display::page_subheader2("Transactions:"). |
|
|
|
|
Display::page_subheader3("Chamilo transaction info:")."<pre>".print_r($transaction_chamilo_info, true)."</pre>". |
|
|
|
|
Display::page_subheader3("Webservice transaction reponse:")."<pre>".print_r($result, true)."</pre>", |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return array( |
|
|
|
|
'message' => Display::return_message("Transaction NOT found in third party", 'warning'), |
|
|
|
|
//'raw_reponse' => print_r($result, true) |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Prepares the relationship between two fields (one from the original database and on from the destination/local database) |
|
|
|
|
* @param array List of fields that must be matched ('fields_match' => array(0=>array('orig'=>'...','dest'=>'...',...))) |
|
|
|
|
@ -1002,7 +1002,7 @@ class Migration { |
|
|
|
|
} |
|
|
|
|
$extra_fields_to_insert = array(); |
|
|
|
|
global $data_list; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($table['fields_match'] as $id_field => $details) { |
|
|
|
|
//if ($table['dest_table'] == 'session') {error_log('Processing field '.$details['orig']);} |
|
|
|
|
$params = array(); |
|
|
|
|
@ -1043,7 +1043,7 @@ class Migration { |
|
|
|
|
$options = $extra_field['options']; |
|
|
|
|
$field_type = $extra_field['field_type']; |
|
|
|
|
//if ($table['dest_table'] == 'session') {error_log('Field orid: '.$details['orig']);} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($options)) { |
|
|
|
|
//if ($table['dest_table'] == 'session') {error_log('Options not empty');} |
|
|
|
|
if (!is_array($options)) { $options = array($options); } |
|
|
|
|
@ -1080,16 +1080,16 @@ class Migration { |
|
|
|
|
unset($extra_field); |
|
|
|
|
} |
|
|
|
|
//if ($table['dest_table']=='session') { error_log('Params: '.print_r($params,1)); } |
|
|
|
|
// If a dest_func entry has been defind, use this entry as the main |
|
|
|
|
// If a dest_func entry has been defind, use this entry as the main |
|
|
|
|
// operation to execute when inserting the item |
|
|
|
|
if (!empty($table['dest_func'])) { |
|
|
|
|
//error_log('Calling '.$table['dest_func'].' on data recovered: '.print_r($dest_row, 1)); |
|
|
|
|
//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, $data_list)); |
|
|
|
|
|
|
|
|
|
/* if (isset($table['show_in_error_log']) && $table['show_in_error_log'] == false) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
//error_log('Result of calling ' . $table['dest_func'] . ': ' . print_r($item_result, 1)); |
|
|
|
|
} |
|
|
|
|
@ -1100,7 +1100,7 @@ class Migration { |
|
|
|
|
case 'course': |
|
|
|
|
//Saving courses in array |
|
|
|
|
if ($item_result) { |
|
|
|
|
//$data_list['courses'][$dest_row['uidIdCurso']] = $item_result; |
|
|
|
|
//$data_list['courses'][$dest_row['uidIdCurso']] = $item_result; |
|
|
|
|
} else { |
|
|
|
|
error_log('Course Not FOUND'); |
|
|
|
|
error_log(print_r($item_result, 1)); |
|
|
|
|
@ -1116,7 +1116,7 @@ class Migration { |
|
|
|
|
//$data_list['users_alumno'][$dest_row['uidIdAlumno']]['extra'] = $item_result; |
|
|
|
|
} |
|
|
|
|
if (isset($dest_row['uidIdEmpleado'])) { |
|
|
|
|
//print_r($dest_row['uidIdEmpleado']);exit; |
|
|
|
|
//print_r($dest_row['uidIdEmpleado']);exit; |
|
|
|
|
//$data_list['users_empleado'][$dest_row['uidIdEmpleado']]['extra'] = $item_result; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
@ -1126,7 +1126,7 @@ class Migration { |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case 'session': |
|
|
|
|
//$data_list['sessions'][$dest_row['uidIdPrograma']] = $item_result; |
|
|
|
|
//$data_list['sessions'][$dest_row['uidIdPrograma']] = $item_result; |
|
|
|
|
$handler_id = $item_result; //session_id |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
@ -1148,8 +1148,8 @@ class Migration { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Helper function to create extra fields in the Chamilo database. If the |
|
|
|
|
* extra field aleady exists, then just return the ID of this field. If |
|
|
|
|
* Helper function to create extra fields in the Chamilo database. If the |
|
|
|
|
* extra field aleady exists, then just return the ID of this field. If |
|
|
|
|
* options are provided ('options' sub-array), then options are inserted in |
|
|
|
|
* the corresponding x_field_options table. |
|
|
|
|
* @param Array An array containing an 'extra_fields' entry with details about the required extra fields |
|
|
|
|
@ -1169,7 +1169,7 @@ class Migration { |
|
|
|
|
|
|
|
|
|
$selected_fields = self::prepare_field_match($options); |
|
|
|
|
|
|
|
|
|
//Adding options. This is only processed if the corresponding |
|
|
|
|
//Adding options. This is only processed if the corresponding |
|
|
|
|
// extra_field has an 'options' sub-aray defined |
|
|
|
|
if (!empty($options)) { |
|
|
|
|
$extra_field_option_obj = new ExtraFieldOption($table['dest_table']); |
|
|
|
|
@ -1189,7 +1189,7 @@ class Migration { |
|
|
|
|
$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'] = |
|
|
|
|
//$extra_fields[$table['dest_table']]['extra_field_'.$extra_field['field_variable']]['selected_option'] = |
|
|
|
|
//error_log('$data: ' . print_r($data_to_insert, 1)); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
|