1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29:
30: class Horde_Kolab_Cli_Module_Account
31: implements Horde_Kolab_Cli_Module
32: {
33: 34: 35: 36: 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: 55: 56: 57: 58:
59: public function getBaseOptions()
60: {
61: return array();
62: }
63:
64: 65: 66: 67: 68:
69: public function hasOptionGroup()
70: {
71: return false;
72: }
73:
74: 75: 76: 77: 78:
79: public function getOptionGroupTitle()
80: {
81: return '';
82: }
83:
84: 85: 86: 87: 88:
89: public function getOptionGroupDescription()
90: {
91: return '';
92: }
93:
94: 95: 96: 97: 98:
99: public function getOptionGroupOptions()
100: {
101: return array();
102: }
103:
104: 105: 106: 107: 108: 109: 110: 111: 112:
113: public function handleArguments(&$options, &$arguments, &$world)
114: {
115: }
116:
117: 118: 119: 120: 121: 122: 123: 124: 125: 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: }