summaryrefslogtreecommitdiff
path: root/plugins/YammerImport/scripts/yammer-import.php
blob: b4aa921e50cd2a5dda62b380bfb3a08503a105a4 (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
63
64
65
<?php

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


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

$longoptions = array('verify=', 'reset');
require INSTALLDIR . "/scripts/commandline.inc";

echo "Checking current state...\n";
$runner = YammerRunner::init();

if (have_option('reset')) {
    echo "Resetting Yammer import state...\n";
    $runner->reset();
    echo "done.\n";
    exit(0);
}

switch ($runner->state())
{
    case 'init':
        echo "Requesting authentication to Yammer API...\n";
        $url = $runner->requestAuth();
        echo "Log in to Yammer at the following URL and confirm permissions:\n";
        echo "\n";
        echo "    $url\n";
        echo "\n";
        echo "Pass the resulting code back by running:\n";
        echo "\n";
        echo "    php yammer-import.php --verify=####\n";
        echo "\n";
        break;

    case 'requesting-auth':
        if (!have_option('verify')) {
            echo "Awaiting authentication...\n";
            echo "\n";
            echo "If you need to start over, reset the state:\n";
            echo "\n";
            echo "    php yammer-import.php --reset\n";
            echo "\n";
            exit(1);
        }
        echo "Saving final authentication token for Yammer API...\n";
        $runner->saveAuthToken(get_option_value('verify'));
        // Fall through...

    default:
        while ($runner->hasWork()) {
            echo "... {$runner->state()}\n";
            if (!$runner->iterate()) {
                echo "FAIL??!?!?!\n";
            }
        }
        if ($runner->isDone()) {
            echo "... done.\n";
        } else {
            echo "... no more import work scheduled.\n";
        }
        break;
}