summaryrefslogtreecommitdiff
path: root/plugins/YammerImport/yamdump.php
blob: 96127dd1762a8c55a6972db1f86ce7e7cac57bbb (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?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();

$data = $yam->messages();
var_dump($data);

/*
  ["messages"]=>
  ["meta"]=> // followed_user_ids, current_user_id, etc
  ["threaded_extended"]=> // empty!
  ["references"]=> // lists the users, threads, replied messages, tags
*/

// 1) we're getting messages in descending order, but we'll want to process ascending
// 2) we'll need to pull out all those referenced items too?
// 3) do we need to page over or anything?

// 20 qualifying messages per hit...
// use older_than to grab more
// (better if we can go in reverse though!)
// meta: The older-available element indicates whether messages older than those shown are available to be fetched. See the older_than parameter mentioned above.

foreach ($data['references'] as $item) {
    if ($item['type'] == 'user') {
        $user = $imp->prepUser($item);
        var_dump($user);
    } else if ($item['type'] == 'group') {
        $group = $imp->prepGroup($item);
        var_dump($group);
    } else if ($item['type'] == 'tag') {
        // could need these if we work from the parsed message text
        // otherwise, the #blarf in orig text is fine.
    } else if ($item['type'] == 'thread') {
        // Shouldn't need thread info; we'll reconstruct conversations
        // from the reply-to chains.
    } else if ($item['type'] == 'message') {
        // If we're processing everything, then we don't need the refs here.
    } else {
        echo "(skipping unknown ref: " . $item['type'] . ")\n";
    }
}

// Process in reverse chron order...
// @fixme follow paging
$messages = $data['messages'];
array_reverse($messages);
foreach ($messages as $message) {
    $notice = $imp->prepNotice($message);
    var_dump($notice);
}