We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit 7c53c1a4 authored by Brion Vibber's avatar Brion Vibber

Poking around at import funcs...

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