summaryrefslogtreecommitdiff
path: root/plugins/YammerImport/yammer-import.php
blob: 7241809ba05733e4095604eb0d00821daf1c23af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php

if (php_sapi_name() != 'cli') {
    die('no');
}

define('INSTALLDIR', dirname(dirname(dirname(__FILE__))));

require INSTALLDIR . "/scripts/commandline.inc";

// temp stuff
require 'yam-config.php';
$yam = new SN_YammerClient($consumerKey, $consumerSecret, $token, $tokenSecret);
$imp = new YammerImporter($yam);

// First, import all the users!
// @fixme follow paging -- we only get 50 at a time
$data = $yam->users();
foreach ($data as $item) {
    $user = $imp->importUser($item);
    echo "Imported Yammer user " . $item['id'] . " as $user->nickname ($user->id)\n";
}

$data = $yam->messages();
// @fixme pull the full group list; this'll be a partial list with less data
// and only for groups referenced in the message set.
foreach ($data['references'] as $item) {
    if ($item['type'] == 'group') {
        $group = $imp->importGroup($item);
        echo "Imported Yammer group " . $item['id'] . " as $group->nickname ($group->id)\n";
    }
}

// Process in reverse chron order...
// @fixme follow paging -- we only get 20 at a time, and start at the most recent!
$messages = $data['messages'];
$messages = array_reverse($messages);
foreach ($messages as $item) {
    $notice = $imp->importNotice($item);
    echo "Imported Yammer notice " . $item['id'] . " as $notice->id\n";
}