Fixes for Twitter bridge breakage on 32-bit servers. New "Snowflake" 64-bit IDs have become too big to fit in the integer portion of double-precision floats, so to reliably use these IDs we need to pull the new string form now.
Machines with 64-bit PHP installation should have had no problems (except on Windows, where integers are still 32 bits)
This commit is contained in:
parent
7e6c0e542f
commit
c169dcb522
|
@ -205,8 +205,9 @@ class TwitterStatusFetcher extends ParallelizingDaemon
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($timeline)) {
|
if (!empty($timeline)) {
|
||||||
Twitter_synch_status::setLastId($flink->foreign_id, 'home_timeline', $timeline[0]->id);
|
$lastId = twitter_id($timeline[0]);
|
||||||
common_debug("Set lastId value '{$timeline[0]->id}' for foreign id '{$flink->foreign_id}' and timeline 'home_timeline'");
|
Twitter_synch_status::setLastId($flink->foreign_id, 'home_timeline', $lastId);
|
||||||
|
common_debug("Set lastId value '$lastId' for foreign id '{$flink->foreign_id}' and timeline 'home_timeline'");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Okay, record the time we synced with Twitter for posterity
|
// Okay, record the time we synced with Twitter for posterity
|
||||||
|
|
|
@ -128,6 +128,34 @@ function is_twitter_notice($id)
|
||||||
return (!empty($n2s));
|
return (!empty($n2s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pull the formatted status ID number from a Twitter status object
|
||||||
|
* returned via JSON from Twitter API.
|
||||||
|
*
|
||||||
|
* Encapsulates checking for the id_str attribute, which is required
|
||||||
|
* to read 64-bit "Snowflake" ID numbers on a 32-bit system -- the
|
||||||
|
* integer id attribute gets corrupted into a double-precision float,
|
||||||
|
* losing a few digits of precision.
|
||||||
|
*
|
||||||
|
* Warning: avoid performing arithmetic or direct comparisons with
|
||||||
|
* this number, as it may get coerced back to a double on 32-bit.
|
||||||
|
*
|
||||||
|
* @param object $status
|
||||||
|
* @param string $field base field name if not 'id'
|
||||||
|
* @return mixed id number as int or string
|
||||||
|
*/
|
||||||
|
function twitter_id($status, $field='id')
|
||||||
|
{
|
||||||
|
$field_str = "{$field}_str";
|
||||||
|
if (isset($status->$field_str)) {
|
||||||
|
// String version of the id -- required on 32-bit systems
|
||||||
|
// since the 64-bit numbers get corrupted as ints.
|
||||||
|
return $status->$field_str;
|
||||||
|
} else {
|
||||||
|
return $status->$field;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if we need to broadcast a notice over the Twitter bridge, and
|
* Check if we need to broadcast a notice over the Twitter bridge, and
|
||||||
* do so if necessary. Will determine whether to do a straight post or
|
* do so if necessary. Will determine whether to do a straight post or
|
||||||
|
@ -148,7 +176,7 @@ function broadcast_twitter($notice)
|
||||||
if (!empty($notice->repeat_of) && is_twitter_notice($notice->repeat_of)) {
|
if (!empty($notice->repeat_of) && is_twitter_notice($notice->repeat_of)) {
|
||||||
$retweet = retweet_notice($flink, Notice::staticGet('id', $notice->repeat_of));
|
$retweet = retweet_notice($flink, Notice::staticGet('id', $notice->repeat_of));
|
||||||
if (is_object($retweet)) {
|
if (is_object($retweet)) {
|
||||||
Notice_to_status::saveNew($notice->id, $retweet->id);
|
Notice_to_status::saveNew($notice->id, twitter_id($retweet));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// Our error processing will have decided if we need to requeue
|
// Our error processing will have decided if we need to requeue
|
||||||
|
@ -242,7 +270,7 @@ function broadcast_oauth($notice, $flink) {
|
||||||
try {
|
try {
|
||||||
$status = $client->statusesUpdate($statustxt, $params);
|
$status = $client->statusesUpdate($statustxt, $params);
|
||||||
if (!empty($status)) {
|
if (!empty($status)) {
|
||||||
Notice_to_status::saveNew($notice->id, $status->id);
|
Notice_to_status::saveNew($notice->id, twitter_id($status));
|
||||||
}
|
}
|
||||||
} catch (OAuthClientException $e) {
|
} catch (OAuthClientException $e) {
|
||||||
return process_error($e, $flink, $notice);
|
return process_error($e, $flink, $notice);
|
||||||
|
|
|
@ -56,7 +56,7 @@ class TwitterImport
|
||||||
|
|
||||||
if (preg_match("/$source/", mb_strtolower($status->source))) {
|
if (preg_match("/$source/", mb_strtolower($status->source))) {
|
||||||
common_debug($this->name() . ' - Skipping import of status ' .
|
common_debug($this->name() . ' - Skipping import of status ' .
|
||||||
$status->id . ' with source ' . $source);
|
twitter_id($status) . ' with source ' . $source);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,23 +86,24 @@ class TwitterImport
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$statusUri = $this->makeStatusURI($status->user->screen_name, $status->id);
|
$statusId = twitter_id($status);
|
||||||
|
$statusUri = $this->makeStatusURI($status->user->screen_name, $statusId);
|
||||||
|
|
||||||
// check to see if we've already imported the status
|
// check to see if we've already imported the status
|
||||||
$n2s = Notice_to_status::staticGet('status_id', $status->id);
|
$n2s = Notice_to_status::staticGet('status_id', $statusId);
|
||||||
|
|
||||||
if (!empty($n2s)) {
|
if (!empty($n2s)) {
|
||||||
common_log(
|
common_log(
|
||||||
LOG_INFO,
|
LOG_INFO,
|
||||||
$this->name() .
|
$this->name() .
|
||||||
" - Ignoring duplicate import: {$status->id}"
|
" - Ignoring duplicate import: {$statusId}"
|
||||||
);
|
);
|
||||||
return Notice::staticGet('id', $n2s->notice_id);
|
return Notice::staticGet('id', $n2s->notice_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it's a retweet, save it as a repeat!
|
// If it's a retweet, save it as a repeat!
|
||||||
if (!empty($status->retweeted_status)) {
|
if (!empty($status->retweeted_status)) {
|
||||||
common_log(LOG_INFO, "Status {$status->id} is a retweet of {$status->retweeted_status->id}.");
|
common_log(LOG_INFO, "Status {$statusId} is a retweet of " . twitter_id($status->retweeted_status) . ".");
|
||||||
$original = $this->saveStatus($status->retweeted_status);
|
$original = $this->saveStatus($status->retweeted_status);
|
||||||
if (empty($original)) {
|
if (empty($original)) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -126,7 +127,7 @@ class TwitterImport
|
||||||
'uri' => $statusUri,
|
'uri' => $statusUri,
|
||||||
'is_local' => Notice::GATEWAY));
|
'is_local' => Notice::GATEWAY));
|
||||||
common_log(LOG_INFO, "Saved {$repeat->id} as a repeat of {$original->id}");
|
common_log(LOG_INFO, "Saved {$repeat->id} as a repeat of {$original->id}");
|
||||||
Notice_to_status::saveNew($repeat->id, $status->id);
|
Notice_to_status::saveNew($repeat->id, $statusId);
|
||||||
return $repeat;
|
return $repeat;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,17 +146,18 @@ class TwitterImport
|
||||||
|
|
||||||
$notice->reply_to = null;
|
$notice->reply_to = null;
|
||||||
|
|
||||||
if (!empty($status->in_reply_to_status_id)) {
|
$replyTo = twitter_id($status, 'in_reply_to_status_id');
|
||||||
common_log(LOG_INFO, "Status {$status->id} is a reply to status {$status->in_reply_to_status_id}");
|
if (!empty($replyTo)) {
|
||||||
$n2s = Notice_to_status::staticGet('status_id', $status->in_reply_to_status_id);
|
common_log(LOG_INFO, "Status {$statusId} is a reply to status {$replyTo}");
|
||||||
|
$n2s = Notice_to_status::staticGet('status_id', $replyTo);
|
||||||
if (empty($n2s)) {
|
if (empty($n2s)) {
|
||||||
common_log(LOG_INFO, "Couldn't find local notice for status {$status->in_reply_to_status_id}");
|
common_log(LOG_INFO, "Couldn't find local notice for status {$replyTo}");
|
||||||
} else {
|
} else {
|
||||||
$reply = Notice::staticGet('id', $n2s->notice_id);
|
$reply = Notice::staticGet('id', $n2s->notice_id);
|
||||||
if (empty($reply)) {
|
if (empty($reply)) {
|
||||||
common_log(LOG_INFO, "Couldn't find local notice for status {$status->in_reply_to_status_id}");
|
common_log(LOG_INFO, "Couldn't find local notice for status {$replyTo}");
|
||||||
} else {
|
} else {
|
||||||
common_log(LOG_INFO, "Found local notice {$reply->id} for status {$status->in_reply_to_status_id}");
|
common_log(LOG_INFO, "Found local notice {$reply->id} for status {$replyTo}");
|
||||||
$notice->reply_to = $reply->id;
|
$notice->reply_to = $reply->id;
|
||||||
$notice->conversation = $reply->conversation;
|
$notice->conversation = $reply->conversation;
|
||||||
}
|
}
|
||||||
|
@ -165,7 +167,7 @@ class TwitterImport
|
||||||
if (empty($notice->conversation)) {
|
if (empty($notice->conversation)) {
|
||||||
$conv = Conversation::create();
|
$conv = Conversation::create();
|
||||||
$notice->conversation = $conv->id;
|
$notice->conversation = $conv->id;
|
||||||
common_log(LOG_INFO, "No known conversation for status {$status->id} so making a new one {$conv->id}.");
|
common_log(LOG_INFO, "No known conversation for status {$statusId} so making a new one {$conv->id}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$notice->is_local = Notice::GATEWAY;
|
$notice->is_local = Notice::GATEWAY;
|
||||||
|
@ -186,7 +188,7 @@ class TwitterImport
|
||||||
Event::handle('EndNoticeSave', array($notice));
|
Event::handle('EndNoticeSave', array($notice));
|
||||||
}
|
}
|
||||||
|
|
||||||
Notice_to_status::saveNew($notice->id, $status->id);
|
Notice_to_status::saveNew($notice->id, $statusId);
|
||||||
|
|
||||||
$this->saveStatusMentions($notice, $status);
|
$this->saveStatusMentions($notice, $status);
|
||||||
$this->saveStatusAttachments($notice, $status);
|
$this->saveStatusAttachments($notice, $status);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user