Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.4 KiB

10 years ago
10 years ago
10 years ago
  1. <?php
  2. function update_queue_time($id) {
  3. logger('queue: requeue item ' . $id);
  4. q("UPDATE `queue` SET `last` = '%s' WHERE `id` = %d LIMIT 1",
  5. dbesc(datetime_convert()),
  6. intval($id)
  7. );
  8. }
  9. function remove_queue_item($id) {
  10. logger('queue: remove queue item ' . $id);
  11. q("DELETE FROM `queue` WHERE `id` = %d LIMIT 1",
  12. intval($id)
  13. );
  14. }
  15. function add_to_queue($cid,$network,$msg,$batch = false) {
  16. $max_queue = get_config('system','max_contact_queue');
  17. if($max_queue < 1)
  18. $max_queue = 500;
  19. $batch_queue = get_config('system','max_batch_queue');
  20. if($batch_queue < 1)
  21. $batch_queue = 1000;
  22. $r = q("SELECT COUNT(*) AS `total` FROM `queue` left join `contact` ON `queue`.`cid` = `contact`.`id`
  23. WHERE `queue`.`cid` = %d AND `contact`.`self` = 0 ",
  24. intval($cid)
  25. );
  26. if($r && count($r)) {
  27. if($batch && ($r[0]['total'] > $batch_queue)) {
  28. logger('add_to_queue: too many queued items for batch server ' . $cid . ' - discarding message');
  29. return;
  30. }
  31. elseif((! $batch) && ($r[0]['total'] > $max_queue)) {
  32. logger('add_to_queue: too many queued items for contact ' . $cid . ' - discarding message');
  33. return;
  34. }
  35. }
  36. q("INSERT INTO `queue` ( `cid`, `network`, `created`, `last`, `content`, `batch`)
  37. VALUES ( %d, '%s', '%s', '%s', '%s', %d) ",
  38. intval($cid),
  39. dbesc($network),
  40. dbesc(datetime_convert()),
  41. dbesc(datetime_convert()),
  42. dbesc($msg),
  43. intval(($batch) ? 1: 0)
  44. );
  45. }