Esempio n. 1
0
 function prepare($args)
 {
     $ok = parent::prepare($args);
     $this->subaction = $this->trimmed('subaction');
     $this->runner = YammerRunner::init();
     return $ok;
 }
Esempio n. 2
0
 /**
  * Data elements of the form
  *
  * @return void
  */
 function formData()
 {
     $this->out->hidden('subaction', 'progress');
     $runner = YammerRunner::init();
     $error = $runner->lastError();
     $userCount = $runner->countUsers();
     $groupCount = $runner->countGroups();
     $fetchedCount = $runner->countFetchedNotices();
     $savedCount = $runner->countSavedNotices();
     $labels = array('init' => array('label' => _m('Initialize'), 'progress' => _m('No import running'), 'complete' => _m('Initiated Yammer server connection...')), 'requesting-auth' => array('label' => _m('Connect to Yammer'), 'progress' => _m('Awaiting authorization...'), 'complete' => _m('Connected.')), 'import-users' => array('label' => _m('Import user accounts'), 'progress' => sprintf(_m('Importing %d user...', 'Importing %d users...', $userCount), $userCount), 'complete' => sprintf(_m('Imported %d user.', 'Imported %d users.', $userCount), $userCount)), 'import-groups' => array('label' => _m('Import user groups'), 'progress' => sprintf(_m('Importing %d group...', 'Importing %d groups...', $groupCount), $groupCount), 'complete' => sprintf(_m('Imported %d group.', 'Imported %d groups.', $groupCount), $groupCount)), 'fetch-messages' => array('label' => _m('Prepare public notices for import'), 'progress' => sprintf(_m('Preparing %d notice...', 'Preparing %d notices...', $fetchedCount), $fetchedCount), 'complete' => sprintf(_m('Prepared %d notice.', 'Prepared %d notices.', $fetchedCount), $fetchedCount)), 'save-messages' => array('label' => _m('Import public notices'), 'progress' => sprintf(_m('Importing %d notice...', 'Importing %d notices...', $savedCount), $savedCount), 'complete' => sprintf(_m('Imported %d notice.', 'Imported %d notices.', $savedCount), $savedCount)), 'done' => array('label' => _m('Done'), 'progress' => sprintf(_m('Import is complete!')), 'complete' => sprintf(_m('Import is complete!'))));
     $steps = array_keys($labels);
     $currentStep = array_search($runner->state(), $steps);
     $classes = array('yammer-import');
     if ($error) {
         $classes[] = 'yammer-error';
     } else {
         $classes[] = 'yammer-running';
     }
     $this->out->elementStart('fieldset', array('class' => implode(' ', $classes)));
     // TRANS: Fieldset legend.
     $this->out->element('legend', array(), _m('Import status'));
     foreach ($steps as $step => $state) {
         if ($state == 'init') {
             // Don't show 'init', it's boring.
             continue;
         }
         if ($step < $currentStep) {
             // This step is done
             $this->progressBar($state, 'complete', $labels[$state]['label'], $labels[$state]['complete']);
         } else {
             if ($step == $currentStep) {
                 // This step is in progress
                 $this->progressBar($state, 'progress', $labels[$state]['label'], $labels[$state]['progress'], $error);
             } else {
                 // This step has not yet been done.
                 $this->progressBar($state, 'waiting', $labels[$state]['label'], _m('Waiting...'));
             }
         }
     }
     $this->out->elementEnd('fieldset');
 }
 function handle($notice)
 {
     $runner = YammerRunner::init();
     if ($runner->hasWork()) {
         try {
             if ($runner->iterate()) {
                 if ($runner->hasWork()) {
                     // More to do? Shove us back on the queue...
                     $runner->startBackgroundImport();
                 }
             }
         } catch (Exception $e) {
             try {
                 $runner->recordError($e->getMessage());
             } catch (Exception $f) {
                 common_log(LOG_ERR, "Error while recording error in Yammer background import: " . $e->getMessage() . " " . $f->getMessage());
             }
         }
     } else {
         // We're done!
         common_log(LOG_INFO, "Yammer import has no work to do at this time; discarding.");
     }
     return true;
 }
Esempio n. 4
0
<?php

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();
    echo "done.\n";
    exit(0);
}
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 --verify=####\n";
        echo "\n";
        break;
    case 'requesting-auth':
        if (!have_option('verify')) {