BxDolQueue.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCore UNA Core
  7. * @{
  8. */
  9. class BxDolQueue extends BxDolFactory
  10. {
  11. protected $_oQuery;
  12. protected $_bBusy;
  13. protected $_iLimitSend;
  14. protected $_iLimitSendPerRecipient;
  15. protected $_aSentTo;
  16. protected function __construct()
  17. {
  18. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  19. trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
  20. parent::__construct();
  21. $this->_bBusy = false;
  22. }
  23. /**
  24. * Prevent cloning the instance
  25. */
  26. public function __clone()
  27. {
  28. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  29. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  30. }
  31. /**
  32. * Send some number of items (email/push) from queue
  33. *
  34. * @param int $iLimit - number of queue items to send
  35. * @return real number of sent queue items or false, if sending process was already started with a previous call and wasn't finished yet.
  36. */
  37. public function send($iLimit = 0)
  38. {
  39. if($this->_bBusy)
  40. return false;
  41. $this->_bBusy = true;
  42. $aSent = array();
  43. if(empty($iLimit))
  44. $iLimit = $this->_iLimitSend;
  45. $aItems = $this->_oQuery->getItems(array('type' => 'to_send', 'start' => 0, 'per_page' => $iLimit));
  46. foreach($aItems as $iId => $aItem)
  47. if(call_user_func_array(array($this, '_send'), array_slice($aItem, 1))) {
  48. $this->_oQuery->deleteItem($iId);
  49. $aSent[] = $iId;
  50. }
  51. $this->_bBusy = false;
  52. return count($aSent);
  53. }
  54. }
  55. /** @} */