PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/package/app/app/scripts/billing_summary_insert.php

https://bitbucket.org/pandaos/kaltura
PHP | 62 lines | 46 code | 16 blank | 0 comment | 19 complexity | 5015c7279e6d484bd993cdeb8a768670 MD5 | raw file
Possible License(s): AGPL-3.0, GPL-3.0, BSD-3-Clause, LGPL-2.1, GPL-2.0, LGPL-3.0, JSON, MPL-2.0-no-copyleft-exception, Apache-2.0
  1. <?php
  2. function usage()
  3. {
  4. echo "\nusage: billing_summary_insert [www/ll/l3/ak] [date yyyy-mm-dd] [path - may use wildcard]\n";
  5. die;
  6. }
  7. $activity = 1;//PartnerActivity::PARTNER_ACTIVITY_TRAFFIC;
  8. $sub_activity_name = @$argv[1];
  9. if ($sub_activity_name == "www")
  10. $sub_activity = 1;
  11. else if ($sub_activity_name == "ll")
  12. $sub_activity = 2;
  13. else if ($sub_activity_name == "l3")
  14. $sub_activity = 3;
  15. else if ($sub_activity_name == "ak")
  16. $sub_activity = 4;
  17. else
  18. {
  19. echo "invalid sub_activity [$sub_activity]- use either www or ll or l3 or ak\n";
  20. usage();
  21. }
  22. $date = @$argv[2];
  23. $path = @$argv[3];
  24. if (strlen($date) == 8)
  25. $date = substr($date, 0, 4)."-".substr($date, 4, 2)."-".substr($date, 6, 2);
  26. if (strlen($date) != 10 || !$path)
  27. {
  28. usage();
  29. }
  30. $files = glob($argv[3]);
  31. echo "delete from partner_activity where activity=$activity and sub_activity=$sub_activity and activity_date='$date';\n";
  32. foreach($files as $file)
  33. {
  34. $data = file_get_contents($file);
  35. $lines = explode("\n", $data);
  36. foreach($lines as $line)
  37. {
  38. $stats = explode(",", $line);
  39. $partner_id = $stats[0] != "" ? $stats[0] : "null";
  40. $usage = @$stats[1];
  41. if ($usage == "")
  42. continue;
  43. echo "insert into partner_activity (partner_id, activity_date, activity, sub_activity, amount) values($partner_id,'$date',$activity,$sub_activity,$usage);\n";
  44. }
  45. }
  46. ?>