static function getSubscription($subscribed, $url) { $sub = new RSSCloudSubscription(); $sub->whereAdd("subscribed = {$subscribed}"); $sub->whereAdd("url = '{$url}'"); $sub->limit(1); if ($sub->find()) { $sub->fetch(); return $sub; } return false; }
/** * Save an RSSCloud subscription * * @param string $feed a valid profile feed * * @return boolean success result */ function saveSubscription($feed) { $user = $this->userFromFeed($feed); $notifyUrl = $this->getNotifyUrl(); $sub = RSSCloudSubscription::getSubscription($user->id, $notifyUrl); if ($sub) { common_log(LOG_INFO, "RSSCloud plugin - {$notifyUrl} refreshed subscription" . " to user {$user->nickname} (id: {$user->id})."); } else { $sub = new RSSCloudSubscription(); $sub->subscribed = $user->id; $sub->url = $notifyUrl; $sub->created = common_sql_now(); if (!$sub->insert()) { common_log_db_error($sub, 'INSERT', __FILE__); return false; } common_log(LOG_INFO, "RSSCloud plugin - {$notifyUrl} subscribed" . " to user {$user->nickname} (id: {$user->id})"); } return true; }
/** * Handle problems posting cloud notifications. Increment the failure * count, or delete the subscription if the maximum number of failures * is exceeded. * * XXX: Redo with proper DB_DataObject methods once I figure out what * what the problem is with pluginized DB_DataObjects. -Z * * @param RSSCloudSubscription $cloudSub the subscription in question * * @return boolean success */ function handleFailure($cloudSub) { $failCnt = $cloudSub->failures + 1; if ($failCnt == self::MAX_FAILURES) { common_log(LOG_INFO, 'Deleting RSSCloud subcription ' . '(max failure count reached), profile: ' . $cloudSub->subscribed . ' handler: ' . $cloudSub->url); // XXX: WTF! ->delete() doesn't work. Clearly, there are some issues with // the DB_DataObject, or my understanding of it. Have to drop into SQL. // $result = $cloudSub->delete(); $qry = 'DELETE from rsscloud_subscription' . ' WHERE subscribed = ' . $cloudSub->subscribed . ' AND url = \'' . $cloudSub->url . '\''; $result = $cloudSub->query($qry); if (!$result) { common_log_db_error($cloudSub, 'DELETE', __FILE__); common_log(LOG_ERR, 'Could not delete RSSCloud subscription.'); } } else { common_debug('Updating failure count on RSSCloud subscription. ' . $failCnt); $failCnt = $cloudSub->failures + 1; // XXX: ->update() not working either, gar! $qry = 'UPDATE rsscloud_subscription' . ' SET failures = ' . $failCnt . ' WHERE subscribed = ' . $cloudSub->subscribed . ' AND url = \'' . $cloudSub->url . '\''; $result = $cloudSub->query($qry); if (!$result) { common_log_db_error($cloudsub, 'UPDATE', __FILE__); common_log(LOG_ERR, 'Could not update failure ' . 'count on RSSCloud subscription'); } } }