/* Add them to the database */
foreach(array_unique($match[1]) as $hashtag) {
/* elide characters we don't want in the tag */
- $hashtag = common_canonical_tag($hashtag);
-
- $tag = DB_DataObject::factory('Notice_tag');
- $tag->notice_id = $this->id;
- $tag->tag = $hashtag;
- $tag->created = $this->created;
- $id = $tag->insert();
- if (!$id) {
- $last_error = PEAR::getStaticProperty('DB_DataObject','lastError');
- common_log(LOG_ERR, 'DB error inserting hashtag: ' . $last_error->message);
- common_server_error(sprintf(_('DB error inserting hashtag: %s'), $last_error->message));
- return;
- }
+ $this->saveTag($hashtag);
}
return true;
}
+ function saveTag($hashtag)
+ {
+ $hashtag = common_canonical_tag($hashtag);
+
+ $tag = new Notice_tag();
+ $tag->notice_id = $this->id;
+ $tag->tag = $hashtag;
+ $tag->created = $this->created;
+ $id = $tag->insert();
+
+ if (!$id) {
+ throw new ServerException(sprintf(_('DB error inserting hashtag: %s'),
+ $last_error->message));
+ return;
+ }
+ }
+
static function saveNew($profile_id, $content, $source=null, $is_local=1, $reply_to=null, $uri=null) {
$profile = Profile::staticGet($profile_id);
continue;
}
+ // we automatically add a tag for every group name, too
+
+ $tag = Notice_tag::pkeyGet(array('tag' => common_canonical_tag($nickname),
+ 'notice_id' => $this->id));
+
+ if (is_null($tag)) {
+ $this->saveTag($nickname);
+ }
+
if ($profile->isMember($group)) {
$gi = new Group_inbox();
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
-class Notice_tag extends Memcached_DataObject
+class Notice_tag extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
-
+
static function getStream($tag, $offset=0, $limit=20) {
- $qry =
+ $qry =
'SELECT notice.* ' .
'FROM notice JOIN notice_tag ON notice.id = notice_tag.notice_id ' .
'WHERE notice_tag.tag = "%s" ';
'notice_tag:notice_stream:' . common_keyize($tag),
$offset, $limit);
}
-
+
function blowCache()
{
$cache = common_memcache();
$cache->delete(common_cache_key('notice_tag:notice_stream:' . $this->tag));
}
}
+
+ function &pkeyGet($kv)
+ {
+ return Memcached_DataObject::pkeyGet('Notice_tag', $kv);
+ }
}