From 78962a9be3756fd399a6a1757f30f4c3c65ea1ee Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel
Date: Tue, 21 Dec 2010 22:21:54 +0100
Subject: [PATCH] Allow to activate logging.
---
framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module.php | 6 ++--
.../Kolab_Cli/lib/Horde/Kolab/Cli/Module/Base.php | 34 ++++++++++++++++++----
.../lib/Horde/Kolab/Cli/Module/Folder.php | 6 ++--
framework/Kolab_Cli/package.xml | 4 +++
.../Kolab_Cli/test/Horde/Kolab/Cli/TestCase.php | 18 ++++++++++++
.../Horde/Kolab/Cli/Unit/Cli/Module/BaseTest.php | 28 ++++++++++++++++--
.../test/Horde/Kolab/Cli/Unit/Cli/OptionsTest.php | 11 +++++++
7 files changed, 93 insertions(+), 14 deletions(-)
diff --git a/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module.php b/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module.php
index 531762a7d..650791b54 100644
--- a/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module.php
+++ b/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module.php
@@ -33,10 +33,10 @@ extends Horde_Cli_Modular_Module
/**
* Handle the options and arguments.
*
- * @param mixed $options An array of options.
- * @param mixed $arguments An array of arguments.
+ * @param mixed &$options An array of options.
+ * @param mixed &$arguments An array of arguments.
*
* @return NULL
*/
- public function handleArguments($options, $arguments);
+ public function handleArguments(&$options, &$arguments);
}
\ No newline at end of file
diff --git a/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/Base.php b/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/Base.php
index 702b710da..2d48916ae 100644
--- a/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/Base.php
+++ b/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/Base.php
@@ -65,7 +65,8 @@ Choices are:
- pear [IMAP]: The PEAR-Net_IMAP driver
- roundcube [IMAP]: The roundcube IMAP driver
- mock [Mem.]: A dummy driver that uses memory."
- )
+ ),
+ 'default' => 'horde'
)
),
new Horde_Argv_Option(
@@ -89,7 +90,8 @@ Choices are:
'--host',
array(
'action' => 'store',
- 'help' => Horde_Kolab_Cli_Translation::t('The host that holds the data.')
+ 'help' => Horde_Kolab_Cli_Translation::t('The host that holds the data.'),
+ 'default' => 'localhost'
)
),
new Horde_Argv_Option(
@@ -100,6 +102,14 @@ Choices are:
'help' => Horde_Kolab_Cli_Translation::t('Produce time measurements to indicate how long the processing takes.')
)
),
+ new Horde_Argv_Option(
+ '-l',
+ '--log',
+ array(
+ 'action' => 'store',
+ 'help' => Horde_Kolab_Cli_Translation::t('Write a log file in the provided LOG location.')
+ )
+ ),
);
}
@@ -146,19 +156,31 @@ Choices are:
/**
* Handle the options and arguments.
*
- * @param mixed $options An array of options.
- * @param mixed $arguments An array of arguments.
+ * @param mixed &$options An array of options.
+ * @param mixed &$arguments An array of arguments.
*
* @return NULL
*/
- public function handleArguments($options, $arguments)
+ public function handleArguments(&$options, &$arguments)
{
- if (in_array($options['driver'], array('roundcube', 'php', 'pear'))) {
+ if (isset($options['driver'])
+ && in_array($options['driver'], array('roundcube', 'php', 'pear'))) {
if (defined('E_DEPRECATED')) {
error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED & ~E_NOTICE);
} else {
error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE);
}
}
+ if (isset($options['log'])) {
+ if (class_exists('Horde_Log_Logger')) {
+ $options['logger'] = new Horde_Log_Logger(
+ new Horde_Log_Handler_Stream(
+ $options['log']
+ )
+ );
+ } else {
+ file_put_contents($options['log'], 'The Horde_Log_Logger class is not available!');
+ }
+ }
}
}
\ No newline at end of file
diff --git a/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/Folder.php b/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/Folder.php
index d74516039..ab5cc9f5e 100644
--- a/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/Folder.php
+++ b/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/Folder.php
@@ -96,12 +96,12 @@ implements Horde_Kolab_Cli_Module
/**
* Handle the options and arguments.
*
- * @param mixed $options An array of options.
- * @param mixed $arguments An array of arguments.
+ * @param mixed &$options An array of options.
+ * @param mixed &$arguments An array of arguments.
*
* @return NULL
*/
- public function handleArguments($options, $arguments)
+ public function handleArguments(&$options, &$arguments)
{
}
diff --git a/framework/Kolab_Cli/package.xml b/framework/Kolab_Cli/package.xml
index 1ff398e70..62ff61fda 100644
--- a/framework/Kolab_Cli/package.xml
+++ b/framework/Kolab_Cli/package.xml
@@ -103,6 +103,10 @@