class YammeradminpanelAction extends AdminPanelAction
{
+ private $runner;
+
/**
* Returns the page title
*
*/
function getInstructions()
{
- return _m('Yammer import tool');
+ return _m('This Yammer import tool is still undergoing testing, ' .
+ 'and is incomplete in some areas. ' .
+ 'Currently user subscriptions and group memberships are not ' .
+ 'transferred; in the future this may be supported for ' .
+ 'imports done by verified administrators on the Yammer side.');
}
- /**
- * Show the Yammer admin panel form
- *
- * @return void
- */
- function showForm()
+ function prepare($args)
{
- $form = new YammerAdminPanelForm($this);
- $form->show();
- return;
+ $ok = parent::prepare($args);
+
+ $this->subaction = $this->trimmed('subaction');
+ $this->runner = YammerRunner::init();
+
+ return $ok;
}
-}
-class YammerAdminPanelForm extends AdminForm
-{
- /**
- * ID of the form
- *
- * @return string ID of the form
- */
- function id()
+ function handle($args)
{
- return 'yammeradminpanel';
+ // @fixme move this to saveSettings and friends?
+ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ StatusNet::setApi(true); // short error pages :P
+ $this->checkSessionToken();
+ if ($this->subaction == 'change-apikey') {
+ $form = new YammerApiKeyForm($this);
+ } else if ($this->subaction == 'apikey') {
+ if ($this->saveKeys()) {
+ $form = new YammerAuthInitForm($this, $this->runner);
+ } else {
+ $form = new YammerApiKeyForm($this);
+ }
+ } else if ($this->subaction == 'authinit') {
+ // hack
+ if ($this->arg('change-apikey')) {
+ $form = new YammerApiKeyForm($this);
+ } else {
+ $url = $this->runner->requestAuth();
+ $form = new YammerAuthVerifyForm($this, $this->runner);
+ }
+ } else if ($this->subaction == 'authverify') {
+ $this->runner->saveAuthToken($this->trimmed('verify_token'));
+
+ // Haho! Now we can make THE FUN HAPPEN
+ $this->runner->startBackgroundImport();
+
+ $form = new YammerProgressForm($this, $this->runner);
+ } else if ($this->subaction == 'pause-import') {
+ $this->runner->recordError(_m('Paused from admin panel.'));
+ $form = $this->statusForm();
+ } else if ($this->subaction == 'continue-import') {
+ $this->runner->clearError();
+ $this->runner->startBackgroundImport();
+ $form = $this->statusForm();
+ } else if ($this->subaction == 'abort-import') {
+ $this->runner->reset();
+ $form = $this->statusForm();
+ } else if ($this->subaction == 'progress') {
+ $form = $this->statusForm();
+ } else {
+ throw new ClientException('Invalid POST');
+ }
+ return $this->showAjaxForm($form);
+ }
+ return parent::handle($args);
}
- /**
- * class of the form
- *
- * @return string class of the form
- */
- function formClass()
+ function saveKeys()
{
- return 'form_settings';
+ $key = $this->trimmed('consumer_key');
+ $secret = $this->trimmed('consumer_secret');
+ Config::save('yammer', 'consumer_key', $key);
+ Config::save('yammer', 'consumer_secret', $secret);
+
+ return !empty($key) && !empty($secret);
}
- /**
- * Action of the form
- *
- * @return string URL of the action
- */
- function action()
+ function showAjaxForm($form)
{
- return common_local_url('yammeradminpanel');
+ $this->startHTML('text/xml;charset=utf-8');
+ $this->elementStart('head');
+ $this->element('title', null, _m('Yammer import'));
+ $this->elementEnd('head');
+ $this->elementStart('body');
+ $form->show();
+ $this->elementEnd('body');
+ $this->elementEnd('html');
}
/**
- * Data elements of the form
- *
- * @return void
+ * Fetch the appropriate form for our current state.
+ * @return Form
*/
- function formData()
+ function statusForm()
{
- $this->out->element('p', array(), 'yammer import IN DA HOUSE');
-
- /*
- Possible states of the yammer import process:
- - null (not doing any sort of import)
- - requesting-auth
- - authenticated
- - import-users
- - import-groups
- - fetch-messages
- - import-messages
- - done
- */
- $yammerState = Yammer_state::staticGet('id', 1);
- $state = $yammerState ? $yammerState->state || null;
-
- switch($state)
+ if (!(common_config('yammer', 'consumer_key'))
+ || !(common_config('yammer', 'consumer_secret'))) {
+ return new YammerApiKeyForm($this);
+ }
+ switch($this->runner->state())
{
- case null:
- $this->out->element('p', array(), 'Time to start auth:');
- $this->showAuthForm();
- break;
+ case 'init':
+ return new YammerAuthInitForm($this, $this->runner);
case 'requesting-auth':
- $this->out->element('p', array(), 'Need to finish auth!');
- $this->showAuthForm();
- break;
- case 'import-users':
- case 'import-groups':
- case 'import-messages':
- case 'save-messages':
- $this->showImportState();
- break;
-
+ return new YammerAuthVerifyForm($this, $this->runner);
+ default:
+ return new YammerProgressForm($this, $this->runner);
}
}
/**
- * Action elements
+ * Show the Yammer admin panel form
*
* @return void
*/
- function formActions()
+ function showForm()
+ {
+ $this->elementStart('fieldset');
+ $this->statusForm()->show();
+ $this->elementEnd('fieldset');
+ }
+
+ function showStylesheets()
+ {
+ parent::showStylesheets();
+ $this->cssLink(Plugin::staticPath('YammerImport', 'css/admin.css'), null, 'screen, projection, tv');
+ }
+
+ function showScripts()
{
- // No submit buttons needed at bottom
+ parent::showScripts();
+ $this->script(Plugin::staticPath('YammerImport', 'js/yammer-admin.js'));
}
}