Fixes for Yammer groups import: pulling explicit list, fixed avatar fetch
This commit is contained in:
parent
7a381f2533
commit
acd7613933
@ -100,7 +100,7 @@ class SN_YammerClient
|
|||||||
*
|
*
|
||||||
* @throws Exception for HTTP error or bad JSON return
|
* @throws Exception for HTTP error or bad JSON return
|
||||||
*/
|
*/
|
||||||
protected function api($method, $params=array())
|
public function api($method, $params=array())
|
||||||
{
|
{
|
||||||
$body = $this->fetchApi("api/v1/$method.json", $params);
|
$body = $this->fetchApi("api/v1/$method.json", $params);
|
||||||
$data = json_decode($body, true);
|
$data = json_decode($body, true);
|
||||||
@ -217,4 +217,20 @@ class SN_YammerClient
|
|||||||
{
|
{
|
||||||
return $this->api('users', $params);
|
return $this->api('users', $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* High-level API hit: fetch all groups in the network (up to 20 at a time).
|
||||||
|
* Return data is the full JSON array returned, listing user items.
|
||||||
|
*
|
||||||
|
* The matching messages themselves will be in the 'users' item within.
|
||||||
|
*
|
||||||
|
* @param array $options optional set of additional params for the request.
|
||||||
|
* @return array of JSON-sourced user data arrays
|
||||||
|
*
|
||||||
|
* @throws Exception on low-level or HTTP error
|
||||||
|
*/
|
||||||
|
public function groups($params=array())
|
||||||
|
{
|
||||||
|
return $this->api('groups', $params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,18 +21,18 @@ foreach ($data as $item) {
|
|||||||
echo "Imported Yammer user " . $item['id'] . " as $user->nickname ($user->id)\n";
|
echo "Imported Yammer user " . $item['id'] . " as $user->nickname ($user->id)\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $yam->messages();
|
// Groups!
|
||||||
// @fixme pull the full group list; this'll be a partial list with less data
|
// @fixme follow paging -- we only get 20 at a time
|
||||||
// and only for groups referenced in the message set.
|
$data = $yam->groups();
|
||||||
foreach ($data['references'] as $item) {
|
foreach ($data as $item) {
|
||||||
if ($item['type'] == 'group') {
|
$group = $imp->importGroup($item);
|
||||||
$group = $imp->importGroup($item);
|
echo "Imported Yammer group " . $item['id'] . " as $group->nickname ($group->id)\n";
|
||||||
echo "Imported Yammer group " . $item['id'] . " as $group->nickname ($group->id)\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Messages!
|
||||||
// Process in reverse chron order...
|
// Process in reverse chron order...
|
||||||
// @fixme follow paging -- we only get 20 at a time, and start at the most recent!
|
// @fixme follow paging -- we only get 20 at a time, and start at the most recent!
|
||||||
|
$data = $yam->messages();
|
||||||
$messages = $data['messages'];
|
$messages = $data['messages'];
|
||||||
$messages = array_reverse($messages);
|
$messages = array_reverse($messages);
|
||||||
foreach ($messages as $item) {
|
foreach ($messages as $item) {
|
||||||
|
@ -51,10 +51,12 @@ class YammerImporter
|
|||||||
} else {
|
} else {
|
||||||
$user = User::register($data['options']);
|
$user = User::register($data['options']);
|
||||||
$profile = $user->getProfile();
|
$profile = $user->getProfile();
|
||||||
try {
|
if ($data['avatar']) {
|
||||||
$this->saveAvatar($data['avatar'], $profile);
|
try {
|
||||||
} catch (Exception $e) {
|
$this->saveAvatar($data['avatar'], $profile);
|
||||||
common_log(LOG_ERROR, "Error importing Yammer avatar: " . $e->getMessage());
|
} catch (Exception $e) {
|
||||||
|
common_log(LOG_ERR, "Error importing Yammer avatar: " . $e->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->recordImportedUser($data['orig_id'], $profile->id);
|
$this->recordImportedUser($data['orig_id'], $profile->id);
|
||||||
return $profile;
|
return $profile;
|
||||||
@ -76,10 +78,12 @@ class YammerImporter
|
|||||||
return User_group::staticGet('id', $groupId);
|
return User_group::staticGet('id', $groupId);
|
||||||
} else {
|
} else {
|
||||||
$group = User_group::register($data['options']);
|
$group = User_group::register($data['options']);
|
||||||
try {
|
if ($data['avatar']) {
|
||||||
$this->saveAvatar($data['avatar'], $group);
|
try {
|
||||||
} catch (Exception $e) {
|
$this->saveAvatar($data['avatar'], $group);
|
||||||
common_log(LOG_ERROR, "Error importing Yammer avatar: " . $e->getMessage());
|
} catch (Exception $e) {
|
||||||
|
common_log(LOG_ERR, "Error importing Yammer avatar: " . $e->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->recordImportedGroup($data['orig_id'], $group->id);
|
$this->recordImportedGroup($data['orig_id'], $group->id);
|
||||||
return $group;
|
return $group;
|
||||||
@ -111,7 +115,7 @@ class YammerImporter
|
|||||||
$content .= ' ' . $upload->shortUrl();
|
$content .= ' ' . $upload->shortUrl();
|
||||||
$uploads[] = $upload;
|
$uploads[] = $upload;
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
common_log(LOG_ERROR, "Error importing Yammer attachment: " . $e->getMessage());
|
common_log(LOG_ERR, "Error importing Yammer attachment: " . $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,7 +258,8 @@ class YammerImporter
|
|||||||
$options['local'] = true;
|
$options['local'] = true;
|
||||||
return array('orig_id' => $origId,
|
return array('orig_id' => $origId,
|
||||||
'orig_url' => $origUrl,
|
'orig_url' => $origUrl,
|
||||||
'options' => $options);
|
'options' => $options,
|
||||||
|
'avatar' => $avatar);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user