yammer-import.php 1.7 KB

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