diff options
author | Brion Vibber <brion@pobox.com> | 2010-09-02 15:04:25 -0700 |
---|---|---|
committer | Brion Vibber <brion@pobox.com> | 2010-09-02 15:04:25 -0700 |
commit | 2196d00b1b9a97b498897099c6993383c43b1d44 (patch) | |
tree | 2c0cb5a0d12b93eb743ff93c52c7d3209c619003 /classes | |
parent | 6df8230488f3c4035ac2c3385631978b5a746fbc (diff) | |
parent | e365e709c5bab7d593ee1cde26c8bcfdddcc6780 (diff) |
Merge branch '0.9.x' into 1.0.x
Conflicts:
lib/command.php
Diffstat (limited to 'classes')
-rw-r--r-- | classes/Notice.php | 28 | ||||
-rw-r--r-- | classes/Profile.php | 21 | ||||
-rw-r--r-- | classes/Status_network.php | 11 | ||||
-rw-r--r-- | classes/Status_network_tag.php | 66 |
4 files changed, 105 insertions, 21 deletions
diff --git a/classes/Notice.php b/classes/Notice.php index 5a70f70b6..14477b1b5 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1019,25 +1019,31 @@ class Notice extends Memcached_DataObject if (empty($uris)) { return; } + $sender = Profile::staticGet($this->profile_id); foreach (array_unique($uris) as $uri) { - $user = User::staticGet('uri', $uri); + $profile = Profile::fromURI($uri); - if (!empty($user)) { - if ($user->hasBlocked($sender)) { - continue; - } + if (empty($profile)) { + common_log(LOG_WARNING, "Unable to determine profile for URI '$uri'"); + continue; + } - $reply = new Reply(); + if ($profile->hasBlocked($sender)) { + common_log(LOG_INFO, "Not saving reply to profile {$profile->id} ($uri) from sender {$sender->id} because of a block."); + continue; + } - $reply->notice_id = $this->id; - $reply->profile_id = $user->id; - common_log(LOG_INFO, __METHOD__ . ": saving reply: notice $this->id to profile $user->id"); + $reply = new Reply(); - $id = $reply->insert(); - } + $reply->notice_id = $this->id; + $reply->profile_id = $profile->id; + + common_log(LOG_INFO, __METHOD__ . ": saving reply: notice $this->id to profile $profile->id"); + + $id = $reply->insert(); } return; diff --git a/classes/Profile.php b/classes/Profile.php index d7617f0b7..8f8679550 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -960,4 +960,25 @@ class Profile extends Memcached_DataObject return $feed; } + + static function fromURI($uri) + { + $profile = null; + + if (Event::handle('StartGetProfileFromURI', array($uri, &$profile))) { + // Get a local user or remote (OMB 0.1) profile + $user = User::staticGet('uri', $uri); + if (!empty($user)) { + $profile = $user->getProfile(); + } else { + $remote_profile = Remote_profile::staticGet('uri', $uri); + if (!empty($remote_profile)) { + $profile = Profile::staticGet('id', $remote_profile->profile_id); + } + } + Event::handle('EndGetProfileFromURI', array($uri, $profile)); + } + + return $profile; + } } diff --git a/classes/Status_network.php b/classes/Status_network.php index 5680c1458..c4f37ce1c 100644 --- a/classes/Status_network.php +++ b/classes/Status_network.php @@ -308,15 +308,7 @@ class Status_network extends Safe_DataObject */ function getTags() { - $result = array(); - - $tags = new Status_network_tag(); - $tags->site_id = $this->site_id; - if ($tags->find()) { - while ($tags->fetch()) { - $result[] = $tags->tag; - } - } + $result = Status_network_tag::getTags($this->site_id); // XXX : for backwards compatibility if (empty($result)) { @@ -329,6 +321,7 @@ class Status_network extends Safe_DataObject /** * Save a given set of tags * @param array tags + * @fixme only add/remove differentials */ function setTags($tags) { diff --git a/classes/Status_network_tag.php b/classes/Status_network_tag.php index 18c508bc8..7dab23289 100644 --- a/classes/Status_network_tag.php +++ b/classes/Status_network_tag.php @@ -61,9 +61,73 @@ class Status_network_tag extends Safe_DataObject ###END_AUTOCODE - function pkeyGet($kv) { return Memcached_DataObject::pkeyGet('Status_network_tag', $kv); } + + /** + * Fetch the (possibly cached) tag entries for the given site id. + * Uses status_network's cache settings. + * + * @param string $site_id + * @return array of strings + */ + static function getTags($site_id) + { + $key = 'status_network_tags:' . $site_id; + if (Status_network::$cache) { + $packed = Status_network::$cache->get($key); + if (is_string($packed)) { + if ($packed == '') { + return array(); + } else { + return explode('|', $packed); + } + } + } + + $result = array(); + + $tags = new Status_network_tag(); + $tags->site_id = $site_id; + if ($tags->find()) { + while ($tags->fetch()) { + $result[] = $tags->tag; + } + } + + if (Status_network::$cache) { + $packed = implode('|', $result); + Status_network::$cache->set($key, $packed, 3600); + } + + return $result; + } + + /** + * Drop the cached tag entries for this site. + * Needed after inserting/deleting a tag entry. + */ + function decache() + { + $key = 'status_network_tags:' . $this->site_id; + if (Status_network::$cache) { + Status_network::$cache->delete($key); + } + } + + function insert() + { + $ret = parent::insert(); + $this->decache(); + return $ret; + } + + function delete() + { + $ret = parent::delete(); + $this->decache(); + return $ret; + } } |