BxDolCronAcl.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 BxDolCronAcl extends BxDolCron
  10. {
  11. public function processing()
  12. {
  13. $iExpireLetters = 0;
  14. $iExpireNotificationDays = (int)getParam("sys_acl_expire_notification_days");
  15. $bExpireNotifyOnce = getParam("sys_acl_expire_notify_once") == 'on';
  16. $oAcl = BxDolAcl::getInstance();
  17. $oDb = BxDolDb::getInstance();
  18. $aIds = $oDb->getColumn("SELECT DISTINCT `IDMember` FROM `sys_acl_levels_members`");
  19. foreach($aIds as $iId) {
  20. $aMemCur = $oAcl->getMemberMembershipInfo($iId);
  21. // If expire_notification_days is -1 then notify after expiration
  22. if($aMemCur['id'] == MEMBERSHIP_ID_STANDARD && $iExpireNotificationDays == -1 ) {
  23. $iDatePrev = time() - 24 * 3600;
  24. $aMemPrev = $oAcl->getMemberMembershipInfo($iId, $iDatePrev); // Get previous membership level
  25. if($aMemCur['id'] != $aMemPrev['id']) {
  26. $bMailResult = $oAcl->getExpirationLetter($iId, $aMemPrev['name'], -1);
  27. if($bMailResult)
  28. $iExpireLetters++;
  29. }
  30. }
  31. // If memberhip is not standard then check if it will change
  32. elseif($aMemCur['id'] != MEMBERSHIP_ID_STANDARD) {
  33. $iDateNext = time() + $iExpireNotificationDays * 24 * 3600;
  34. $aMemNext = $oAcl->getMemberMembershipInfo($iId, $iDateNext);
  35. if($aMemCur['id'] != $aMemNext['id'] && $aMemNext['id'] == MEMBERSHIP_ID_STANDARD) {
  36. if(!$bExpireNotifyOnce || abs($iDateNext - $aMemCur['date_expires']) < 24 * 3600) {
  37. $bMailResult = $oAcl->getExpirationLetter($iId, $aMemCur['name'], (int)(($aMemCur['date_expires'] - time())/(24 * 3600)));
  38. if($bMailResult)
  39. $iExpireLetters++;
  40. }
  41. }
  42. }
  43. // clean memory
  44. if(($oProfile = BxDolProfile::getInstance($iId)) !== false) {
  45. unset($GLOBALS['bxDolClasses']['BxDolProfile_' . $iId]);
  46. unset($GLOBALS['bxDolClasses']['BxDolAccount_' . $oProfile->getAccountId()]);
  47. BxDolDb::getInstance()->cleanMemory('BxDolAclQuery::getLevelCurrent' . $iId . 0);
  48. }
  49. }
  50. }
  51. }
  52. /** @} */