fix_lp_total_time.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script checks that the c_lp_item_view.total_time field
  5. * doesn't have big values. The scripts updates it or send a message to the admin (depending the settings).
  6. */
  7. exit;
  8. require_once __DIR__.'/../../main/inc/global.inc.php';
  9. opcache_reset();
  10. $maxSeconds = 5 * 60 * 60; // Check records higher than 5 hours
  11. $valueToUpdate = 1 * 60 * 60; // Update this abusive records with 1 hours
  12. $limit = 10; // Only fix first 10
  13. $sendMessage = true;
  14. $userId = 1; // User id that will receive a report
  15. $update = false;
  16. $sql = "SELECT iid, total_time FROM c_lp_item_view
  17. WHERE total_time > $maxSeconds
  18. order by total_time desc
  19. LIMIT $limit
  20. ";
  21. $result = Database::query($sql);
  22. $log = '';
  23. while ($row = Database::fetch_array($result, 'ASSOC')) {
  24. $id = $row['iid'];
  25. $oldTotalTime = $row['total_time'];
  26. $sql = "UPDATE c_lp_item_view SET total_time = '$valueToUpdate' WHERE iid = $id;";
  27. // Uncomment to fix
  28. if ($update) {
  29. Database::query($sql);
  30. }
  31. $oldTotalTime = round($oldTotalTime / 3600, 2);
  32. $report = "Previous total_time : ".$oldTotalTime." hours";
  33. $report .= PHP_EOL;
  34. $report .= "New total_time: $valueToUpdate";
  35. $report .= PHP_EOL;
  36. $report .= $sql;
  37. $report .= PHP_EOL;
  38. $report .= PHP_EOL;
  39. $log .= $report;
  40. echo $report;
  41. }
  42. if ($sendMessage && !empty($log)) {
  43. $log = nl2br($log);
  44. MessageManager::send_message_simple(
  45. $userId,
  46. 'LP time abusive fixes',
  47. $log,
  48. 1
  49. );
  50. }