TwitterBridge: partial merge of id_str usage from 0.9.x for improved 32-bit and pre-5.2.10 compatibility. (on 64-bit in 5.2.6 we can pull the integer IDs, but silently lose some precision on the end.)

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)

Conflicts:

	plugins/TwitterBridge/twitterimport.php <- as this hasn't been broken out, the import code is NOT FULLY UPDATED HERE.
This commit is contained in:
Brion Vibber 2010-12-13 12:12:22 -08:00
parent 3f9b8b293d
commit 39cad55711
2 changed files with 33 additions and 4 deletions

View File

@ -218,8 +218,9 @@ class TwitterStatusFetcher extends ParallelizingDaemon
}
if (!empty($timeline)) {
Twitter_synch_status::setLastId($flink->foreign_id, 'home_timeline', $timeline[0]->id);
common_debug("Set lastId value '{$timeline[0]->id}' for foreign id '{$flink->foreign_id}' and timeline 'home_timeline'");
$lastId = twitter_id($timeline[0]);
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

View File

@ -128,6 +128,34 @@ function is_twitter_notice($id)
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
* 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)) {
$retweet = retweet_notice($flink, Notice::staticGet('id', $notice->repeat_of));
if (is_object($retweet)) {
Notice_to_status::saveNew($notice->id, $retweet->id);
Notice_to_status::saveNew($notice->id, twitter_id($retweet));
return true;
} else {
// Our error processing will have decided if we need to requeue
@ -242,7 +270,7 @@ function broadcast_oauth($notice, $flink) {
try {
$status = $client->statusesUpdate($statustxt, $params);
if (!empty($status)) {
Notice_to_status::saveNew($notice->id, $status->id);
Notice_to_status::saveNew($notice->id, twitter_id($status));
}
} catch (OAuthClientException $e) {
return process_error($e, $flink, $notice);