<?php
/**
* StatusNet - the distributed open-source microblogging tool
- * Copyright (C) 2008, 2009, StatusNet, Inc.
+ * Copyright (C) 2008-2010, StatusNet, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
$flink->find();
$flinks = array();
- common_log(LOG_INFO, "hello");
while ($flink->fetch()) {
$conn->disconnect();
- // XXX: Could not find a less brutal way to blow
+ // XXX: Couldn't find a less brutal way to blow
// away a cached connection
global $_DB_DATAOBJECT;
{
if (empty($flink)) {
common_log(LOG_WARNING, $this->name() .
- " - Cannot retrieve Foreign_link for foreign ID $fid");
+ " - Can't retrieve Foreign_link for foreign ID $fid");
return;
}
continue;
}
- $this->saveStatus($status, $flink);
+ $notice = null;
+
+ $notice = $this->saveStatus($status, $flink);
+
+ if (!empty($notice)) {
+ common_broadcast_notice($notice);
+ }
}
// Okay, record the time we synced with Twitter for posterity
$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
+ $notice = Notice::staticGet('uri', $uri);
+
if (empty($notice)) {
+ // XXX: transaction here?
+
$notice = new Notice();
$notice->profile_id = $id;
$notice->is_local = Notice::GATEWAY;
if (Event::handle('StartNoticeSave', array(&$notice))) {
- $id = $notice->insert();
+ $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::insertNotice($flink->user_id, $notice->id);
+
+ $notice->blowOnInsert();
+
+ return $notice;
+ }
- $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
+ /**
+ * Look up a Profile by profileurl field. Profile::staticGet() was
+ * not working consistently.
+ *
+ * @param string $url the profile url
+ *
+ * @return mixed the first profile with that url, or null
+ */
- $inbox->insert();
+ function getProfileByUrl($nickname, $profileurl)
+ {
+ $profile = new Profile();
+ $profile->nickname = $nickname;
+ $profile->profileurl = $profileurl;
+ $profile->limit(1);
+
+ if ($profile->find()) {
+ $profile->fetch();
+ return $profile;
}
+
+ return null;
}
function ensureProfile($user)
// check to see if there's already a profile for this user
$profileurl = 'http://twitter.com/' . $user->screen_name;
- $profile = Profile::staticGet('profileurl', $profileurl);
+ $profile = $this->getProfileByUrl($user->screen_name, $profileurl);
if (!empty($profile)) {
common_debug($this->name() .
return $profile->id;
} else {
+
common_debug($this->name() . ' - Adding profile and remote profile ' .
"for Twitter user: $profileurl.");
$profile->profileurl = $profileurl;
$profile->created = common_sql_now();
- $id = $profile->insert();
+ try {
+ $id = $profile->insert();
+ } catch(Exception $e) {
+ common_log(LOG_WARNING, $this->name . ' Couldn\'t insert profile - ' . $e->getMessage());
+ }
if (empty($id)) {
common_log_db_error($profile, 'INSERT', __FILE__);
$remote_pro->uri = $profileurl;
$remote_pro->created = common_sql_now();
- $rid = $remote_pro->insert();
+ try {
+ $rid = $remote_pro->insert();
+ } catch (Exception $e) {
+ common_log(LOG_WARNING, $this->name() . ' Couldn\'t save remote profile - ' . $e->getMessage());
+ }
if (empty($rid)) {
common_log_db_error($profile, 'INSERT', __FILE__);
if ($this->fetchAvatar($url, $filename)) {
$this->newAvatar($id, $size, $mediatype, $filename);
} else {
- common_log(LOG_WARNING, $this->id() .
+ common_log(LOG_WARNING, $id() .
" - Problem fetching Avatar: $url");
}
}
$profile = Profile::staticGet($profile_id);
if (empty($profile)) {
- common_debug($this->name() . " - Could not get profile: $profile_id!");
+ common_debug($this->name() . " - Couldn't get profile: $profile_id!");
return;
}
$avatar->created = common_sql_now();
- $id = $avatar->insert();
+ try {
+ $id = $avatar->insert();
+ } catch (Exception $e) {
+ common_log(LOG_WARNING, $this->name() . ' Couldn\'t insert avatar - ' . $e->getMessage());
+ }
if (empty($id)) {
common_log_db_error($avatar, 'INSERT', __FILE__);
$ok = file_put_contents($avatarfile, $response->getBody());
if (!$ok) {
common_log(LOG_WARNING, $this->name() .
- " - Could not open file $filename");
+ " - Couldn't open file $filename");
return false;
}
} else {