コード例 #1
0
 static function fromNoticeInbox($user_id)
 {
     $ids = array();
     $ni = new Notice_inbox();
     $ni->user_id = $user_id;
     $ni->selectAdd();
     $ni->selectAdd('notice_id');
     $ni->orderBy('notice_id DESC');
     $ni->limit(0, self::MAX_NOTICES);
     if ($ni->find()) {
         while ($ni->fetch()) {
             $ids[] = $ni->notice_id;
         }
     }
     $ni->free();
     unset($ni);
     $inbox = new Inbox();
     $inbox->user_id = $user_id;
     $inbox->pack($ids);
     $inbox->fake = true;
     return $inbox;
 }
コード例 #2
0
ファイル: fixup_inboxes.php プロジェクト: Br3nda/laconica
mb_internal_encoding('UTF-8');
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once INSTALLDIR . '/lib/common.php';
$start_at = $argc > 1 ? $argv[1] : null;
common_log(LOG_INFO, 'Updating user inboxes.');
$user = new User();
if ($start_at) {
    $user->whereAdd('id >= ' . $start_at);
}
$cnt = $user->find();
$cache = common_memcache();
while ($user->fetch()) {
    common_log(LOG_INFO, 'Updating inbox for user ' . $user->id);
    $user->query('BEGIN');
    $inbox = new Notice_inbox();
    $result = $inbox->query('INSERT LOW_PRIORITY INTO notice_inbox (user_id, notice_id, created) ' . 'SELECT ' . $user->id . ', notice.id, notice.created ' . 'FROM subscription JOIN notice ON subscription.subscribed = notice.profile_id ' . 'WHERE subscription.subscriber = ' . $user->id . ' ' . 'AND notice.created >= subscription.created ' . 'AND NOT EXISTS (SELECT user_id, notice_id ' . 'FROM notice_inbox ' . 'WHERE user_id = ' . $user->id . ' ' . 'AND notice_id = notice.id)');
    if (is_null($result) || $result === false) {
        common_log_db_error($inbox, 'INSERT', __FILE__);
        continue;
    }
    $orig = clone $user;
    $user->inboxed = 1;
    $result = $user->update($orig);
    if (!$result) {
        common_log_db_error($user, 'UPDATE', __FILE__);
        continue;
    }
    $user->query('COMMIT');
    $inbox->free();
    unset($inbox);
コード例 #3
0
ファイル: triminboxes.php プロジェクト: Br3nda/laconica
if (!empty($id)) {
    $user->whereAdd('id > ' . $id);
}
$cnt = $user->find();
while ($user->fetch()) {
    $inbox_entry = new Notice_inbox();
    $inbox_entry->user_id = $user->id;
    $inbox_entry->orderBy('created DESC');
    $inbox_entry->limit(1000, 1);
    $id = null;
    if ($inbox_entry->find(true)) {
        $id = $inbox_entry->notice_id;
    }
    $inbox_entry->free();
    unset($inbox_entry);
    if (is_null($id)) {
        continue;
    }
    $start = microtime(true);
    $old_inbox = new Notice_inbox();
    $cnt = $old_inbox->query('DELETE from notice_inbox WHERE user_id = ' . $user->id . ' AND notice_id < ' . $id);
    $old_inbox->free();
    unset($old_inbox);
    print "Deleted {$cnt} notices for {$user->nickname} ({$user->id}).\n";
    $finish = microtime(true);
    $delay = 3.0 * ($finish - $start);
    print "Delaying {$delay} seconds...";
    // Wait to let slaves catch up
    usleep($delay * 1000000);
    print "DONE.\n";
}
コード例 #4
0
 function saveStatus($status, $flink)
 {
     $id = $this->ensureProfile($status->user);
     $profile = Profile::staticGet($id);
     if (!$profile) {
         common_log(LOG_ERR, 'Problem saving notice. No associated Profile.');
         return null;
     }
     // XXX: change of screen name?
     $uri = 'http://twitter.com/' . $status->user->screen_name . '/status/' . $status->id;
     $notice = Notice::staticGet('uri', $uri);
     // check to see if we've already imported the status
     if (!$notice) {
         $notice = new Notice();
         $notice->profile_id = $id;
         $notice->uri = $uri;
         $notice->created = strftime('%Y-%m-%d %H:%M:%S', strtotime($status->created_at));
         $notice->content = common_shorten_links($status->text);
         // XXX
         $notice->rendered = common_render_content($notice->content, $notice);
         $notice->source = 'twitter';
         $notice->reply_to = null;
         // XXX lookup reply
         $notice->is_local = Notice::GATEWAY;
         if (Event::handle('StartNoticeSave', array(&$notice))) {
             $id = $notice->insert();
             Event::handle('EndNoticeSave', array($notice));
         }
     }
     if (!Notice_inbox::pkeyGet(array('notice_id' => $notice->id, 'user_id' => $flink->user_id))) {
         // Add to inbox
         $inbox = new Notice_inbox();
         $inbox->user_id = $flink->user_id;
         $inbox->notice_id = $notice->id;
         $inbox->created = $notice->created;
         $inbox->source = NOTICE_INBOX_SOURCE_GATEWAY;
         // From a private source
         $inbox->insert();
     }
 }
コード例 #5
0
ファイル: Notice.php プロジェクト: Br3nda/laconica
 function saveGroups()
 {
     $enabled = common_config('inboxes', 'enabled');
     if ($enabled !== true && $enabled !== 'transitional') {
         return;
     }
     /* extract all !group */
     $count = preg_match_all('/(?:^|\\s)!([A-Za-z0-9]{1,64})/', strtolower($this->content), $match);
     if (!$count) {
         return true;
     }
     $profile = $this->getProfile();
     /* Add them to the database */
     foreach (array_unique($match[1]) as $nickname) {
         /* XXX: remote groups. */
         $group = User_group::staticGet('nickname', $nickname);
         if (!$group) {
             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();
             $gi->group_id = $group->id;
             $gi->notice_id = $this->id;
             $gi->created = common_sql_now();
             $result = $gi->insert();
             if (!$result) {
                 common_log_db_error($gi, 'INSERT', __FILE__);
             }
             // FIXME: do this in an offline daemon
             $inbox = new Notice_inbox();
             $UT = common_config('db', 'type') == 'pgsql' ? '"user"' : 'user';
             $qry = 'INSERT INTO notice_inbox (user_id, notice_id, created, source) ' . "SELECT {$UT}.id, " . $this->id . ", '" . $this->created . "', 2 " . "FROM {$UT} JOIN group_member ON {$UT}.id = group_member.profile_id " . 'WHERE group_member.group_id = ' . $group->id . ' ' . 'AND NOT EXISTS (SELECT user_id, notice_id ' . 'FROM notice_inbox ' . "WHERE user_id = {$UT}.id " . 'AND notice_id = ' . $this->id . ' )';
             if ($enabled === 'transitional') {
                 $qry .= " AND {$UT}.inboxed = 1";
             }
             $result = $inbox->query($qry);
         }
     }
 }