Accepting branch_id when calling webservice see BT#4882

skala
Julio Montoya 13 years ago
parent 553459b207
commit a9740cd2f3
  1. 16
      main/inc/global.inc.php
  2. 43
      tests/migrate/migration.class.php
  3. 6
      tests/migrate/migration.custom.class.php
  4. 15
      tests/migrate/transaction_tester.php

@ -328,17 +328,9 @@ if (!$x = strpos($_SERVER['PHP_SELF'], 'whoisonline.php')) {
// ===== end "who is logged in?" module section =====
if (api_get_setting('server_type') == 'test') {
/*
Server type is test
- high error reporting level
- only do addslashes on $_GET and $_POST
*/
if (IS_PHP_53) {
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
} else {
error_reporting(E_ALL & ~E_NOTICE);
}
if (api_get_setting('server_type') == 'test') {
//error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
error_reporting(-1);
} else {
/*
Server type is not test
@ -606,7 +598,7 @@ if (!isset($_SESSION['login_as']) && isset($_user)) {
// The langstat object will then be used in the get_lang() function.
// This block can be removed to speed things up a bit as it should only ever
// be used in development versions.
if ($_configuration['language_measure_frequency'] == 1) {
if (isset($_configuration['language_measure_frequency']) && $_configuration['language_measure_frequency'] == 1) {
require_once api_get_path(SYS_CODE_PATH).'/cron/lang/langstats.class.php';
$langstats = new langstats();
}

@ -635,14 +635,17 @@ class Migration {
* @param int The ID of the branch
* @return int The ID of the last transaction registered
*/
static function get_latest_transaction_by_branch($branch_id) {
static function get_latest_transaction_id_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";
$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)) {
$row = Database::fetch_array($result);
return $row['id'];
return $row['transaction_id'];
}
return 376011;
}
@ -688,7 +691,7 @@ class Migration {
* @param int An optional transaction ID to start from. If none provided, fetches the latest transaction available and add + 1
* @return The operation results
*/
function search_transactions($t_id = null) {
function search_transactions($transaction_id = null, $branch_id = null) {
error_log('search_transactions');
//Testing transactions
@ -705,13 +708,26 @@ class Migration {
$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));
*/
$branches = self::get_branches();
if (empty($branch_id)) {
$branches = self::get_branches();
} else {
$branches = array('branch_id' => $branch_id);
}
foreach ($branches as $branch) {
error_log('Treating transactions for branch '.$branch['branch_id']);
$last = self::get_latest_transaction_by_branch($branch['branch_id']);
//$result = self::soap_call($this->web_service_connection_info, 'transacciones', array('ultimo' => $last, 'cantidad' => 2));
if (empty($transaction_id)) {
$last_transaction_id = self::get_latest_transaction_id_by_branch($branch['branch_id']);
} else {
$last_transaction_id = $transaction_id;
}
//Calling a process to save transactions
MigrationCustom::process_transactions(array('ultimo' => $last, 'cantidad' => 2), $web_service_params);
$params = array(
'ultimo' => $last_transaction_id,
'cantidad' => 2,
'sede' => $branch['branch_id'],
);
MigrationCustom::process_transactions($params, $web_service_params);
}
}
@ -821,9 +837,16 @@ class Migration {
* @param int Transaction id of the third party
*
*/
function load_transaction_by_third_party_id($transaction_external_id, $forced = false) {
function load_transaction_by_third_party_id($transaction_external_id, $branch_id, $forced = false) {
//Asking for 2 transactions by getting 1
$result = self::soap_call($this->web_service_connection_info,'transacciones', array('ultimo' => $transaction_external_id, 'cantidad' => 2));
$params = array(
'ultimo' => $transaction_external_id,
'cantidad' => 2,
'sede' => $branch_id
);
$result = self::soap_call($this->web_service_connection_info, 'transacciones', $params);
//Hacking webservice default result
if ($result && isset($result[0])) {

@ -1473,14 +1473,14 @@ class MigrationCustom {
// const TRANSACTION_TYPE_DEL_INTENS = 26;
static function transaction_26($data, $web_service_details) {
return self::transaction_extra_field_eliminar_generic('intensidad', $data, $web_service_details);
}
}
// editar intfase_editar IID
// const TRANSACTION_TYPE_EDIT_INTENS = 27;
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) {
@ -1517,7 +1517,7 @@ class MigrationCustom {
string(12) "AAAAATbYxkg="
}
*/
function process_transactions($params, $web_service_details) {
static function process_transactions($params, $web_service_details) {
$transactions = Migration::soap_call($web_service_details, 'transacciones', $params);
$transaction_status_list = self::get_transaction_status_list();

@ -8,7 +8,11 @@ Display::display_header();
$form = new FormValidator('transaction_tester');
$form->addElement('header', 'Transaction tester');
$form->addElement('text', 'transaction_id', get_lang('TransactionId'));
$form->addElement('text', 'branch_id', get_lang('BranchId'));
$form->addRule('transaction_id',get_lang('ThisFieldShouldBeNumeric'),'numeric');
$form->addRule('branch_id',get_lang('ThisFieldShouldBeNumeric'),'numeric');
$form->addElement('checkbox', 'forced', null, get_lang('ForceTransactionCreation'));
$form->addElement('button', 'add', get_lang('Send'));
@ -19,7 +23,8 @@ if ($form->validate()) {
$values = $form->getSubmitValues();
$transaction_id = $values['transaction_id'];
$response = Display::page_subheader2("Executing transaction #$transaction_id");
$branch_id = $values['branch_id'];
$response = Display::page_subheader2("Executing transaction #$transaction_id in branch_id: $branch_id");
require_once 'migration.class.php';
require_once 'migration.custom.class.php';
@ -29,19 +34,19 @@ if ($form->validate()) {
$migration = new Migration();
$migration->set_web_service_connection_info($matches);
$forced = isset($values['forced']) && $values['forced'] == 1 ? true : false;
//This is the fault of the webservice
$transaction_id--;
$result = $migration->load_transaction_by_third_party_id($transaction_id, $forced);
$result = $migration->load_transaction_by_third_party_id($transaction_id, $branch_id, $forced);
$response .= $result['message'];
if (isset($result['raw_reponse'])) {
$response .= $result['raw_reponse'];
}
}
$form->setDefaults(array('transaction_id' => '376012'));
$form->setDefaults(array('transaction_id' => '376014', 'branch_id' => 2));
$form->display();
if (!empty($response)) {
echo $response;
}
}
Loading…
Cancel
Save