migrate.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * Migration launcher
  4. * Call with either "migration" or "sync" as first parameter
  5. * @package chamilo.migration
  6. */
  7. /**
  8. * Load required classes
  9. */
  10. require_once dirname(__FILE__).'/../../main/inc/global.inc.php';
  11. require_once 'config.php';
  12. require_once api_get_path(LIBRARY_PATH).'attendance.lib.php';
  13. require_once api_get_path(LIBRARY_PATH).'thematic.lib.php';
  14. $action_type = ((!empty($argv[1]) && $argv[1]=='migration')?'migration':'sync');
  15. if (is_file(dirname(__FILE__) . '/migration.custom.class.php')) {
  16. require_once 'migration.custom.class.php';
  17. } else {
  18. 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");
  19. }
  20. require_once 'migration.class.php';
  21. if (empty($servers)) {
  22. die("This script requires a servers array with the connection settings and the file to parse\n");
  23. }
  24. $data_list = array('users'=>array(),'courses'=>array(),'sessions'=>array());
  25. $utc_datetime = api_get_utc_datetime();
  26. $start = time();
  27. echo "\n-- Starting at ".date('h:i:s')." local server time\n";
  28. if (!empty($servers)) {
  29. foreach ($servers as $server_info) {
  30. if ($server_info['active']) {
  31. echo "\n---- Start loading server----- \n";
  32. echo $server_info['name']."\n\n";
  33. error_log('Treating server '.$server_info['name']);
  34. //echo "---- ----------------------- \n";
  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 orig_db_conn.inc.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. $class = 'Migration' . strtoupper($db_type);
  46. $m = new $class($config_info['host'], $config_info['port'], $config_info['db_user'], $config_info['db_pass'], $config_info['db_name'], $boost);
  47. $m->connect();
  48. /**
  49. * Prepare the arrays of matches that will allow for the migration
  50. */
  51. $migrate = array();
  52. $branch = $server_info['branch_id'];
  53. include $server_info['filename'];
  54. if ($action_type == 'migration') {
  55. error_log('Starting Migration');
  56. //Default migration from MSSQL to Chamilo MySQL
  57. $m->migrate($matches);
  58. } else {
  59. //Getting transactions from MSSQL (via webservices)
  60. if (!empty($matches['web_service_calls'])) {
  61. error_log('Starting Synchronization');
  62. $m->set_web_service_connection_info($matches);
  63. //This functions truncates the transaction lists!
  64. //$m->insert_test_transactions();
  65. //$m->get_transactions_from_webservice();
  66. //Load transactions saved before
  67. $params = array('branch_id' => 2);
  68. $m->execute_transactions();
  69. } else {
  70. error_log('Make sure you define the web_service_calls array in your db_matches.php file');
  71. }
  72. //print_r($m->errors_stack);
  73. }
  74. //echo "OK so far\n";
  75. echo "\n ---- End loading server----- \n";
  76. } else {
  77. error_log("db_matches not activated: {$server_info['name']} {$server_info['filename']}");
  78. }
  79. }
  80. }
  81. $end = time();
  82. echo "Total process took ".($end-$start)." seconds \n";
  83. error_log("Total process took ".($end-$start)." seconds");