summaryrefslogtreecommitdiff
path: root/plugins/YammerImport
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-09-21 15:24:14 -0700
committerBrion Vibber <brion@pobox.com>2010-09-28 07:44:20 -0700
commit7c53c1a462a5c6b13370f66c09706624f472056a (patch)
tree16b484385202e56c0d824269b81a1d50968e2774 /plugins/YammerImport
parent7a81bc371309aee0d45dfcec35466557cc6a1ba1 (diff)
Poking around at import funcs...
Diffstat (limited to 'plugins/YammerImport')
-rw-r--r--plugins/YammerImport/yammerimporter.php75
1 files changed, 62 insertions, 13 deletions
diff --git a/plugins/YammerImport/yammerimporter.php b/plugins/YammerImport/yammerimporter.php
index 7710d41b5..2c8d09b9b 100644
--- a/plugins/YammerImport/yammerimporter.php
+++ b/plugins/YammerImport/yammerimporter.php
@@ -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));
}