Merge pull request #730 from annando/more-twitter-logging

Added some logging for Twitter to better analyse problems
This commit is contained in:
Hypolite Petovan 2018-09-03 18:52:38 -04:00 committed by GitHub
commit f42f1d3b12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -888,16 +888,19 @@ function twitter_fetchtimeline(App $a, $uid)
try { try {
$items = $connection->get('statuses/user_timeline', $parameters); $items = $connection->get('statuses/user_timeline', $parameters);
} catch (TwitterOAuthException $e) { } catch (TwitterOAuthException $e) {
logger('twitter_fetchtimeline: Error fetching timeline for user ' . $uid . ': ' . $e->getMessage()); logger('Error fetching timeline for user ' . $uid . ': ' . $e->getMessage());
return; return;
} }
if (!is_array($items)) { if (!is_array($items)) {
logger('No items for user ' . $uid, LOGGER_INFO);
return; return;
} }
$posts = array_reverse($items); $posts = array_reverse($items);
logger('Starting from ID ' . $lastid . ' for user ' . $uid, LOGGER_DEBUG);
if (count($posts)) { if (count($posts)) {
foreach ($posts as $post) { foreach ($posts as $post) {
if ($post->id_str > $lastid) { if ($post->id_str > $lastid) {
@ -913,19 +916,22 @@ function twitter_fetchtimeline(App $a, $uid)
$_SESSION["authenticated"] = true; $_SESSION["authenticated"] = true;
$_SESSION["uid"] = $uid; $_SESSION["uid"] = $uid;
logger('Preparing Twitter ID ' . $post->id_str . ' for user ' . $uid, LOGGER_DEBUG);
$_REQUEST = twitter_do_mirrorpost($a, $uid, $post); $_REQUEST = twitter_do_mirrorpost($a, $uid, $post);
if (empty($_REQUEST['body'])) { if (empty($_REQUEST['body'])) {
continue; continue;
} }
logger('twitter: posting for user ' . $uid); logger('Posting Twitter ID ' . $post->id_str . ' for user ' . $uid);
item_post($a); item_post($a);
} }
} }
} }
PConfig::set($uid, 'twitter', 'lastid', $lastid); PConfig::set($uid, 'twitter', 'lastid', $lastid);
logger('Last ID for user ' . $uid . ' is now ' . $lastid, LOGGER_DEBUG);
} }
function twitter_queue_hook(App $a) function twitter_queue_hook(App $a)
@ -1581,7 +1587,7 @@ function twitter_fetchhometimeline(App $a, $uid)
$create_user = PConfig::get($uid, 'twitter', 'create_user'); $create_user = PConfig::get($uid, 'twitter', 'create_user');
$mirror_posts = PConfig::get($uid, 'twitter', 'mirror_posts'); $mirror_posts = PConfig::get($uid, 'twitter', 'mirror_posts');
logger("twitter_fetchhometimeline: Fetching for user " . $uid, LOGGER_DEBUG); logger("Fetching timeline for user " . $uid, LOGGER_DEBUG);
$application_name = Config::get('twitter', 'application_name'); $application_name = Config::get('twitter', 'application_name');
@ -1596,7 +1602,7 @@ function twitter_fetchhometimeline(App $a, $uid)
try { try {
$own_contact = twitter_fetch_own_contact($a, $uid); $own_contact = twitter_fetch_own_contact($a, $uid);
} catch (TwitterOAuthException $e) { } catch (TwitterOAuthException $e) {
logger('twitter_fetchhometimeline: Error fetching own contact for user ' . $uid . ': ' . $e->getMessage()); logger('Error fetching own contact for user ' . $uid . ': ' . $e->getMessage());
return; return;
} }
@ -1607,7 +1613,7 @@ function twitter_fetchhometimeline(App $a, $uid)
if (DBA::isResult($r)) { if (DBA::isResult($r)) {
$own_id = $r[0]["nick"]; $own_id = $r[0]["nick"];
} else { } else {
logger("twitter_fetchhometimeline: Own twitter contact not found for user " . $uid, LOGGER_DEBUG); logger("Own twitter contact not found for user " . $uid);
return; return;
} }
@ -1617,14 +1623,14 @@ function twitter_fetchhometimeline(App $a, $uid)
if (DBA::isResult($r)) { if (DBA::isResult($r)) {
$self = $r[0]; $self = $r[0];
} else { } else {
logger("twitter_fetchhometimeline: Own contact not found for user " . $uid, LOGGER_DEBUG); logger("Own contact not found for user " . $uid);
return; return;
} }
$u = q("SELECT * FROM user WHERE uid = %d LIMIT 1", $u = q("SELECT * FROM user WHERE uid = %d LIMIT 1",
intval($uid)); intval($uid));
if (!DBA::isResult($u)) { if (!DBA::isResult($u)) {
logger("twitter_fetchhometimeline: Own user not found for user " . $uid, LOGGER_DEBUG); logger("Own user not found for user " . $uid);
return; return;
} }
@ -1642,18 +1648,23 @@ function twitter_fetchhometimeline(App $a, $uid)
try { try {
$items = $connection->get('statuses/home_timeline', $parameters); $items = $connection->get('statuses/home_timeline', $parameters);
} catch (TwitterOAuthException $e) { } catch (TwitterOAuthException $e) {
logger('twitter_fetchhometimeline: Error fetching home timeline: ' . $e->getMessage()); logger('Error fetching home timeline for user ' . $uid . ': ' . $e->getMessage());
return; return;
} }
if (!is_array($items)) { if (!is_array($items)) {
logger("twitter_fetchhometimeline: Error fetching home timeline: " . print_r($items, true), LOGGER_DEBUG); logger('No array while fetching home timeline for user ' . $uid . ': ' . print_r($items, true));
return;
}
if (empty($items)) {
logger('No new timeline content for user ' . $uid, LOGGER_INFO);
return; return;
} }
$posts = array_reverse($items); $posts = array_reverse($items);
logger("twitter_fetchhometimeline: Fetching timeline for user " . $uid . " " . sizeof($posts) . " items", LOGGER_DEBUG); logger('Fetching timeline from ID ' . $lastid . ' for user ' . $uid . ' ' . sizeof($posts) . ' items', LOGGER_DEBUG);
if (count($posts)) { if (count($posts)) {
foreach ($posts as $post) { foreach ($posts as $post) {
@ -1667,12 +1678,12 @@ function twitter_fetchhometimeline(App $a, $uid)
} }
if (stristr($post->source, $application_name) && $post->user->screen_name == $own_id) { if (stristr($post->source, $application_name) && $post->user->screen_name == $own_id) {
logger("twitter_fetchhometimeline: Skip previously sended post", LOGGER_DEBUG); logger("Skip previously sent post", LOGGER_DEBUG);
continue; continue;
} }
if ($mirror_posts && $post->user->screen_name == $own_id && $post->in_reply_to_status_id_str == "") { if ($mirror_posts && $post->user->screen_name == $own_id && $post->in_reply_to_status_id_str == "") {
logger("twitter_fetchhometimeline: Skip post that will be mirrored", LOGGER_DEBUG); logger("Skip post that will be mirrored", LOGGER_DEBUG);
continue; continue;
} }
@ -1680,9 +1691,12 @@ function twitter_fetchhometimeline(App $a, $uid)
twitter_fetchparentposts($a, $uid, $post, $connection, $self); twitter_fetchparentposts($a, $uid, $post, $connection, $self);
} }
logger('Preparing post ' . $post->id_str . ' for user ' . $uid, LOGGER_DEBUG);
$postarray = twitter_createpost($a, $uid, $post, $self, $create_user, true, false); $postarray = twitter_createpost($a, $uid, $post, $self, $create_user, true, false);
if (empty($postarray['body']) || trim($postarray['body']) == "") { if (empty($postarray['body']) || trim($postarray['body']) == "") {
logger('Empty body for post ' . $post->id_str . ' and user ' . $uid, LOGGER_DEBUG);
continue; continue;
} }
@ -1698,11 +1712,13 @@ function twitter_fetchhometimeline(App $a, $uid)
$item = Item::insert($postarray, false, $notify); $item = Item::insert($postarray, false, $notify);
$postarray["id"] = $item; $postarray["id"] = $item;
logger('twitter_fetchhometimeline: User ' . $self["nick"] . ' posted home timeline item ' . $item); logger('User ' . uid . ' posted home timeline item ' . $item);
} }
} }
PConfig::set($uid, 'twitter', 'lasthometimelineid', $lastid); PConfig::set($uid, 'twitter', 'lasthometimelineid', $lastid);
logger('Last timeline ID for user ' . $uid . ' is now ' . $lastid, LOGGER_DEBUG);
// Fetching mentions // Fetching mentions
$lastid = PConfig::get($uid, 'twitter', 'lastmentionid'); $lastid = PConfig::get($uid, 'twitter', 'lastmentionid');
@ -1715,18 +1731,18 @@ function twitter_fetchhometimeline(App $a, $uid)
try { try {
$items = $connection->get('statuses/mentions_timeline', $parameters); $items = $connection->get('statuses/mentions_timeline', $parameters);
} catch (TwitterOAuthException $e) { } catch (TwitterOAuthException $e) {
logger('twitter_fetchhometimeline: Error fetching mentions: ' . $e->getMessage()); logger('Error fetching mentions: ' . $e->getMessage());
return; return;
} }
if (!is_array($items)) { if (!is_array($items)) {
logger("twitter_fetchhometimeline: Error fetching mentions: " . print_r($items, true), LOGGER_DEBUG); logger("Error fetching mentions: " . print_r($items, true), LOGGER_DEBUG);
return; return;
} }
$posts = array_reverse($items); $posts = array_reverse($items);
logger("twitter_fetchhometimeline: Fetching mentions for user " . $uid . " " . sizeof($posts) . " items", LOGGER_DEBUG); logger("Fetching mentions for user " . $uid . " " . sizeof($posts) . " items", LOGGER_DEBUG);
if (count($posts)) { if (count($posts)) {
foreach ($posts as $post) { foreach ($posts as $post) {
@ -1750,11 +1766,13 @@ function twitter_fetchhometimeline(App $a, $uid)
$item = Item::insert($postarray); $item = Item::insert($postarray);
logger('twitter_fetchhometimeline: User ' . $self["nick"] . ' posted mention timeline item ' . $item); logger('User ' . $uid . ' posted mention timeline item ' . $item);
} }
} }
PConfig::set($uid, 'twitter', 'lastmentionid', $lastid); PConfig::set($uid, 'twitter', 'lastmentionid', $lastid);
logger('Last mentions ID for user ' . $uid . ' is now ' . $lastid, LOGGER_DEBUG);
} }
function twitter_fetch_own_contact(App $a, $uid) function twitter_fetch_own_contact(App $a, $uid)