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: class Horde_Kolab_Cli_Module_List
29: implements Horde_Kolab_Cli_Module
30: {
31: 32: 33: 34: 35:
36: public function getUsage()
37: {
38: return Horde_Kolab_Cli_Translation::t(" list - Handle folder lists (the default action is \"folders\")
39:
40: - folders : List the folders in the backend
41: - types : Display all folders that have a folder type.
42: - type TYPE : Display the folders of type TYPE.
43: - owners : List all folders and their owners.
44: - defaults : List the default folders for all users.
45: - aclsupport : Display if the server supports ACL.
46: - namespace : Display the server namespace information.
47: - sync : Synchronize the cache.
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 = 'folders';
131: } else {
132: $action = $arguments[1];
133: }
134: switch ($action) {
135: case 'folders':
136: $folders = $world['storage']->getList()->listFolders();
137: foreach ($folders as $folder) {
138: $cli->writeln($folder);
139: }
140: break;
141: case 'types':
142: $types = $world['storage']->getList()
143: ->getQuery()
144: ->listTypes();
145: if (!empty($types)) {
146: $pad = max(array_map('strlen', array_keys($types))) + 2;
147: foreach ($types as $folder => $type) {
148: $cli->writeln(Horde_String::pad($folder . ':', $pad) . $type);
149: }
150: }
151: break;
152: case 'type':
153: if (!isset($arguments[2])) {
154: throw new Horde_Kolab_Cli_Exception('You must provide a TYPE argument!');
155: }
156: $type = $arguments[2];
157: $folders = $world['storage']->getList()
158: ->getQuery()
159: ->listByType($type);
160: foreach ($folders as $folder) {
161: $cli->writeln($folder);
162: }
163: break;
164: case 'owners':
165: $owners = $world['storage']->getList()
166: ->getQuery()
167: ->listOwners();
168: if (!empty($owners)) {
169: $pad = max(array_map('strlen', array_keys($owners))) + 2;
170: foreach ($owners as $folder => $owner) {
171: $cli->writeln(Horde_String::pad($folder . ':', $pad) . $owner);
172: }
173: }
174: break;
175: case 'defaults':
176: $defaults = $world['storage']->getList()
177: ->getQuery()
178: ->listDefaults();
179: if (!empty($defaults)) {
180: foreach ($defaults as $owner => $folders) {
181: $cli->writeln('User "' . $owner . '":');
182: $cli->writeln();
183: foreach ($folders as $type => $folder) {
184: $cli->writeln(' ' . Horde_String::pad($type . ':', 14) . $folder);
185: }
186: $cli->writeln();
187: }
188: }
189: break;
190: case 'aclsupport':
191: if ($world['storage']->getList()
192: ->getQuery(Horde_Kolab_Storage_List::QUERY_ACL)
193: ->hasAclSupport()) {
194: echo "The remote server supports ACL.\n";
195: } else {
196: echo "The remote server does not support ACL.\n";
197: }
198: break;
199: case 'namespaces':
200: $cli->writeln((string)$world['storage']->getList()->getNamespace());
201: break;
202: case 'sync':
203: $folders = $world['storage']->getList()->synchronize();
204: break;
205: default:
206: $cli->message(
207: sprintf(
208: Horde_Kolab_Cli_Translation::t('Action %s not supported!'),
209: $action
210: ),
211: 'cli.error'
212: );
213: break;
214: }
215: }
216: }