test_transaction.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * This script will test the recovery of transactions from an external database
  4. * queried through web services.
  5. */
  6. ini_set('display_errors',1);
  7. ini_set('mssql.datetimeconvert',0);
  8. $eol = "<br />";
  9. if (PHP_SAPI == 'cli') {
  10. $eol = "\n";
  11. }
  12. /**
  13. * Load connect info
  14. */
  15. require_once dirname(__FILE__).'/../../main/inc/global.inc.php';
  16. require 'config.php';
  17. if (is_file(dirname(__FILE__) . '/migration.custom.class.php')) {
  18. require_once 'migration.custom.class.php';
  19. } else {
  20. 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");
  21. }
  22. require_once 'migration.class.php';
  23. if (empty($servers)) {
  24. die("This script requires a servers array with the connection settings and the file to parse\n");
  25. }
  26. $start = time();
  27. $branches = array();
  28. /**
  29. * Try connecting
  30. */
  31. if (!empty($servers)) {
  32. foreach($servers as $server_info) {
  33. if ($server_info['active']) {
  34. $branch = $server_info['branch_id'];
  35. $config_info = $server_info['connection'];
  36. $db_type = $config_info['type'];
  37. if (empty($db_type)) {
  38. die("This script requires a DB type to work. Please update config.php\n");
  39. }
  40. $file = dirname(__FILE__) . '/migration.' . $db_type . '.class.php';
  41. if (!is_file($file)) {
  42. die("Could not find db type file " . $file . "\n");
  43. }
  44. require_once $file;
  45. $matches = null;
  46. include $server_info['filename'];
  47. if (!isset($matches['web_service_calls']['filename'])) {
  48. continue;
  49. }
  50. $branches[] = $branch;
  51. //echo 'Found server '.$server_info['name'].$eol.$eol;
  52. require_once $matches['web_service_calls']['filename'];
  53. $class = 'Migration' . strtoupper($db_type);
  54. $m = new $class($config_info['host'], $config_info['port'], $config_info['db_user'], $config_info['db_pass'], $config_info['db_name'], $boost);
  55. $m->connect();
  56. $m->search_transactions($matches['web_service_calls']);
  57. //Load transactions saved before
  58. if (!empty($_POST['ok'])) {
  59. $m->load_transactions($matches);
  60. }
  61. }
  62. }
  63. }
  64. /**
  65. * Show form
  66. */
  67. echo '<p><form action="" method="POST">';
  68. echo '<table>';
  69. echo '<tr><!--td>Sede</td><td><select name="branch">';
  70. foreach ($branches as $branch) {
  71. echo '<option value="'.$branch.'">'.$branch.'</option>';
  72. }
  73. echo '</select></td-->';
  74. echo '<td><input type="submit" name="ok" value="Probar una transaccion"></td></tr>';
  75. echo '</table>';
  76. echo '</form></p>';
  77. echo "$eol";