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_Base
31: implements Horde_Kolab_Cli_Module
32: {
33: 34: 35: 36: 37:
38: public function getUsage()
39: {
40: return '';
41: }
42:
43: 44: 45: 46: 47: 48:
49: public function getBaseOptions()
50: {
51: return array(
52: new Horde_Argv_Option(
53: '-d',
54: '--driver',
55: array(
56: 'action' => 'store',
57: 'choices' => array('horde', 'horde-php', 'php', 'pear', 'roundcube', 'mock'),
58: 'help' => Horde_Kolab_Cli_Translation::t("The Kolab backend driver that should be used.
59: Choices are:
60:
61: - horde [IMAP]: The Horde_Imap_Client driver as pure PHP implementation.
62: - horde-php [IMAP]: The Horde_Imap_Client driver based on c-client in PHP
63: - php [IMAP]: The PHP imap_* functions which are based on c-client
64: - pear [IMAP]: The PEAR-Net_IMAP driver
65: - roundcube [IMAP]: The roundcube IMAP driver
66: - mock [Mem.]: A dummy driver that uses memory."
67: ),
68: )
69: ),
70: new Horde_Argv_Option(
71: '-u',
72: '--username',
73: array(
74: 'action' => 'store',
75: 'help' => Horde_Kolab_Cli_Translation::t('The user accessing the backend.')
76: )
77: ),
78: new Horde_Argv_Option(
79: '-p',
80: '--password',
81: array(
82: 'action' => 'store',
83: 'help' => Horde_Kolab_Cli_Translation::t('The password of the user accessing the backend.')
84: )
85: ),
86: new Horde_Argv_Option(
87: '-H',
88: '--host',
89: array(
90: 'action' => 'store',
91: 'help' => Horde_Kolab_Cli_Translation::t('The host that holds the data.'),
92: )
93: ),
94: new Horde_Argv_Option(
95: '-P',
96: '--port',
97: array(
98: 'action' => 'store',
99: 'help' => Horde_Kolab_Cli_Translation::t('The port that should be used to connect to the host.')
100: )
101: ),
102: new Horde_Argv_Option(
103: '-S',
104: '--secure',
105: array(
106: 'action' => 'store',
107: 'help' => Horde_Kolab_Cli_Translation::t('Sets the connection type. Use either "tls" or "ssl" here.')
108: )
109: ),
110: new Horde_Argv_Option(
111: '-t',
112: '--timed',
113: array(
114: 'action' => 'store_true',
115: 'help' => Horde_Kolab_Cli_Translation::t('Produce time measurements to indicate how long the processing takes. You *must* activate logging for this as well.')
116: )
117: ),
118: new Horde_Argv_Option(
119: '-m',
120: '--memory',
121: array(
122: 'action' => 'store_true',
123: 'help' => Horde_Kolab_Cli_Translation::t('Report memory consumption statistics. You *must* activate logging for this as well.')
124: )
125: ),
126: new Horde_Argv_Option(
127: '-n',
128: '--nocache',
129: array(
130: 'action' => 'store_true',
131: 'help' => Horde_Kolab_Cli_Translation::t('Deactivate caching of the IMAP data.')
132: )
133: ),
134: new Horde_Argv_Option(
135: '-l',
136: '--log',
137: array(
138: 'action' => 'store',
139: '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.')
140: )
141: ),
142: new Horde_Argv_Option(
143: '-D',
144: '--debug',
145: array(
146: 'action' => 'store',
147: '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.'),
148: )
149: ),
150: new Horde_Argv_Option(
151: '-c',
152: '--config',
153: array(
154: 'action' => 'store',
155: 'help' => Horde_Kolab_Cli_Translation::t('Path to the configuration file. Comman line parameters overwrite values from the configuration file.')
156: )
157: ),
158: );
159: }
160:
161: 162: 163: 164: 165:
166: public function hasOptionGroup()
167: {
168: return false;
169: }
170:
171: 172: 173: 174: 175:
176: public function getOptionGroupTitle()
177: {
178: return '';
179: }
180:
181: 182: 183: 184: 185:
186: public function getOptionGroupDescription()
187: {
188: return '';
189: }
190:
191: 192: 193: 194: 195:
196: public function getOptionGroupOptions()
197: {
198: return array();
199: }
200:
201: 202: 203: 204: 205: 206: 207: 208: 209:
210: public function handleArguments(&$options, &$arguments, &$world)
211: {
212: if (isset($options['driver'])
213: && in_array($options['driver'], array('roundcube', 'php', 'pear'))) {
214: if (defined('E_DEPRECATED')) {
215: error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED & ~E_NOTICE);
216: } else {
217: error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE);
218: }
219: }
220: if (isset($options['log'])) {
221: if (class_exists('Horde_Log_Logger')) {
222: $options['log'] = new Horde_Log_Logger(
223: new Horde_Log_Handler_Stream(
224: ($options['log'] == 'STDOUT') ? STDOUT : $options['log']
225: )
226: );
227: } else {
228: file_put_contents($options['log'], 'The Horde_Log_Logger class is not available!');
229: unset($options['log']);
230: }
231: }
232: $world['storage'] = $this->_getStorage($options);
233: $world['format'] = $this->_getFormat($options);
234: }
235:
236:
237: 238: 239: 240: 241: 242: 243:
244: private function _getStorage($options)
245: {
246: if (empty($options['driver'])) {
247: return;
248: }
249: if ($options['driver'] == 'mock') {
250: $options['data'] = array(
251: 'format' => 'brief',
252: 'user/test' => null
253: );
254: }
255: $params = array(
256: 'driver' => $options['driver'],
257: 'params' => $options,
258: 'logger' => isset($options['log']) ? $options['log'] : null,
259: 'timelog' => isset($options['log']) && isset($options['timed']) ? $options['log'] : null,
260: );
261: if (empty($options['nocache'])) {
262: $params['cache'] = array('prefix' => 'kolab_cache_', 'dir' => '/tmp/kolab', 'lifetime' => 0);
263: }
264: $factory = new Horde_Kolab_Storage_Factory($params);
265: return $factory->create();
266: }
267:
268: 269: 270: 271: 272: 273: 274:
275: private function _getFormat($options)
276: {
277: return new Horde_Kolab_Format_Factory(
278: array(
279: 'timelog' => isset($options['log']) && isset($options['timed']) ? $options['log'] : null,
280: 'memlog' => isset($options['log']) && isset($options['memory']) ? $options['log'] : null,
281: )
282: );
283: }
284: }