function initializeInbox($user)
{
    if (!have_option('q', 'quiet')) {
        print "Initializing inbox for {$user->nickname}...";
    }
    $inbox = Inbox::staticGet('user_id', $user->id);
    if ($inbox && !empty($inbox->fake)) {
        if (!have_option('q', 'quiet')) {
            echo "(replacing faux cached inbox)";
        }
        $inbox = false;
    }
    if (!empty($inbox)) {
        if (!have_option('q', 'quiet')) {
            print "SKIP\n";
        }
    } else {
        $inbox = Inbox::initialize($user->id);
        if (!have_option('q', 'quiet')) {
            if (empty($inbox)) {
                print "ERR\n";
            } else {
                print "DONE\n";
            }
        }
    }
}
 /**
  * Append the given notice to the given user's inbox.
  * Caching updates are managed for the inbox itself.
  *
  * If the notice is already in this inbox, the second
  * add will be silently dropped.
  *
  * @param int @user_id
  * @param int $notice_id
  * @return boolean success
  */
 static function insertNotice($user_id, $notice_id)
 {
     $inbox = DB_DataObject::staticGet('inbox', 'user_id', $user_id);
     if (empty($inbox)) {
         $inbox = Inbox::initialize($user_id);
     }
     if (empty($inbox)) {
         return false;
     }
     $ids = $inbox->unpack();
     if (in_array(intval($notice_id), $ids)) {
         // Already in there, we probably re-ran some inbox adds
         // due to an error. Skip the dupe silently.
         return true;
     }
     $result = $inbox->query(sprintf('UPDATE inbox ' . 'set notice_ids = concat(cast(0x%08x as binary(4)), ' . 'substr(notice_ids, 1, %d)) ' . 'WHERE user_id = %d', $notice_id, 4 * (self::MAX_NOTICES - 1), $user_id));
     if ($result) {
         self::blow('inbox:user_id:%d', $user_id);
     }
     return $result;
 }
Example #3
0
 /**
  * Append the given notice to the given user's inbox.
  * Caching updates are managed for the inbox itself.
  *
  * If the notice is already in this inbox, the second
  * add will be silently dropped.
  *
  * @param int @user_id
  * @param int $notice_id
  * @return boolean success
  */
 static function insertNotice($user_id, $notice_id)
 {
     // Going straight to the DB rather than trusting our caching
     // during an update. Note: not using DB_DataObject::staticGet,
     // which is unsafe to use directly (in-process caching causes
     // memory leaks, which accumulate in queue processes).
     $inbox = new Inbox();
     if (!$inbox->get('user_id', $user_id)) {
         $inbox = Inbox::initialize($user_id);
     }
     if (empty($inbox)) {
         return false;
     }
     $ids = $inbox->unpack();
     if (in_array(intval($notice_id), $ids)) {
         // Already in there, we probably re-ran some inbox adds
         // due to an error. Skip the dupe silently.
         return true;
     }
     $result = $inbox->query(sprintf('UPDATE inbox ' . 'set notice_ids = concat(cast(0x%08x as binary(4)), ' . 'substr(notice_ids, 1, %d)) ' . 'WHERE user_id = %d', $notice_id, 4 * (self::MAX_NOTICES - 1), $user_id));
     if ($result) {
         self::blow('inbox:user_id:%d', $user_id);
     }
     return $result;
 }