Added basis for test-transaction script

skala
Yannick Warnier 14 years ago
parent a9ea8366c2
commit cd3fe0085b
  1. 10
      tests/migrate/migration.class.php
  2. 78
      tests/migrate/test_transaction.php

@ -589,12 +589,11 @@ class Migration {
return 0;
}
/**
* Gets the latest recorded transaction for a specific branch
* 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_by_branch($branch_id) {
return 376011;
$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";
@ -603,7 +602,7 @@ class Migration {
$row = Database::fetch_array($result);
return $row['id'];
}
return 20;
return 376011;
}
/**
* Gets a specific transaction using select parameters
@ -664,15 +663,16 @@ class Migration {
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($web_service_params, 'transacciones', array('ultimo' => $last, 'cantidad' => 2));
$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' => 2));
$web_service_params['class']::process_transactions($web_service_params, array('ultimo' => $last, 'cantidad' => 1));
}
}
/**
* Loads a specific set of transactions from the transactions table and executes them
* @param array Transactions filter
* @param int Optional limit of transactions to execute
* @return void
*/
function load_transactions($matches) {

@ -0,0 +1,78 @@
<?php
/**
* This script will test the recovery of transactions from an external database
* queried through web services.
*/
ini_set('display_errors',1);
ini_set('mssql.datetimeconvert',0);
$eol = "<br />";
if (PHP_SAPI == 'cli') {
$eol = "\n";
}
/**
* Load connect info
*/
require_once dirname(__FILE__).'/../../main/inc/global.inc.php';
require 'config.php';
if (is_file(dirname(__FILE__) . '/migration.custom.class.php')) {
require_once 'migration.custom.class.php';
} else {
die("You need to define a custom migration class as migration.custom.class.php\n(copy it from migration.custom.class.dist.php, otherwise this migration process\n will not know what to do with the original database fields\n");
}
require_once 'migration.class.php';
if (empty($servers)) {
die("This script requires a servers array with the connection settings and the file to parse\n");
}
$start = time();
$branches = array();
/**
* Try connecting
*/
if (!empty($servers)) {
foreach($servers as $server_info) {
if ($server_info['active']) {
$branch = $server_info['branch_id'];
$config_info = $server_info['connection'];
$db_type = $config_info['type'];
if (empty($db_type)) {
die("This script requires a DB type to work. Please update config.php\n");
}
$file = dirname(__FILE__) . '/migration.' . $db_type . '.class.php';
if (!is_file($file)) {
die("Could not find db type file " . $file . "\n");
}
require_once $file;
$matches = null;
include $server_info['filename'];
if (!isset($matches['web_service_calls']['filename'])) {
continue;
}
$branches[] = $branch;
//echo 'Found server '.$server_info['name'].$eol.$eol;
require_once $matches['web_service_calls']['filename'];
$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'], $boost);
$m->connect();
$m->search_transactions($matches['web_service_calls']);
//Load transactions saved before
if (!empty($_POST['ok'])) {
$m->load_transactions($matches);
}
}
}
}
/**
* Show form
*/
echo '<p><form action="" method="POST">';
echo '<table>';
echo '<tr><!--td>Sede</td><td><select name="branch">';
foreach ($branches as $branch) {
echo '<option value="'.$branch.'">'.$branch.'</option>';
}
echo '</select></td-->';
echo '<td><input type="submit" name="ok" value="Probar una transaccion"></td></tr>';
echo '</table>';
echo '</form></p>';
echo "$eol";
Loading…
Cancel
Save