forked from GNUsocial/gnu-social
YammerImport: fix for importing over existing user/group nicknames; copies the new data if available onto the existing entry
This commit is contained in:
parent
17e5ffbe4e
commit
6cf7b24017
@ -41,13 +41,22 @@ class YammerImporter
|
|||||||
function importUser($item)
|
function importUser($item)
|
||||||
{
|
{
|
||||||
$data = $this->prepUser($item);
|
$data = $this->prepUser($item);
|
||||||
|
$nickname = $data['options']['nickname'];
|
||||||
|
|
||||||
$profileId = $this->findImportedUser($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::staticGet('nickname', $nickname);
|
||||||
$profile = $user->getProfile();
|
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']) {
|
if ($data['avatar']) {
|
||||||
try {
|
try {
|
||||||
$this->saveAvatar($data['avatar'], $profile);
|
$this->saveAvatar($data['avatar'], $profile);
|
||||||
@ -69,12 +78,21 @@ class YammerImporter
|
|||||||
function importGroup($item)
|
function importGroup($item)
|
||||||
{
|
{
|
||||||
$data = $this->prepGroup($item);
|
$data = $this->prepGroup($item);
|
||||||
|
$nickname = $data['options']['nickname'];
|
||||||
|
|
||||||
$groupId = $this->findImportedGroup($data['orig_id']);
|
$groupId = $this->findImportedGroup($data['orig_id']);
|
||||||
if ($groupId) {
|
if ($groupId) {
|
||||||
return User_group::staticGet('id', $groupId);
|
return User_group::staticGet('id', $groupId);
|
||||||
} else {
|
} 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']) {
|
if ($data['avatar']) {
|
||||||
try {
|
try {
|
||||||
$this->saveAvatar($data['avatar'], $group);
|
$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.
|
* Load or create an imported notice from Yammer data.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user