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