index.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. if (cfr('ROOT')) {
  3. if ($ubillingConfig->getAlterParam('FEES_HARVESTER')) {
  4. set_time_limit(0);
  5. $billCfg = $ubillingConfig->getBilling();
  6. $altCfg = $ubillingConfig->getAlter();
  7. $baseUrl = '?module=feesharvesterimport';
  8. $fundsFlow = new FundsFlow();
  9. $moduleControls = '';
  10. $moduleControls .= wf_Link($baseUrl . '&migrate=full', wf_img('skins/icon_restoredb.png') . ' ' . __('Migrate all fees data for all time'), false, 'ubButton');
  11. $moduleControls .= wf_Link($baseUrl . '&migrate=month', wf_img('skins/icon_restoredb.png') . ' ' . __('Migrate fees data by selected month'), false, 'ubButton');
  12. show_window(__('Migrate previous fees data into database'), $moduleControls);
  13. //rendering some stats
  14. if (!ubRouting::checkGet('migrate')) {
  15. $stgLogPath = $altCfg['STG_LOG_PATH'];
  16. $wcPath = '/usr/bin/wc'; // WTF???
  17. $catPath = $billCfg['CAT'];
  18. $grepPath = $billCfg['GREP'];
  19. if (file_exists($stgLogPath)) {
  20. //counting fees from stargazer log
  21. $command = $catPath . ' ' . $stgLogPath . ' | ' . $grepPath . ' "' . $fundsFlow::MASK_FEE . '" | ' . $wcPath . ' -l';
  22. $feeRecordsCount = shell_exec($command);
  23. $feeRecordsCount = trim($feeRecordsCount);
  24. //counting fees from DB
  25. $feesDb = new NyanORM($fundsFlow::TABLE_FEES);
  26. $feesDb->where('cashtype', '=', '0');
  27. $feesDb->where('admin', '=', 'stargazer');
  28. $feeDbCount = $feesDb->getFieldsCount();
  29. show_info(__('Stargazer log file contains') . ' ' . $feeRecordsCount . ' ' . __('fee records'));
  30. show_info(__('Ubilling database contains') . ' ' . $feeDbCount . ' ' . __('fee records'));
  31. if ($feeRecordsCount > $feeDbCount) {
  32. show_warning(__('May be not all of fee records imported to database'));
  33. } else {
  34. show_success(__('Looks like all data currently synced'));
  35. }
  36. } else {
  37. show_error(__('File not found') . ': ' . $stgLogPath);
  38. }
  39. show_window('', wf_BackLink('?module=taskbar'));
  40. } else {
  41. $migrationMode = ubRouting::get('migrate');
  42. //migration confirmation interface for selected time range
  43. if (!ubRouting::checkPost('runmigration')) {
  44. if ($migrationMode == 'full') {
  45. $inputs = '';
  46. $inputs .= wf_HiddenInput('runmigration', 'true');
  47. $inputs .= wf_CheckInput('agree', __('I`m ready'), false, false) . ' ';
  48. $inputs .= wf_Submit(__('Migrate all fees data for all time'));
  49. $confirmationForm = wf_Form('', 'POST', $inputs, 'glamour');
  50. show_window('', $confirmationForm);
  51. }
  52. if ($migrationMode == 'month') {
  53. $inputs = '';
  54. $inputs .= wf_HiddenInput('runmigration', 'true');
  55. $inputs .= wf_YearSelectorPreset('migrateyear', __('Year'), false, curyear()) . ' ';
  56. $inputs .= wf_MonthSelector('migratemonth', __('Month'), date("m"), false) . ' ';
  57. $inputs .= wf_CheckInput('agree', __('I`m ready'), true, false) . ' ';
  58. $inputs .= wf_delimiter(0);
  59. $inputs .= wf_Submit(__('Migrate fees data by selected month'));
  60. $confirmationForm = wf_Form('', 'POST', $inputs, 'glamour');
  61. show_window('', $confirmationForm);
  62. }
  63. show_info(__('This process make take a while, please be patient'));
  64. } else {
  65. //do some migration here
  66. if (ubRouting::checkPost('agree')) {
  67. //process manager init
  68. $harvesterProcess = new StarDust('FEESHARVESTER');
  69. //full migration here
  70. if ($migrationMode == 'full') {
  71. if ($harvesterProcess->notRunning()) {
  72. $harvesterProcess->start();
  73. $harvestedFees = $fundsFlow->harvestFees();
  74. $harvesterProcess->stop();
  75. ubRouting::nav($baseUrl);
  76. } else {
  77. show_error(__('Migration') . ': ' . __('Already running'));
  78. }
  79. }
  80. //month migration
  81. if ($migrationMode == 'month') {
  82. if (ubRouting::checkPost(array('migrateyear', 'migratemonth'))) {
  83. $migrateYear = ubRouting::post('migrateyear', 'int');
  84. $migrateMonth = ubRouting::post('migratemonth', 'int');
  85. $customPeriod = $migrateYear . '-' . $migrateMonth;
  86. if ($harvesterProcess->notRunning()) {
  87. $harvesterProcess->start();
  88. $harvestedFees = $fundsFlow->harvestFees($customPeriod);
  89. $harvesterProcess->stop();
  90. ubRouting::nav($baseUrl);
  91. } else {
  92. show_error(__('Migration') . ': ' . __('Already running'));
  93. }
  94. } else {
  95. show_error(__('Something went wrong'));
  96. }
  97. }
  98. } else {
  99. show_error(__('You are not mentally prepared for this'));
  100. }
  101. }
  102. show_window('', wf_BackLink($baseUrl));
  103. }
  104. } else {
  105. show_error(__('This module is disabled'));
  106. }
  107. } else {
  108. show_error(__('Access denied'));
  109. }