checkfreshness.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. require_once ('libs/api.compat.php');
  3. require_once ('libs/api.ubrouting.php');
  4. if (ubRouting::optionCliCheck('run', false)) {
  5. $diffDumpFlag = ubRouting::optionCliCheck('dumpdiff', false);
  6. $errorCount = 0;
  7. $ubillingLibsPath = __DIR__ . '/../../YALF/api/libs/';
  8. $yalfLibsPath = __DIR__ . '/libs/';
  9. $ignoreList = array('api.compat.php', 'api.ubconfig.php', 'api.mysql.php', 'api.eventview.php', 'api.processmon.php', 'api.taskbar.php', 'api.apachezen.php', 'api.backups.php', 'api.usermanager.php', 'api.yalfloginform.php'); //that libs may be different
  10. $ignoreList = array_flip($ignoreList);
  11. $allYalfLibs = rcms_scandir($yalfLibsPath, '*.php');
  12. $allUbillingLibs = rcms_scandir($ubillingLibsPath, '*.php');
  13. if (!empty($allYalfLibs)) {
  14. if (!empty($allUbillingLibs)) {
  15. $allYalfLibs = array_flip($allYalfLibs);
  16. $allUbillingLibs = array_flip($allUbillingLibs);
  17. foreach ($allYalfLibs as $eachYalfLib => $index) {
  18. if (file_exists($ubillingLibsPath . $eachYalfLib)) {
  19. if (!isset($ignoreList[$eachYalfLib])) {
  20. $diffResult = shell_exec('diff --ignore-all-space ' . $yalfLibsPath . $eachYalfLib . ' ' . $ubillingLibsPath . $eachYalfLib);
  21. if (!empty($diffResult)) {
  22. $errorCount++;
  23. print('FAILED: ' . $eachYalfLib . PHP_EOL);
  24. if ($diffDumpFlag) {
  25. print('=========================' . PHP_EOL);
  26. print_r($diffResult);
  27. print('=========================' . PHP_EOL);
  28. }
  29. } else {
  30. print('OK: ' . $eachYalfLib . PHP_EOL);
  31. }
  32. }
  33. }
  34. }
  35. //summary here
  36. print('=========================' . PHP_EOL);
  37. if ($errorCount > 0) {
  38. print('Found ' . $errorCount . ' issues with libs freshness' . PHP_EOL);
  39. } else {
  40. print('Everything is Ok' . PHP_EOL);
  41. }
  42. } else {
  43. print('Error: no Ubilling libs at specified path not found: ' . $ubillingLibsPath . PHP_EOL);
  44. }
  45. } else {
  46. print('Error: no YALF libs at specified path not found: ' . $yalfLibsPath . PHP_EOL);
  47. }
  48. } else {
  49. print('Usage: php ./api/checkfreshness.php --run [--dumpdiff]' . PHP_EOL);
  50. }