]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/YammerImport/scripts/yammer-import.php
Ok, command-line workflow for YammerImportPlugin seems to mostly work, at least on...
[quix0rs-gnu-social.git] / plugins / YammerImport / scripts / yammer-import.php
1 <?php
2
3 if (php_sapi_name() != 'cli') {
4     die('no');
5 }
6
7
8 define('INSTALLDIR', dirname(dirname(dirname(dirname(__FILE__)))));
9
10 $longoptions = array('verify=', 'reset');
11 require INSTALLDIR . "/scripts/commandline.inc";
12
13 echo "Checking current state...\n";
14 $runner = YammerRunner::init();
15
16 if (have_option('reset')) {
17     echo "Resetting Yammer import state...\n";
18     $runner->reset();
19 }
20
21 switch ($runner->state())
22 {
23     case 'init':
24         echo "Requesting authentication to Yammer API...\n";
25         $url = $runner->requestAuth();
26         echo "Log in to Yammer at the following URL and confirm permissions:\n";
27         echo "\n";
28         echo "    $url\n";
29         echo "\n";
30         echo "Pass the resulting code back by running:\n";
31         echo "\n";
32         echo "    php yammer-import.php --verify=####\n";
33         echo "\n";
34         break;
35
36     case 'requesting-auth':
37         if (!have_option('verify')) {
38             echo "Awaiting authentication...\n";
39             echo "\n";
40             echo "If you need to start over, reset the state:\n";
41             echo "\n";
42             echo "    php yammer-import.php --reset\n";
43             echo "\n";
44             exit(1);
45         }
46         echo "Saving final authentication token for Yammer API...\n";
47         $runner->saveAuthToken(get_option_value('verify'));
48         // Fall through...
49
50     default:
51         while ($runner->hasWork()) {
52             echo "... {$runner->state()}\n";
53             if (!$runner->iterate()) {
54                 echo "FAIL??!?!?!\n";
55             }
56         }
57         if ($runner->isDone()) {
58             echo "... done.\n";
59         } else {
60             echo "... no more import work scheduled.\n";
61         }
62         break;
63 }