Copyright 2010-2016 Horde LLC (http://www.horde.org/) See the enclosed file COPYING for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.
Author: Jan Schneider (jan@horde.org)
Inheritance: extends Horde_Translation_Autodetect
Example #1
0
File: List.php Project: horde/horde
 /**
  * Run the module.
  *
  * @param Horde_Cli $cli       The CLI handler.
  * @param mixed     $options   An array of options.
  * @param mixed     $arguments An array of arguments.
  * @param array     &$world    A list of initialized dependencies.
  *
  * @return NULL
  */
 public function run($cli, $options, $arguments, &$world)
 {
     if (!isset($arguments[1])) {
         $action = 'folders';
     } else {
         $action = $arguments[1];
     }
     switch ($action) {
         case 'folders':
             $folders = $world['storage']->getList()->listFolders();
             foreach ($folders as $folder) {
                 $cli->writeln($folder);
             }
             break;
         case 'types':
             $types = $world['storage']->getList()->getQuery()->listTypes();
             if (!empty($types)) {
                 $pad = max(array_map('strlen', array_keys($types))) + 2;
                 foreach ($types as $folder => $type) {
                     $cli->writeln(Horde_String::pad($folder . ':', $pad) . $type);
                 }
             }
             break;
         case 'type':
             if (!isset($arguments[2])) {
                 throw new Horde_Kolab_Cli_Exception('You must provide a TYPE argument!');
             }
             $type = $arguments[2];
             $folders = $world['storage']->getList()->getQuery()->listByType($type);
             foreach ($folders as $folder) {
                 $cli->writeln($folder);
             }
             break;
         case 'owners':
             $owners = $world['storage']->getList()->getQuery()->listOwners();
             if (!empty($owners)) {
                 $pad = max(array_map('strlen', array_keys($owners))) + 2;
                 foreach ($owners as $folder => $owner) {
                     $cli->writeln(Horde_String::pad($folder . ':', $pad) . $owner);
                 }
             }
             break;
         case 'defaults':
             $defaults = $world['storage']->getList()->getQuery()->listDefaults();
             if (!empty($defaults)) {
                 foreach ($defaults as $owner => $folders) {
                     $cli->writeln('User "' . $owner . '":');
                     $cli->writeln();
                     foreach ($folders as $type => $folder) {
                         $cli->writeln('  ' . Horde_String::pad($type . ':', 14) . $folder);
                     }
                     $cli->writeln();
                 }
             }
             break;
         case 'aclsupport':
             if ($world['storage']->getList()->getQuery(Horde_Kolab_Storage_List::QUERY_ACL)->hasAclSupport()) {
                 echo "The remote server supports ACL.\n";
             } else {
                 echo "The remote server does not support ACL.\n";
             }
             break;
         case 'namespaces':
             $cli->writeln((string) $world['storage']->getList()->getNamespace());
             break;
         case 'sync':
             $folders = $world['storage']->getList()->synchronize();
             break;
         default:
             $cli->message(sprintf(Horde_Kolab_Cli_Translation::t('Action %s not supported!'), $action), 'cli.error');
             break;
     }
 }
Example #2
0
 /**
  * Run the module.
  *
  * @param Horde_Cli $cli       The CLI handler.
  * @param mixed     $options   An array of options.
  * @param mixed     $arguments An array of arguments.
  * @param array     &$world    A list of initialized dependencies.
  *
  * @return NULL
  */
 public function run($cli, $options, $arguments, &$world)
 {
     if (!isset($arguments[1])) {
         $action = 'read';
     } else {
         $action = $arguments[1];
     }
     switch ($action) {
         case 'read':
             $parser = $world['format']->create('Xml', $arguments[2]);
             if (empty($arguments[4])) {
                 if (file_exists($arguments[3])) {
                     $contents = file_get_contents($arguments[3]);
                     $data = $parser->load($contents);
                     $id = $arguments[3];
                 } else {
                     $cli->message(sprintf(Horde_Kolab_Cli_Translation::t('%s is no local file!'), $arguments[3]), 'cli.error');
                 }
             } else {
                 $ks_data = $world['storage']->getData($arguments[3]);
                 $part = $ks_data->fetchPart($arguments[4], $arguments[5]);
                 rewind($part);
                 $xml = quoted_printable_decode(stream_get_contents($part));
                 $data = $parser->load($xml);
                 $id = $arguments[3] . ':' . $arguments[4] . '[' . $arguments[5] . ']';
             }
             if (class_exists('Horde_Yaml')) {
                 $this->_formatOutput($cli, $id, Horde_Yaml::dump($data));
             } else {
                 $this->_formatOutput($cli, $id, print_r($data, true));
             }
             break;
         default:
             $cli->message(sprintf(Horde_Kolab_Cli_Translation::t('Action %s not supported!'), $action), 'cli.error');
             break;
     }
 }
Example #3
0
 /**
  * Run the module.
  *
  * @param Horde_Cli $cli       The CLI handler.
  * @param mixed     $options   An array of options.
  * @param mixed     $arguments An array of arguments.
  * @param array     &$world    A list of initialized dependencies.
  *
  * @return NULL
  */
 public function run($cli, $options, $arguments, &$world)
 {
     if (!isset($arguments[1])) {
         $action = 'info';
     } else {
         $action = $arguments[1];
     }
     if (!isset($arguments[2])) {
         $folder_name = 'INBOX';
     } else {
         $folder_name = $arguments[2];
     }
     switch ($action) {
         case 'info':
             break;
         case 'synchronize':
             $world['storage']->getData($folder_name, $arguments[3])->synchronize();
             break;
         case 'stamp':
             $cli->writeln((string) $world['storage']->getData($folder_name)->getStamp());
             break;
         case 'complete':
             $data = $world['storage']->getData($folder_name);
             $complete = $data->fetchComplete($arguments[3]);
             $cli->writeln($complete[1]->toString(array('headers' => $complete[0])));
             break;
         case 'part':
             $data = $world['storage']->getData($folder_name);
             $part = $data->fetchPart($arguments[3], $arguments[4]);
             rewind($part);
             $cli->writeln(quoted_printable_decode(stream_get_contents($part)));
             break;
         case 'fetch':
             $data = $world['storage']->getData($folder_name, $arguments[3]);
             $objects = $data->fetch(explode(',', $arguments[4]));
             foreach ($objects as $uid => $message) {
                 $this->_yamlOutput($cli, $uid, $message);
             }
             break;
         case 'ids':
             $data = $world['storage']->getData($folder_name, $arguments[3]);
             foreach ($data->getObjectIds() as $id) {
                 $cli->writeln((string) $id);
             }
             break;
         case 'objects':
             $data = $world['storage']->getData($folder_name, $arguments[3]);
             foreach ($data->getObjects() as $id => $object) {
                 $this->_yamlOutput($cli, $id, $object);
             }
             break;
         case 'backendobjects':
             $data = $world['storage']->getData($folder_name, $arguments[3]);
             foreach ($data->getObjectsByBackendId() as $id => $object) {
                 $this->_yamlOutput($cli, $id, $object);
             }
             break;
         case 'object':
             $data = $world['storage']->getData($folder_name, $arguments[3]);
             $object = $data->getObject($arguments[4]);
             $this->_yamlOutput($cli, $arguments[4], $object);
             break;
         case 'backendobject':
             $data = $world['storage']->getData($folder_name, $arguments[3]);
             $object = $data->getObjectByBackendId($arguments[4]);
             $this->_yamlOutput($cli, $arguments[4], $object);
             break;
         case 'create':
             $data = $world['storage']->getData($folder_name, $arguments[3]);
             switch (Horde_String::lower($arguments[4])) {
                 case 'yaml':
                     if (class_exists('Horde_Yaml')) {
                         $object = Horde_Yaml::loadFile($arguments[5]);
                     } else {
                         throw new Horde_Kolab_Cli_Exception('The Horde_Yaml package is missing!');
                     }
             }
             $data->create($object);
             $cli->writeln($object['uid']);
             break;
         case 'move':
             $data = $world['storage']->getData($folder_name, $arguments[3]);
             $objects = $data->move($arguments[4], $arguments[5]);
             break;
         case 'delete':
             $data = $world['storage']->getData($folder_name, $arguments[3]);
             $objects = $data->delete(explode(',', $arguments[4]));
             break;
         case 'deleteall':
             $world['storage']->getData($folder_name, $arguments[3])->deleteAll();
             break;
         case 'deleteuids':
             $data = $world['storage']->getData($folder_name, $arguments[3]);
             $objects = $data->deleteBackendIds(explode(',', $arguments[4]));
             break;
         case 'backendid':
             $data = $world['storage']->getData($folder_name, $arguments[3]);
             $cli->writeln((string) $data->getBackendId($arguments[4]));
             break;
         default:
             $cli->message(sprintf(Horde_Kolab_Cli_Translation::t('Action %s not supported!'), $action), 'cli.error');
             break;
     }
 }
Example #4
0
 /**
  * Run the module.
  *
  * @param Horde_Cli $cli       The CLI handler.
  * @param mixed     $options   An array of options.
  * @param mixed     $arguments An array of arguments.
  * @param array     &$world    A list of initialized dependencies.
  *
  * @return NULL
  */
 public function run($cli, $options, $arguments, &$world)
 {
     if (!isset($arguments[1])) {
         $action = 'display';
     } else {
         $action = $arguments[1];
     }
     switch ($action) {
         case 'display':
             $folders = $world['storage']->getList()->getQuery()->listByType('h-ledger');
             foreach ($folders as $folder) {
                 $cli->writeln($folder);
             }
             break;
             break;
         case 'import':
             $ledger = new Horde_Kolab_Cli_Data_Ledger();
             $ledger->importFile($arguments[3]);
             $data = $world['storage']->getData($arguments[2], 'h-ledger');
             $object = array('type' => 'h-ledger');
             foreach ($ledger->asXml() as $entry) {
                 $object['xml'] = $entry;
                 $data->create($object);
             }
             break;
         default:
             $cli->message(sprintf(Horde_Kolab_Cli_Translation::t('Action %s not supported!'), $action), 'cli.error');
             break;
     }
 }
Example #5
0
File: Base.php Project: horde/horde
 /**
  * Get a set of base options that this module adds to the CLI argument
  * parser.
  *
  * @return array The options.
  */
 public function getBaseOptions()
 {
     return array(new Horde_Argv_Option('-d', '--driver', array('action' => 'store', 'choices' => array('horde', 'horde-php', 'php', 'pear', 'roundcube', 'mock'), 'help' => Horde_Kolab_Cli_Translation::t("The Kolab backend driver that should be used.\nChoices are:\n\n - horde     [IMAP]: The Horde_Imap_Client driver as pure PHP implementation.\n - horde-php [IMAP]: The Horde_Imap_Client driver based on c-client in PHP\n - php       [IMAP]: The PHP imap_* functions which are based on c-client\n - pear      [IMAP]: The PEAR-Net_IMAP driver\n - roundcube [IMAP]: The roundcube IMAP driver\n - mock      [Mem.]: A dummy driver that uses memory."))), new Horde_Argv_Option('-u', '--username', array('action' => 'store', 'help' => Horde_Kolab_Cli_Translation::t('The user accessing the backend.'))), new Horde_Argv_Option('-p', '--password', array('action' => 'store', 'help' => Horde_Kolab_Cli_Translation::t('The password of the user accessing the backend.'))), new Horde_Argv_Option('-H', '--host', array('action' => 'store', 'help' => Horde_Kolab_Cli_Translation::t('The host that holds the data.'))), new Horde_Argv_Option('-P', '--port', array('action' => 'store', 'help' => Horde_Kolab_Cli_Translation::t('The port that should be used to connect to the host.'))), new Horde_Argv_Option('-S', '--secure', array('action' => 'store', 'help' => Horde_Kolab_Cli_Translation::t('Sets the connection type. Use either "tls" or "ssl" here.'))), new Horde_Argv_Option('-t', '--timed', array('action' => 'store_true', 'help' => Horde_Kolab_Cli_Translation::t('Produce time measurements to indicate how long the processing takes. You *must* activate logging for this as well.'))), new Horde_Argv_Option('-m', '--memory', array('action' => 'store_true', 'help' => Horde_Kolab_Cli_Translation::t('Report memory consumption statistics. You *must* activate logging for this as well.'))), new Horde_Argv_Option('-n', '--nocache', array('action' => 'store_true', 'help' => Horde_Kolab_Cli_Translation::t('Deactivate caching of the IMAP data.'))), new Horde_Argv_Option('-l', '--log', array('action' => 'store', 'help' => Horde_Kolab_Cli_Translation::t('Write a log file in the provided LOG location. Use "STDOUT" here to direct the log output to the screen.'))), new Horde_Argv_Option('-D', '--debug', array('action' => 'store', 'help' => Horde_Kolab_Cli_Translation::t('Activates the IMAP debug log. This will log the full IMAP communication - CAUTION: the "php" driver is the only driver variant that does not support this feature. For most drivers you should use "STDOUT" which will direct the debug log to your screen. For the horde, the horde-php, and the roundcube drivers you may also set this to a filename and the output will be directed there.'))), new Horde_Argv_Option('-c', '--config', array('action' => 'store', 'help' => Horde_Kolab_Cli_Translation::t('Path to the configuration file. Comman line parameters overwrite values from the configuration file.'))));
 }
Example #6
0
 /**
  * Run the module.
  *
  * @param Horde_Cli $cli       The CLI handler.
  * @param mixed     $options   An array of options.
  * @param mixed     $arguments An array of arguments.
  * @param array     &$world    A list of initialized dependencies.
  *
  * @return NULL
  */
 public function run($cli, $options, $arguments, &$world)
 {
     if (!isset($arguments[1])) {
         $action = 'all';
     } else {
         $action = $arguments[1];
     }
     switch ($action) {
         case 'all':
             if (!isset($arguments[2])) {
                 $folders = $world['storage']->getList()->getQuery()->listTypes();
             } else {
                 $names = $world['storage']->getList()->getQuery()->listByType($arguments[2]);
                 $folders = array();
                 foreach ($names as $name) {
                     $folders[$name] = $arguments[2];
                 }
             }
             foreach ($folders as $folder => $type) {
                 if ($type == 'mail') {
                     continue;
                 }
                 $data = $world['storage']->getData($folder, $type);
                 foreach ($data->getObjects() as $id => $object) {
                     $this->_yamlOutput($cli, $folder . ': ' . $id, $object);
                 }
             }
             break;
         case 'defects':
             if (!isset($arguments[2])) {
                 $folders = $world['storage']->getList()->getQuery()->listTypes();
             } else {
                 $names = $world['storage']->getList()->getQuery()->listByType($arguments[2]);
                 $folders = array();
                 foreach ($names as $name) {
                     $folders[$name] = $arguments[2];
                 }
             }
             foreach ($folders as $folder => $type) {
                 if ($type == 'mail') {
                     continue;
                 }
                 $data = $world['storage']->getData($folder, $type);
                 foreach ($data->getErrors() as $id) {
                     $complete = $data->fetchComplete($id);
                     $message = "FAILED PARSING:\n\n" . $complete[1]->toString(array('headers' => $complete[0]));
                     $this->_messageOutput($cli, $folder . ': ' . $id, $message);
                 }
                 foreach ($data->getDuplicates() as $object => $ids) {
                     foreach ($ids as $id) {
                         $this->_yamlOutput($cli, "DUPLICATE {$object} in {$folder} (backend {$id})", $data->fetch(array($id)));
                     }
                 }
             }
             break;
         case 'issuelist':
             if (!isset($arguments[2])) {
                 $folders = $world['storage']->getList()->getQuery()->listTypes();
             } else {
                 $names = $world['storage']->getList()->getQuery()->listByType($arguments[2]);
                 $folders = array();
                 foreach ($names as $name) {
                     $folders[$name] = $arguments[2];
                 }
             }
             foreach ($folders as $folder => $type) {
                 if ($type == 'mail') {
                     continue;
                 }
                 $data = $world['storage']->getData($folder, $type);
                 $issues = '';
                 $errors = $data->getErrors();
                 if (!empty($errors)) {
                     $issues = "FAILED parsing the messages with the following UIDs:\n\n";
                     foreach ($errors as $id) {
                         $issues .= " - {$id}\n";
                     }
                     $issues .= "\n";
                 }
                 $duplicates = $data->getDuplicates();
                 if (!empty($duplicates)) {
                     foreach ($duplicates as $object => $ids) {
                         $issues .= "DUPLICATE object ID \"{$object}\" represented by messages with the following UIDs:\n\n";
                         foreach ($ids as $id) {
                             $issues .= " - {$id}\n";
                         }
                         $issues .= "\n";
                     }
                 }
                 if (!empty($issues)) {
                     $cli->writeln('Error report for folder "' . $folder . '"');
                     $cli->writeln('================================================================================');
                     $cli->writeln();
                     $cli->writeln($issues);
                     $cli->writeln('================================================================================');
                     $cli->writeln();
                 }
             }
             break;
         default:
             $cli->message(sprintf(Horde_Kolab_Cli_Translation::t('Action %s not supported!'), $action), 'cli.error');
             break;
     }
 }
Example #7
0
 /**
  * Returns the plural translation of a message.
  *
  * @param string $singular  The singular version to translate.
  * @param string $plural    The plural version to translate.
  * @param integer $number   The number that determines singular vs. plural.
  *
  * @return string  The string translation, or the original string if no
  *                 translation exists.
  */
 public static function ngettext($singular, $plural, $number)
 {
     self::$_domain = 'Horde_Kolab_Cli';
     self::$_directory = '@data_dir@' == '@' . 'data_dir' . '@' ? __DIR__ . '/../../../../locale' : '@data_dir@/Horde_Kolab_Cli/locale';
     return parent::ngettext($singular, $plural, $number);
 }
Example #8
0
 private static function _prepareModular(array $parameters = array())
 {
     return new Horde_Cli_Modular(array('parser' => array('class' => empty($parameters['parser']['class']) ? 'Horde_Argv_Parser' : $parameters['parser']['class'], 'usage' => Horde_Kolab_Cli_Translation::t("[options] MODULE ACTION\n\nPossible MODULEs and ACTIONs:\n\n")), 'modules' => array('directory' => __DIR__ . '/Cli/Module'), 'provider' => array('prefix' => 'Horde_Kolab_Cli_Module_')));
 }
Example #9
0
 /**
  * Run the module.
  *
  * @param Horde_Cli $cli       The CLI handler.
  * @param mixed     $options   An array of options.
  * @param mixed     $arguments An array of arguments.
  * @param array     &$world    A list of initialized dependencies.
  *
  * @return NULL
  */
 public function run($cli, $options, $arguments, &$world)
 {
     if (!isset($arguments[1])) {
         $action = 'show';
     } else {
         $action = $arguments[1];
     }
     if (!isset($arguments[2])) {
         $folder_name = 'INBOX';
     } else {
         $folder_name = $arguments[2];
     }
     switch ($action) {
         case 'create':
             if (!isset($arguments[3])) {
                 $folder = $world['storage']->getList()->createFolder($folder_name);
             } else {
                 $folder = $world['storage']->getList()->createFolder($folder_name, $arguments[3]);
             }
             $this->_showFolder($folder_name, $world, $cli);
             break;
         case 'rename':
             $folder = $world['storage']->getList()->renameFolder($folder_name, $arguments[3]);
             $this->_showFolder($arguments[3], $world, $cli);
             break;
         case 'delete':
             $folder = $world['storage']->getList()->deleteFolder($folder_name);
             break;
         case 'getacl':
             $acl = $world['storage']->getList()->getQuery(Horde_Kolab_Storage_List::QUERY_ACL)->getAcl($folder_name);
             $cli->writeln($folder_name);
             $cli->writeln(str_repeat('=', strlen($folder_name)));
             $pad = max(array_map('strlen', array_keys($acl))) + 2;
             foreach ($acl as $user => $rights) {
                 $cli->writeln(Horde_String::pad($user . ':', $pad) . $rights);
             }
             break;
         case 'getmyacl':
             $acl = $world['storage']->getList()->getQuery(Horde_Kolab_Storage_List::QUERY_ACL)->getMyAcl($folder_name);
             $cli->writeln('Your rights on ' . $folder_name . ': ' . $acl);
             break;
         case 'setacl':
             $acl = $world['storage']->getList()->getQuery(Horde_Kolab_Storage_List::QUERY_ACL)->setAcl($folder_name, $arguments[3], $arguments[4]);
             break;
         case 'deleteacl':
             $acl = $world['storage']->getList()->getQuery(Horde_Kolab_Storage_List::QUERY_ACL)->deleteAcl($folder_name, $arguments[3]);
             break;
         case 'getdesc':
             $list = $world['storage']->getList();
             $world['storage']->addListQuery($list, Horde_Kolab_Storage_List::QUERY_SHARE);
             $cli->writeln($list->getQuery(Horde_Kolab_Storage_List::QUERY_SHARE)->getDescription($folder_name));
             break;
         case 'setdesc':
             $list = $world['storage']->getList();
             $world['storage']->addListQuery($list, Horde_Kolab_Storage_List::QUERY_SHARE);
             $list->getQuery(Horde_Kolab_Storage_List::QUERY_SHARE)->setDescription($folder_name, $arguments[3]);
             break;
         case 'getshare':
             $list = $world['storage']->getList();
             $world['storage']->addListQuery($list, Horde_Kolab_Storage_List::QUERY_SHARE);
             $parameters = $list->getQuery(Horde_Kolab_Storage_List::QUERY_SHARE)->getParameters($folder_name);
             $pad = max(array_map('strlen', array_keys($parameters))) + 2;
             foreach ($parameters as $key => $value) {
                 $cli->writeln(Horde_String::pad($key . ':', $pad) . $value);
             }
             break;
         case 'show':
             $this->_showFolder($folder_name, $world, $cli);
             break;
         default:
             $cli->message(sprintf(Horde_Kolab_Cli_Translation::t('Action %s not supported!'), $action), 'cli.error');
             break;
     }
 }