Poking around at import funcs...

This commit is contained in:
Brion Vibber 2010-09-21 15:24:14 -07:00
parent 05af14e1ca
commit 9b1b9b711b
1 changed files with 62 additions and 13 deletions

View File

@ -26,22 +26,27 @@
class YammerImporter class YammerImporter
{ {
protected $users=array();
protected $groups=array();
protected $notices=array();
/** /**
* Load or create an imported profile from Yammer data. * Load or create an imported profile from Yammer data.
* *
* @param object $item loaded JSON data for Yammer importer * @param object $item loaded JSON data for Yammer importer
* @return Profile * @return Profile
*/ */
function importUserProfile($item) function importUser($item)
{ {
$data = $this->prepUser($item); $data = $this->prepUser($item);
$profileId = $this->findImportedProfile($data['orig_id']); $profileId = $this->findImportedUser($data['orig_id']);
if ($profileId) { if ($profileId) {
return Profile::staticGet('id', $profileId); return Profile::staticGet('id', $profileId);
} else { } else {
$user = User::register($data['options']); $user = User::register($data['options']);
// @fixme set avatar! // @fixme set avatar!
$this->recordImportedUser($data['orig_id'], $user->id);
return $user->getProfile(); return $user->getProfile();
} }
} }
@ -62,6 +67,7 @@ class YammerImporter
} else { } else {
$group = User_group::register($data['options']); $group = User_group::register($data['options']);
// @fixme set avatar! // @fixme set avatar!
$this->recordImportedGroup($data['orig_id'], $group->id);
return $group; return $group;
} }
} }
@ -85,10 +91,17 @@ class YammerImporter
$data['source'], $data['source'],
$data['options']); $data['options']);
// @fixme attachments? // @fixme attachments?
$this->recordImportedNotice($data['orig_id'], $notice->id);
return $notice; return $notice;
} }
} }
/**
* Pull relevant info out of a Yammer data record for a user import.
*
* @param array $item
* @return array
*/
function prepUser($item) function prepUser($item)
{ {
if ($item['type'] != 'user') { if ($item['type'] != 'user') {
@ -121,6 +134,12 @@ class YammerImporter
} }
/**
* Pull relevant info out of a Yammer data record for a group import.
*
* @param array $item
* @return array
*/
function prepGroup($item) function prepGroup($item)
{ {
if ($item['type'] != 'group') { if ($item['type'] != 'group') {
@ -151,6 +170,12 @@ class YammerImporter
'options' => $options); 'options' => $options);
} }
/**
* Pull relevant info out of a Yammer data record for a notice import.
*
* @param array $item
* @return array
*/
function prepNotice($item) function prepNotice($item)
{ {
if (isset($item['type']) && $item['type'] != 'message') { if (isset($item['type']) && $item['type'] != 'message') {
@ -160,7 +185,7 @@ class YammerImporter
$origId = $item['id']; $origId = $item['id'];
$origUrl = $item['url']; $origUrl = $item['url'];
$profile = $this->findImportedProfile($item['sender_id']); $profile = $this->findImportedUser($item['sender_id']);
$content = $item['body']['plain']; $content = $item['body']['plain'];
$source = 'yammer'; $source = 'yammer';
$options = array(); $options = array();
@ -185,22 +210,46 @@ class YammerImporter
'options' => $options); 'options' => $options);
} }
function findImportedProfile($userId) private function findImportedUser($origId)
{ {
// @fixme if (isset($this->users[$origId])) {
return $userId; return $this->users[$origId];
} else {
return false;
}
} }
function findImportedGroup($groupId) private function findImportedGroup($origId)
{ {
// @fixme if (isset($this->groups[$origId])) {
return $groupId; return $this->groups[$origId];
} else {
return false;
}
} }
function findImportedNotice($messageId) private function findImportedNotice($origId)
{ {
// @fixme if (isset($this->notices[$origId])) {
return $messageId; return $this->notices[$origId];
} else {
return false;
}
}
private function recordImportedUser($origId, $userId)
{
$this->users[$origId] = $userId;
}
private function recordImportedGroup($origId, $groupId)
{
$this->groups[$origId] = $groupId;
}
private function recordImportedNotice($origId, $noticeId)
{
$this->notices[$origId] = $noticeId;
} }
/** /**
@ -208,7 +257,7 @@ class YammerImporter
* @param string $ts * @param string $ts
* @return string * @return string
*/ */
function timestamp($ts) private function timestamp($ts)
{ {
return common_sql_date(strtotime($ts)); return common_sql_date(strtotime($ts));
} }