Commit b6c567c1a0f6e3f1974d03541b5ab971f800868c
1 parent
079c63e6
Make subscriptions recurse down folders.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3783 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
35 additions
and
1 deletions
lib/subscriptions/SubscriptionEngine.inc
| @@ -64,7 +64,18 @@ class SubscriptionEngine { | @@ -64,7 +64,18 @@ class SubscriptionEngine { | ||
| 64 | // for each subscriber, construct an address based on their notification preferences | 64 | // for each subscriber, construct an address based on their notification preferences |
| 65 | for ($i=0; $i<count($aSubscribers); $i++) { | 65 | for ($i=0; $i<count($aSubscribers); $i++) { |
| 66 | // lookup the subscription | 66 | // lookup the subscription |
| 67 | - $oSubscription = & Subscription::getByIDs($aSubscribers[$i]->getID(), $iExternalID, $iSubscriptionType); | 67 | + if ($iSubscriptionType == SubscriptionConstants::subscriptionType("FolderSubscription")) { |
| 68 | + $oSubscription = & Subscription::getByIDs($aSubscribers[$i]->getID(), $oValues['folderID'], $iSubscriptionType); | ||
| 69 | + if (empty($oSubscription) || PEAR::isError($oSubscription)) { | ||
| 70 | + $oSubscription =& new Subscription($aSubscribers[$i]->getID(), $aValues["folderID"], $iSubscriptionType); | ||
| 71 | + $res = $oSubscription->create(); | ||
| 72 | + if (empty($res) || PEAR::isError($res)) { | ||
| 73 | + continue; | ||
| 74 | + } | ||
| 75 | + } | ||
| 76 | + } else { | ||
| 77 | + $oSubscription = & Subscription::getByIDs($aSubscribers[$i]->getID(), $iExternalID, $iSubscriptionType); | ||
| 78 | + } | ||
| 68 | 79 | ||
| 69 | // update the alerted status | 80 | // update the alerted status |
| 70 | $oSubscription->setIsAlerted(true); | 81 | $oSubscription->setIsAlerted(true); |
| @@ -109,6 +120,21 @@ class SubscriptionEngine { | @@ -109,6 +120,21 @@ class SubscriptionEngine { | ||
| 109 | $default->log->error("SubscriptionEngine::fireSubscription could not update subscription- db error?"); | 120 | $default->log->error("SubscriptionEngine::fireSubscription could not update subscription- db error?"); |
| 110 | } | 121 | } |
| 111 | } | 122 | } |
| 123 | + | ||
| 124 | + if ($iSubscriptionType == SubscriptionConstants::subscriptionType("FolderSubscription")) { | ||
| 125 | + $oFolder =& Folder::get($iExternalID); | ||
| 126 | + if ($oFolder && !PEAR::isError($oFolder)) { | ||
| 127 | + $iThisSubscriptionsSent = SubscriptionEngine::fireSubscription($oFolder->getParentId(), | ||
| 128 | + ($iSubscriptionAlertType == SubscriptionConstants::subscriptionAlertType("RemoveSubscribedDocument") ? | ||
| 129 | + SubscriptionConstants::subscriptionAlertType("RemoveChildDocument") : | ||
| 130 | + $iSubscriptionAlertType), | ||
| 131 | + SubscriptionConstants::subscriptionType("FolderSubscription"), | ||
| 132 | + $aValues); | ||
| 133 | + $default->log->info("SubscriptionEngine::fireSubscription fired folder subscribers, count=$iThisSubscriptionsSent"); | ||
| 134 | + $iSubscriptionsSent += $iThisSubscriptionsSent; | ||
| 135 | + } | ||
| 136 | + } | ||
| 137 | + | ||
| 112 | // return the number of processed subscriptions | 138 | // return the number of processed subscriptions |
| 113 | return $iSubscriptionsSent; | 139 | return $iSubscriptionsSent; |
| 114 | } | 140 | } |
| @@ -122,6 +148,10 @@ class SubscriptionEngine { | @@ -122,6 +148,10 @@ class SubscriptionEngine { | ||
| 122 | */ | 148 | */ |
| 123 | function retrieveSubscribers($iExternalID, $iSubscriptionType) { | 149 | function retrieveSubscribers($iExternalID, $iSubscriptionType) { |
| 124 | global $default; | 150 | global $default; |
| 151 | + global $aAlreadySent; | ||
| 152 | + if (!isset($aAlreadySent)) { | ||
| 153 | + $aAlreadySent = array(); | ||
| 154 | + } | ||
| 125 | 155 | ||
| 126 | $sql = $default->db; | 156 | $sql = $default->db; |
| 127 | $aUsers = array(); | 157 | $aUsers = array(); |
| @@ -131,6 +161,10 @@ class SubscriptionEngine { | @@ -131,6 +161,10 @@ class SubscriptionEngine { | ||
| 131 | if ($sql->query(array($sQuery, $aParams))) { | 161 | if ($sql->query(array($sQuery, $aParams))) { |
| 132 | while ($sql->next_record()) { | 162 | while ($sql->next_record()) { |
| 133 | $iUserID = $sql->f("user_id"); | 163 | $iUserID = $sql->f("user_id"); |
| 164 | + if (in_array($iUserID, $aAlreadySent)) { | ||
| 165 | + continue; | ||
| 166 | + } | ||
| 167 | + $aAlreadySent[] = $iUserID; | ||
| 134 | $oUser = & User::get($iUserID ); | 168 | $oUser = & User::get($iUserID ); |
| 135 | if ($oUser) { | 169 | if ($oUser) { |
| 136 | $aUsers[] = $oUser; | 170 | $aUsers[] = $oUser; |