function cleanupChannels() { $rc = new Realtime_channel(); $rc->selectAdd(); $rc->selectAdd('channel_key'); $rc->whereAdd('modified < "' . common_sql_date(time() - Realtime_channel::TIMEOUT) . '"'); if ($rc->find()) { $keys = $rc->fetchAll(); foreach ($keys as $key) { $rc = Realtime_channel::staticGet('channel_key', $key); if (!empty($rc)) { printfv("Deleting realtime channel '{$key}'\n"); $rc->delete(); } } } }
/** * For initializing members of the class. * * @param array $argarray misc. arguments * * @return boolean true */ function prepare($argarray) { parent::prepare($argarray); if (!$this->isPost()) { // TRANS: Client exception. Do not translate POST. throw new ClientException(_m('You have to POST it.')); } $this->channelKey = $this->trimmed('channelkey'); if (empty($this->channelKey)) { // TRANS: Client exception thrown when the channel key argument is missing. throw new ClientException(_m('No channel key argument.')); } $this->channel = Realtime_channel::getKV('channel_key', $this->channelKey); if (empty($this->channel)) { // TRANS: Client exception thrown when referring to a non-existing channel. throw new ClientException(_m('No such channel.')); } return true; }
static function fetchChannel($user_id, $action, $arg1, $arg2) { $channel = new Realtime_channel(); if (is_null($user_id)) { $channel->whereAdd('user_id is null'); } else { $channel->user_id = $user_id; } $channel->action = $action; if (is_null($arg1)) { $channel->whereAdd('arg1 is null'); } else { $channel->arg1 = $arg1; } if (is_null($arg2)) { $channel->whereAdd('arg2 is null'); } else { $channel->arg2 = $arg2; } if ($channel->find(true)) { $channel->increment(); return $channel; } else { return null; } }
function _getChannel($action) { $timeline = null; $arg1 = null; $arg2 = null; $action_name = $action->trimmed('action'); // FIXME: lists // FIXME: search (!) // FIXME: profile + tag switch ($action_name) { case 'public': // no arguments break; case 'tag': $tag = $action->trimmed('tag'); if (!empty($tag)) { $arg1 = $tag; } else { $this->log(LOG_NOTICE, "Unexpected 'tag' action without tag argument"); return null; } break; case 'showstream': case 'all': case 'replies': case 'showgroup': $nickname = common_canonical_nickname($action->trimmed('nickname')); if (!empty($nickname)) { $arg1 = $nickname; } else { $this->log(LOG_NOTICE, "Unexpected {$action_name} action without nickname argument."); return null; } break; default: return null; } $user = common_current_user(); $user_id = !empty($user) ? $user->id : null; $channel = Realtime_channel::getChannel($user_id, $action_name, $arg1, $arg2); return $channel; }