BxDolCronNotifies.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. // TODO: move massmaler to separate module
  3. /***************************************************************************
  4. * Dolphin Smart Community Builder
  5. * -------------------
  6. * begin : Mon Mar 23 2006
  7. * copyright : (C) 2007 BoonEx Group
  8. * website : http://www.boonex.com
  9. * This file is part of Dolphin - Smart Community Builder
  10. *
  11. * Dolphin is free software; you can redistribute it and/or modify it under
  12. * the terms of the GNU General Public License as published by the
  13. * Free Software Foundation; either version 2 of the
  14. * License, or any later version.
  15. *
  16. * Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  17. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  18. * See the GNU General Public License for more details.
  19. * You should have received a copy of the GNU General Public License along with Dolphin,
  20. * see license.txt file; if not, write to marketing@boonex.com
  21. ***************************************************************************/
  22. require_once( BX_DIRECTORY_PATH_INC . 'db.inc.php' );
  23. require_once('BxDolCron.php');
  24. class BxDolCronNotifies extends BxDolCron {
  25. function processing() {
  26. set_time_limit( 36000 );
  27. ignore_user_abort();
  28. $sResult = "";
  29. $iPerStart = (int)trim(getParam('msgs_per_start'));
  30. $iFullCount = (int)$GLOBALS['MySQL']->getOne('SELECT COUNT(*) FROM `sys_sbs_queue`');
  31. if($iFullCount) {
  32. $iProcess = $iFullCount < $iPerStart ? $iFullCount : $iPerStart;
  33. $sResult .= "\n- Start email send -\n";
  34. $sResult .= "Total queued emails: " . $iFullCount . "\n";
  35. $sResult .= "Ready for send: " . $iProcess . "\n";
  36. $aMails = $GLOBALS['MySQL']->getAll("SELECT `id`, `email`, `subject`, `body` FROM `sys_sbs_queue` ORDER BY `id` LIMIT 0, " . $iProcess);
  37. $iSent = 0;
  38. $aIds = array();
  39. foreach($aMails as $aMail) {
  40. $aIds[] = $aMail['id'];
  41. if(sendMail($aMail['email'], $aMail['subject'], $aMail['body'], 0, array(), BX_EMAIL_MASS))
  42. $iSent++;
  43. else
  44. $sResult .= "Cannot send message to " . $aMail['email'] . "\n";
  45. }
  46. $GLOBALS['MySQL']->query("DELETE FROM `sys_sbs_queue` WHERE `id` IN ('" . implode("','", $aIds) . "')");
  47. $sResult .= "Processed emails: " . $iSent . "\n";
  48. sendMail(getParam('site_email'), getParam('site_title') . ": Periodic Report", $sResult, 0, array(), BX_EMAIL_NOTIFY, 'text'); // TODO: email template
  49. }
  50. }
  51. }