From 8f438da254defa35d9e066fb29947da208d14319 Mon Sep 17 00:00:00 2001
From: Brion Vibber <brion@pobox.com>
Date: Thu, 23 Sep 2010 17:55:13 -0700
Subject: Ok, command-line workflow for YammerImportPlugin seems to mostly
 work, at least on tiny test site :D

---
 plugins/YammerImport/scripts/yammer-import.php | 43 +++++++++++++++++++-------
 1 file changed, 31 insertions(+), 12 deletions(-)

(limited to 'plugins/YammerImport/scripts/yammer-import.php')

diff --git a/plugins/YammerImport/scripts/yammer-import.php b/plugins/YammerImport/scripts/yammer-import.php
index 24307d6cd..1491cfd30 100644
--- a/plugins/YammerImport/scripts/yammer-import.php
+++ b/plugins/YammerImport/scripts/yammer-import.php
@@ -4,41 +4,60 @@ 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();
+}
+
 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 --auth=####\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 (empty($options['auth'])) {
-            echo "Please finish authenticating!\n";
-            break;
+        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);
         }
-        $runner->saveAuthToken($options['auth']);
+        echo "Saving final authentication token for Yammer API...\n";
+        $runner->saveAuthToken(get_option_value('verify'));
         // Fall through...
 
     default:
-        while (true) {
-            echo "... {$runner->state->state}\n";
+        while ($runner->hasWork()) {
+            echo "... {$runner->state()}\n";
             if (!$runner->iterate()) {
-                echo "... done.\n";
-                break;
+                echo "FAIL??!?!?!\n";
             }
         }
+        if ($runner->isDone()) {
+            echo "... done.\n";
+        } else {
+            echo "... no more import work scheduled.\n";
+        }
         break;
-}
\ No newline at end of file
+}
-- 
cgit v1.2.3-54-g00ecf