summaryrefslogtreecommitdiff
path: root/plugins/YammerImport
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-09-28 13:24:25 -0700
committerBrion Vibber <brion@pobox.com>2010-09-28 15:59:29 -0700
commitc62e4d08008faf7fdfb67f0e5eda3db6d8d1ceef (patch)
treebac39f8633e4a0804d79bbff403283599eb73fec /plugins/YammerImport
parent3a1f1a49b22c2be4234a78cd36016a373d3ca5fc (diff)
YammerImport: fix for importing over existing user/group nicknames; copies the new data if available onto the existing entry
Diffstat (limited to 'plugins/YammerImport')
-rw-r--r--plugins/YammerImport/lib/yammerimporter.php37
1 files changed, 34 insertions, 3 deletions
diff --git a/plugins/YammerImport/lib/yammerimporter.php b/plugins/YammerImport/lib/yammerimporter.php
index ae916dc22..ed1191525 100644
--- a/plugins/YammerImport/lib/yammerimporter.php
+++ b/plugins/YammerImport/lib/yammerimporter.php
@@ -41,13 +41,22 @@ class YammerImporter
function importUser($item)
{
$data = $this->prepUser($item);
+ $nickname = $data['options']['nickname'];
$profileId = $this->findImportedUser($data['orig_id']);
if ($profileId) {
return Profile::staticGet('id', $profileId);
} else {
- $user = User::register($data['options']);
- $profile = $user->getProfile();
+ $user = User::staticGet('nickname', $nickname);
+ if ($user) {
+ common_log(LOG_WARN, "Copying Yammer profile info onto existing user $nickname");
+ $profile = $user->getProfile();
+ $this->savePropertiesOn($profile, $data['options'],
+ array('fullname', 'homepage', 'bio', 'location'));
+ } else {
+ $user = User::register($data['options']);
+ $profile = $user->getProfile();
+ }
if ($data['avatar']) {
try {
$this->saveAvatar($data['avatar'], $profile);
@@ -69,12 +78,21 @@ class YammerImporter
function importGroup($item)
{
$data = $this->prepGroup($item);
+ $nickname = $data['options']['nickname'];
$groupId = $this->findImportedGroup($data['orig_id']);
if ($groupId) {
return User_group::staticGet('id', $groupId);
} else {
- $group = User_group::register($data['options']);
+ $local = Local_group::staticGet('nickname', $nickname);
+ if ($local) {
+ common_log(LOG_WARN, "Copying Yammer group info onto existing group $nickname");
+ $group = User_group::staticGet('id', $local->group_id);
+ $this->savePropertiesOn($group, $data['options'],
+ array('fullname', 'description'));
+ } else {
+ $group = User_group::register($data['options']);
+ }
if ($data['avatar']) {
try {
$this->saveAvatar($data['avatar'], $group);
@@ -87,6 +105,19 @@ class YammerImporter
}
}
+ private function savePropertiesOn($target, $options, $propList)
+ {
+ $changed = 0;
+ $orig = clone($target);
+ foreach ($propList as $prop) {
+ if (!empty($options[$prop]) && $target->$prop != $options[$prop]) {
+ $target->$prop = $options[$prop];
+ $changed++;
+ }
+ }
+ $target->update($orig);
+ }
+
/**
* Load or create an imported notice from Yammer data.
*