2010-09-21 23:54:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if (php_sapi_name() != 'cli') {
|
|
|
|
die('no');
|
|
|
|
}
|
|
|
|
|
2010-09-24 01:55:13 +01:00
|
|
|
|
2010-09-22 20:52:34 +01:00
|
|
|
define('INSTALLDIR', dirname(dirname(dirname(dirname(__FILE__)))));
|
2010-09-21 23:54:39 +01:00
|
|
|
|
2010-09-24 01:55:13 +01:00
|
|
|
$longoptions = array('verify=', 'reset');
|
2010-09-21 23:54:39 +01:00
|
|
|
require INSTALLDIR . "/scripts/commandline.inc";
|
|
|
|
|
2010-09-24 01:55:13 +01:00
|
|
|
echo "Checking current state...\n";
|
2010-09-24 00:40:22 +01:00
|
|
|
$runner = YammerRunner::init();
|
2010-09-21 23:54:39 +01:00
|
|
|
|
2010-09-24 01:55:13 +01:00
|
|
|
if (have_option('reset')) {
|
|
|
|
echo "Resetting Yammer import state...\n";
|
|
|
|
$runner->reset();
|
|
|
|
}
|
|
|
|
|
2010-09-24 00:40:22 +01:00
|
|
|
switch ($runner->state())
|
|
|
|
{
|
|
|
|
case 'init':
|
2010-09-24 01:55:13 +01:00
|
|
|
echo "Requesting authentication to Yammer API...\n";
|
2010-09-24 00:40:22 +01:00
|
|
|
$url = $runner->requestAuth();
|
|
|
|
echo "Log in to Yammer at the following URL and confirm permissions:\n";
|
|
|
|
echo "\n";
|
|
|
|
echo " $url\n";
|
|
|
|
echo "\n";
|
2010-09-24 01:55:13 +01:00
|
|
|
echo "Pass the resulting code back by running:\n";
|
|
|
|
echo "\n";
|
|
|
|
echo " php yammer-import.php --verify=####\n";
|
2010-09-24 00:40:22 +01:00
|
|
|
echo "\n";
|
|
|
|
break;
|
2010-09-21 23:54:39 +01:00
|
|
|
|
2010-09-24 00:40:22 +01:00
|
|
|
case 'requesting-auth':
|
2010-09-24 01:55:13 +01:00
|
|
|
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);
|
2010-09-24 00:40:22 +01:00
|
|
|
}
|
2010-09-24 01:55:13 +01:00
|
|
|
echo "Saving final authentication token for Yammer API...\n";
|
|
|
|
$runner->saveAuthToken(get_option_value('verify'));
|
2010-09-24 00:40:22 +01:00
|
|
|
// Fall through...
|
2010-09-21 23:54:39 +01:00
|
|
|
|
2010-09-24 00:40:22 +01:00
|
|
|
default:
|
2010-09-24 01:55:13 +01:00
|
|
|
while ($runner->hasWork()) {
|
|
|
|
echo "... {$runner->state()}\n";
|
2010-09-24 00:40:22 +01:00
|
|
|
if (!$runner->iterate()) {
|
2010-09-24 01:55:13 +01:00
|
|
|
echo "FAIL??!?!?!\n";
|
2010-09-24 00:40:22 +01:00
|
|
|
}
|
|
|
|
}
|
2010-09-24 01:55:13 +01:00
|
|
|
if ($runner->isDone()) {
|
|
|
|
echo "... done.\n";
|
|
|
|
} else {
|
|
|
|
echo "... no more import work scheduled.\n";
|
|
|
|
}
|
2010-09-24 00:40:22 +01:00
|
|
|
break;
|
2010-09-24 01:55:13 +01:00
|
|
|
}
|