Overview

Packages

  • Kolab
    • Cli

Classes

  • Horde_Kolab_Cli
  • Horde_Kolab_Cli_Data_Ledger
  • Horde_Kolab_Cli_Exception
  • Horde_Kolab_Cli_Module_Account
  • Horde_Kolab_Cli_Module_Base
  • Horde_Kolab_Cli_Module_Data
  • Horde_Kolab_Cli_Module_Folder
  • Horde_Kolab_Cli_Module_Format
  • Horde_Kolab_Cli_Module_Ledger
  • Horde_Kolab_Cli_Module_List
  • Horde_Kolab_Cli_Translation

Interfaces

  • Horde_Kolab_Cli_Module
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * The Horde_Kolab_Cli_Module_Account:: handles operations that require a full
  4:  * account.
  5:  *
  6:  * PHP version 5
  7:  *
  8:  * @category Horde
  9:  * @package  Kolab_Cli
 10:  * @author   Gunnar Wrobel <wrobel@pardus.de>
 11:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
 12:  * @link     http://pear.horde.org/index.php?package=Kolab_Cli
 13:  */
 14: 
 15: /**
 16:  * The Horde_Kolab_Cli_Module_Account:: handles operations that require a full
 17:  * account.
 18:  *
 19:  * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
 20:  *
 21:  * See the enclosed file COPYING for license information (LGPL). If you
 22:  * did not receive this file, see http://www.horde.org/licenses/lgpl21.
 23:  *
 24:  * @category Horde
 25:  * @package  Kolab_Cli
 26:  * @author   Gunnar Wrobel <wrobel@pardus.de>
 27:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
 28:  * @link     http://pear.horde.org/index.php?package=Kolab_Cli
 29:  */
 30: class Horde_Kolab_Cli_Module_Account
 31: implements Horde_Kolab_Cli_Module
 32: {
 33:     /**
 34:      * Get the usage description for this module.
 35:      *
 36:      * @return string The description.
 37:      */
 38:     public function getUsage()
 39:     {
 40:         return Horde_Kolab_Cli_Translation::t("  account - Handles operations on an account level (like listing *all* available groupware objects)
 41: 
 42:   - all [TYPE]       : List all groupware objects of the account (optionally
 43:                        limit to TYPE)
 44:   - defects [TYPE]   : List all defects of the account (optionally limit to
 45:                        TYPE)
 46:   - issuelist [TYPE] : A brief list of issues of the account (optionally
 47:                        limit to TYPE)
 48: 
 49: 
 50: ");
 51:     }
 52: 
 53:     /**
 54:      * Get a set of base options that this module adds to the CLI argument
 55:      * parser.
 56:      *
 57:      * @return array The options.
 58:      */
 59:     public function getBaseOptions()
 60:     {
 61:         return array();
 62:     }
 63: 
 64:     /**
 65:      * Indicate if the module provides an option group.
 66:      *
 67:      * @return boolean True if an option group should be added.
 68:      */
 69:     public function hasOptionGroup()
 70:     {
 71:         return false;
 72:     }
 73: 
 74:     /**
 75:      * Return the title for the option group representing this module.
 76:      *
 77:      * @return string The group title.
 78:      */
 79:     public function getOptionGroupTitle()
 80:     {
 81:         return '';
 82:     }
 83: 
 84:     /**
 85:      * Return the description for the option group representing this module.
 86:      *
 87:      * @return string The group description.
 88:      */
 89:     public function getOptionGroupDescription()
 90:     {
 91:         return '';
 92:     }
 93: 
 94:     /**
 95:      * Return the options for this module.
 96:      *
 97:      * @return array The group options.
 98:      */
 99:     public function getOptionGroupOptions()
100:     {
101:         return array();
102:     }
103: 
104:     /**
105:      * Handle the options and arguments.
106:      *
107:      * @param mixed &$options   An array of options.
108:      * @param mixed &$arguments An array of arguments.
109:      * @param array &$world     A list of initialized dependencies.
110:      *
111:      * @return NULL
112:      */
113:     public function handleArguments(&$options, &$arguments, &$world)
114:     {
115:     }
116: 
117:     /**
118:      * Run the module.
119:      *
120:      * @param Horde_Cli $cli       The CLI handler.
121:      * @param mixed     $options   An array of options.
122:      * @param mixed     $arguments An array of arguments.
123:      * @param array     &$world    A list of initialized dependencies.
124:      *
125:      * @return NULL
126:      */
127:     public function run($cli, $options, $arguments, &$world)
128:     {
129:         if (!isset($arguments[1])) {
130:             $action = 'all';
131:         } else {
132:             $action = $arguments[1];
133:         }
134:         switch ($action) {
135:         case 'all':
136:             if (!isset($arguments[2])) {
137:                 $folders = $world['storage']->getList()->getQuery()->listTypes();
138:             } else {
139:                 $names = $world['storage']->getList()
140:                     ->getQuery()
141:                     ->listByType($arguments[2]);
142:                 $folders = array();
143:                 foreach ($names as $name) {
144:                     $folders[$name] = $arguments[2];
145:                 }
146:             }
147:             foreach ($folders as $folder => $type) {
148:                 if ($type == 'mail') {
149:                     continue;
150:                 }
151:                 $data = $world['storage']->getData($folder, $type);
152:                 foreach ($data->getObjects() as $id => $object) {
153:                     $this->_yamlOutput($cli, $folder . ': ' . $id, $object);
154:                 }
155:             }
156:             break;
157:         case 'defects':
158:             if (!isset($arguments[2])) {
159:                 $folders = $world['storage']->getList()->getQuery()->listTypes();
160:             } else {
161:                 $names = $world['storage']->getList()
162:                     ->getQuery()
163:                     ->listByType($arguments[2]);
164:                 $folders = array();
165:                 foreach ($names as $name) {
166:                     $folders[$name] = $arguments[2];
167:                 }
168:             }
169:             foreach ($folders as $folder => $type) {
170:                 if ($type == 'mail') {
171:                     continue;
172:                 }
173:                 $data = $world['storage']->getData($folder, $type);
174:                 foreach ($data->getErrors() as $id) {
175:                     $complete = $data->fetchComplete($id);
176:                     $message = "FAILED PARSING:\n\n" .
177:                         $complete[1]->toString(array('headers' => $complete[0]));
178:                     $this->_messageOutput($cli, $folder . ': ' . $id, $message);
179:                 }
180:                 foreach ($data->getDuplicates() as $object => $ids) {
181:                     foreach ($ids as $id) {
182:                         $this->_yamlOutput(
183:                             $cli,
184:                             "DUPLICATE $object in $folder (backend $id)",
185:                             $data->fetch(array($id))
186:                         );
187:                     }
188:                 }
189:             }
190:             break;
191:         case 'issuelist':
192:             if (!isset($arguments[2])) {
193:                 $folders = $world['storage']->getList()->getQuery()->listTypes();
194:             } else {
195:                 $names = $world['storage']->getList()
196:                     ->getQuery()
197:                     ->listByType($arguments[2]);
198:                 $folders = array();
199:                 foreach ($names as $name) {
200:                     $folders[$name] = $arguments[2];
201:                 }
202:             }
203:             foreach ($folders as $folder => $type) {
204:                 if ($type == 'mail') {
205:                     continue;
206:                 }
207:                 $data = $world['storage']->getData($folder, $type);
208:                 $issues = '';
209:                 $errors = $data->getErrors();
210:                 if (!empty($errors)) {
211:                     $issues = "FAILED parsing the messages with the following UIDs:\n\n";
212:                     foreach ($errors as $id) {
213:                         $issues .= " - $id\n";
214:                     }
215:                     $issues .= "\n";
216:                 }
217:                 $duplicates = $data->getDuplicates();
218:                 if (!empty($duplicates)) {
219:                     foreach ($duplicates as $object => $ids) {
220:                         $issues .= "DUPLICATE object ID \"$object\" represented by messages with the following UIDs:\n\n";
221:                         foreach ($ids as $id) {
222:                             $issues .= " - $id\n";
223:                         }
224:                         $issues .= "\n";
225:                     }
226:                 }
227:                 if (!empty($issues)) {
228:                     $cli->writeln('Error report for folder "' . $folder . '"');
229:                     $cli->writeln('================================================================================');
230:                     $cli->writeln();
231:                     $cli->writeln($issues);
232:                     $cli->writeln('================================================================================');
233:                     $cli->writeln();
234:                 }
235:             }
236:             break;
237:         default:
238:             $cli->message(
239:                 sprintf(
240:                     Horde_Kolab_Cli_Translation::t('Action %s not supported!'),
241:                     $action
242:                 ),
243:                 'cli.error'
244:             );
245:             break;
246:         }
247:     }
248: 
249:     private function _messageOutput($cli, $id, $output)
250:     {
251:         $cli->writeln('Message UID [' . $id . ']');
252:         $cli->writeln('================================================================================');
253:         $cli->writeln();
254:         $cli->writeln($output);
255:         $cli->writeln();
256:         $cli->writeln('================================================================================');
257:         $cli->writeln();
258:     }
259: 
260:     private function _yamlOutput($cli, $id, $output)
261:     {
262:         $output = $this->_convertDates($output);
263:         if (class_exists('Horde_Yaml')) {
264:             $this->_messageOutput($cli, $id, Horde_Yaml::dump($output));
265:         } else {
266:             $this->_messageOutput($cli, $id, print_r($output, true));
267:         }
268:     }
269: 
270:     private function _convertDates($output)
271:     {
272:         $result = array();
273:         foreach ($output as $name => $element) {
274:             if (is_array($element)) {
275:                 $result[$name] = $this->_convertDates($element);
276:             } else if ($element instanceOf DateTime) {
277:                 $result[$name] = $element->format('c');
278:             } else {
279:                 $result[$name] = $element;
280:             }
281:         }
282:         return $result;
283:     }
284: }
API documentation generated by ApiGen