Commit 36ac1edce3d4e440d651308bd216aa1963d88038
1 parent
2fe2fcde
fix for KTS-1252: subscriptions crashes after deleted document.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5951 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
29 additions
and
11 deletions
lib/subscriptions/Subscription.inc
| @@ -180,6 +180,14 @@ class Subscription extends KTEntity { | @@ -180,6 +180,14 @@ class Subscription extends KTEntity { | ||
| 180 | return generateControllerUrl("browse", "fBrowseType=folder&fFolderId=$this->iExternalID"); | 180 | return generateControllerUrl("browse", "fBrowseType=folder&fFolderId=$this->iExternalID"); |
| 181 | } | 181 | } |
| 182 | } | 182 | } |
| 183 | + | ||
| 184 | + function isValid() { | ||
| 185 | + if ($this->iSubscriptionType == SubscriptionConstants::subscriptionType("DocumentSubscription")) { | ||
| 186 | + return !PEAR::isError(Document::get($this->iExternalID)); | ||
| 187 | + } else if ($this->iSubscriptionType == SubscriptionConstants::subscriptionType("FolderSubscription")) { | ||
| 188 | + return !PEAR::isError(Folder::get($this->iExternalID)); | ||
| 189 | + } | ||
| 190 | + } | ||
| 183 | 191 | ||
| 184 | function getAlertLink() { | 192 | function getAlertLink() { |
| 185 | global $default; | 193 | global $default; |
lib/subscriptions/SubscriptionManager.inc
| @@ -154,20 +154,30 @@ class SubscriptionManager { | @@ -154,20 +154,30 @@ class SubscriptionManager { | ||
| 154 | * @return array of subscription objects, false if the database interaction fails | 154 | * @return array of subscription objects, false if the database interaction fails |
| 155 | */ | 155 | */ |
| 156 | function retrieveUserSubscriptions($iUserID, $iSubscriptionType) { | 156 | function retrieveUserSubscriptions($iUserID, $iSubscriptionType) { |
| 157 | - global $default; | 157 | + |
| 158 | + $table = Subscription::getTableName($iSubscriptionType); // EVIL! | ||
| 159 | + $aQuery = array( | ||
| 160 | + "SELECT id FROM $table WHERE user_id = ?", | ||
| 161 | + $iUserID, | ||
| 162 | + ); | ||
| 163 | + | ||
| 164 | + | ||
| 165 | + $res = DBUtil::getResultArrayKey($aQuery, 'id'); | ||
| 166 | + if (PEAR::isError($res)) { | ||
| 167 | + // isn't this hideous? | ||
| 168 | + $_SESSION['_ktErrorMessage'][] = $res->getMessage(); | ||
| 169 | + return false; | ||
| 170 | + } | ||
| 158 | 171 | ||
| 159 | - $sql = $default->db; | ||
| 160 | - if ($sql->query(array("SELECT id FROM " . Subscription::getTableName($iSubscriptionType) . " " ./*ok*/ | ||
| 161 | - "WHERE user_id = ?", $iUserID))) { | ||
| 162 | - $aSubscriptions = array(); | ||
| 163 | - while ($sql->next_record()) { | ||
| 164 | - $aSubscriptions[] = & Subscription::get($sql->f("id"), $iSubscriptionType); | 172 | + $items = array(); |
| 173 | + foreach ($res as $id) { | ||
| 174 | + $item = Subscription::get($id, $iSubscriptionType); | ||
| 175 | + if ($item->isValid()) { | ||
| 176 | + $items[] = $item; | ||
| 165 | } | 177 | } |
| 166 | - } else { | ||
| 167 | - $_SESSION["errorMessage"] = $lang_err_database; | ||
| 168 | - return false; | ||
| 169 | } | 178 | } |
| 170 | - return $aSubscriptions; | 179 | + |
| 180 | + return $items; | ||
| 171 | } | 181 | } |
| 172 | 182 | ||
| 173 | /** | 183 | /** |