9714: add getConfig cli function
authorsstamer <s.stamer@metaways.de>
Thu, 27 Feb 2014 13:21:56 +0000 (14:21 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 27 Feb 2014 16:06:59 +0000 (17:06 +0100)
https://forge.tine20.org/mantisbt/view.php?id=9714
- add getConfig and test

Change-Id: I2b6abe358f51d87b1b97bcd80c26db47115b9f29
Reviewed-on: http://gerrit.tine20.com/customers/376
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/setup/Setup/CliTest.php
tine20/Setup/Frontend/Cli.php
tine20/Setup/Server/Cli.php

index 0dd33a3..4c3704b 100644 (file)
@@ -35,24 +35,37 @@ class Setup_CliTest extends PHPUnit_Framework_TestCase
      */
     public function testSetConfig()
     {
-        $this->_cliHelper(array('--setconfig','--','configkey=allowedJsonOrigins', 'configvalue='.'["foo","bar"]'));
+        $output = $this->_cliHelper('setconfig', array('--setconfig','--','configkey=allowedJsonOrigins', 'configvalue='.'["foo","bar"]'));
+        $this->assertContains('OK - Updated configuration option allowedJsonOrigins for application Tinebase', $output);
         $result = Tinebase_Config_Abstract::factory('Tinebase')->get('allowedJsonOrigins');
         $this->assertEquals("foo", $result[0]);
         $this->assertEquals("bar", $result[1]);
     }
     
     /**
+     * Test GetConfig
+     */
+    public function testGetConfig()
+    {
+        $this->testSetConfig();
+        $result = $this->_cliHelper('getconfig', array('--getconfig','--','configkey=allowedJsonOrigins'));
+        $result = Zend_Json::decode($result);
+        $this->assertEquals("foo", $result[0]);
+        $this->assertEquals("bar", $result[1]);
+    }
+    
+    /**
      * call handle cli function with params
      * 
      * @param array $_params
      */
-    protected function _cliHelper($_params)
+    protected function _cliHelper($command, $_params)
     {
-        $opts = new Zend_Console_Getopt(array('setconfig=s' => 'setconfig'));
+        $opts = new Zend_Console_Getopt(array($command => $command));
         $opts->setArguments($_params);
         ob_start();
         $this->_cli->handle($opts, false);
         $out = ob_get_clean();
-        $this->assertContains('OK - Updated configuration option allowedJsonOrigins for application Tinebase', $out);
+        return $out;
     }
 }
\ No newline at end of file
index 7f3cfeb..834dbf1 100644 (file)
@@ -70,6 +70,8 @@ class Setup_Frontend_Cli
             $this->_setConfig($_opts);
         } elseif(isset($_opts->create_admin)) {
             $this->_createAdminUser($_opts);
+        } elseif(isset($_opts->getconfig)) {
+            $this->_getConfig($_opts);
         }
         
         if ($exitAfterHandle) {
@@ -404,6 +406,32 @@ class Setup_Frontend_Cli
     }
     
     /**
+     * get config
+     *
+     */
+    protected function _getConfig(Zend_Console_Getopt $_opts)
+    {
+        $options = $this->_parseRemainingArgs($_opts->getRemainingArgs());
+        $errors = array();
+        if (empty($options['configkey'])) {
+            $errors[] = 'Missing argument: configkey';
+        }
+        $configKey = (string)$options['configkey'];
+        $applicationName = (isset($options['app'])) ? $options['app'] : 'Tinebase';
+        
+        if (empty($errors)) {
+            $value = Tinebase_Config_Abstract::factory($applicationName)->get($configKey);
+            $value = is_string($value) ? $value : Zend_Json::encode($value);
+            echo $value . " \n";
+        } else {
+            echo "ERRORS - The following errors occured: \n";
+            foreach ($errors as $error) {
+                echo "- " . $error . "\n";
+            }
+        }
+    }
+    
+    /**
      * create admin user / activate existing user / allow to reset password
      * 
      * @param Zend_Console_Getopt $_opts
index 6431c9a..6dbeb44 100644 (file)
@@ -36,6 +36,7 @@ class Setup_Server_Cli implements Tinebase_Server_Interface
                            setup.php --setconfig -- configkey=sample1 configvalue=value11
                            setup.php --setconfig -- configkey=sample2 configvalue=arrayKey1:Value1,arrayKey2:value2
                           ',
+                'getconfig'                 => 'Get Config value for a specify the key \' -- configKey="your_key"\'',
                 'check_requirements'        => 'Check if all requirements are met to install and run tine20',
                 'create_admin'              => 'Create new admin user (or reactivate if already exists)',
                 'install-s'                 => 'Install applications [All] or comma separated list;'
@@ -70,7 +71,8 @@ class Setup_Server_Cli implements Tinebase_Server_Interface
             empty($opts->egw14import) && 
             empty($opts->check_requirements) && 
             empty($opts->create_admin) && 
-            empty($opts->setconfig))) 
+            empty($opts->setconfig) && 
+            empty($opts->getconfig))) 
         {
             echo $opts->getUsageMessage();
             exit;