protected function getToDBConnection(InputInterface $input, OutputInterface $output) { $type = $input->getArgument('type'); $connectionParams = array('host' => $input->getArgument('hostname'), 'user' => $input->getArgument('username'), 'password' => $input->getOption('password'), 'dbname' => $input->getArgument('database'), 'tablePrefix' => $this->config->getValue('dbtableprefix', 'oc_')); if ($input->getOption('port')) { $connectionParams['port'] = $input->getOption('port'); } return $this->connectionFactory->getConnection($type, $connectionParams); }
public function testConfigMerge() { // Create additional config $additionalConfig = '<?php $CONFIG=array("php53"=>"totallyOutdated");'; $additionalConfigPath = $this->randomTmpDir . 'additionalConfig.testconfig.php'; file_put_contents($additionalConfigPath, $additionalConfig); // Reinstantiate the config to force a read-in of the additional configs $this->config = new \OC\Config($this->randomTmpDir, 'testconfig.php'); // Ensure that the config value can be read and the config has not been modified $this->assertSame('totallyOutdated', $this->config->getValue('php53', 'bogusValue')); $this->assertEquals(self::TESTCONTENT, file_get_contents($this->configFile)); // Write a new value to the config $this->config->setValue('CoolWebsites', array('demo.owncloud.org', 'owncloud.org', 'owncloud.com')); $expected = "<?php\n\$CONFIG = array (\n 'foo' => 'bar',\n 'beers' => \n array (\n 0 => 'Appenzeller',\n " . " 1 => 'Guinness',\n 2 => 'Kölsch',\n ),\n 'alcohol_free' => false,\n 'php53' => 'totallyOutdated',\n 'CoolWebsites' => \n array (\n " . " 0 => 'demo.owncloud.org',\n 1 => 'owncloud.org',\n 2 => 'owncloud.com',\n ),\n);\n"; $this->assertEquals($expected, file_get_contents($this->configFile)); // Cleanup unlink($additionalConfigPath); }
/** * @brief Gets a value from config.php * @param string $key key * @param string $default = null default value * @return string the value or $default * * This function gets the value from config.php. If it does not exist, * $default will be returned. */ public static function getValue($key, $default = null) { return self::$object->getValue($key, $default); }
/** * @param \OC\Config $config * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform */ public function __construct($config, $platform) { $this->platform = $platform; $this->DBNAME = $config->getValue('dbname', 'owncloud'); $this->DBTABLEPREFIX = $config->getValue('dbtableprefix', 'oc_'); }
/** * @throws \RuntimeException when the 3rdparty directory is missing or * the app path list is empty or contains an invalid path */ public static function initPaths() { if (defined('PHPUNIT_CONFIG_DIR')) { self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; } elseif (defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { self::$configDir = OC::$SERVERROOT . '/tests/config/'; } else { self::$configDir = OC::$SERVERROOT . '/config/'; } self::$config = new \OC\Config(self::$configDir); OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT))); /** * FIXME: The following lines are required because we can't yet instantiiate * \OC::$server->getRequest() since \OC::$server does not yet exist. */ $params = ['server' => ['SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'], 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME']]]; $fakeRequest = new \OC\AppFramework\Http\Request($params, null, new \OC\AllConfig(new \OC\SystemConfig(self::$config))); $scriptName = $fakeRequest->getScriptName(); if (substr($scriptName, -1) == '/') { $scriptName .= 'index.php'; //make sure suburi follows the same rules as scriptName if (substr(OC::$SUBURI, -9) != 'index.php') { if (substr(OC::$SUBURI, -1) != '/') { OC::$SUBURI = OC::$SUBURI . '/'; } OC::$SUBURI = OC::$SUBURI . 'index.php'; } } if (OC::$CLI) { OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); } else { if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) { OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { OC::$WEBROOT = '/' . OC::$WEBROOT; } } else { // The scriptName is not ending with OC::$SUBURI // This most likely means that we are calling from CLI. // However some cron jobs still need to generate // a web URL, so we use overwritewebroot as a fallback. OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); } // Resolve /owncloud to /owncloud/ to ensure to always have a trailing // slash which is required by URL generation. if ($_SERVER['REQUEST_URI'] === \OC::$WEBROOT && substr($_SERVER['REQUEST_URI'], -1) !== '/') { header('Location: ' . \OC::$WEBROOT . '/'); exit; } } // search the 3rdparty folder OC::$THIRDPARTYROOT = self::$config->getValue('3rdpartyroot', null); OC::$THIRDPARTYWEBROOT = self::$config->getValue('3rdpartyurl', null); if (empty(OC::$THIRDPARTYROOT) && empty(OC::$THIRDPARTYWEBROOT)) { if (file_exists(OC::$SERVERROOT . '/3rdparty')) { OC::$THIRDPARTYROOT = OC::$SERVERROOT; OC::$THIRDPARTYWEBROOT = OC::$WEBROOT; } elseif (file_exists(OC::$SERVERROOT . '/../3rdparty')) { OC::$THIRDPARTYWEBROOT = rtrim(dirname(OC::$WEBROOT), '/'); OC::$THIRDPARTYROOT = rtrim(dirname(OC::$SERVERROOT), '/'); } } if (empty(OC::$THIRDPARTYROOT) || !file_exists(OC::$THIRDPARTYROOT)) { throw new \RuntimeException('3rdparty directory not found! Please put the ownCloud 3rdparty' . ' folder in the ownCloud folder or the folder above.' . ' You can also configure the location in the config.php file.'); } // search the apps folder $config_paths = self::$config->getValue('apps_paths', array()); if (!empty($config_paths)) { foreach ($config_paths as $paths) { if (isset($paths['url']) && isset($paths['path'])) { $paths['url'] = rtrim($paths['url'], '/'); $paths['path'] = rtrim($paths['path'], '/'); OC::$APPSROOTS[] = $paths; } } } elseif (file_exists(OC::$SERVERROOT . '/apps')) { OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true); } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { OC::$APPSROOTS[] = array('path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', 'url' => '/apps', 'writable' => true); } if (empty(OC::$APPSROOTS)) { throw new \RuntimeException('apps directory not found! Please put the ownCloud apps folder in the ownCloud folder' . ' or the folder above. You can also configure the location in the config.php file.'); } $paths = array(); foreach (OC::$APPSROOTS as $path) { $paths[] = $path['path']; if (!is_dir($path['path'])) { throw new \RuntimeException(sprintf('App directory "%s" not found! Please put the ownCloud apps folder in the' . ' ownCloud folder or the folder above. You can also configure the location in the' . ' config.php file.', $path['path'])); } } // set the right include path set_include_path(OC::$SERVERROOT . '/lib/private' . PATH_SEPARATOR . OC::$SERVERROOT . '/config' . PATH_SEPARATOR . OC::$THIRDPARTYROOT . '/3rdparty' . PATH_SEPARATOR . implode(PATH_SEPARATOR, $paths) . PATH_SEPARATOR . get_include_path() . PATH_SEPARATOR . OC::$SERVERROOT); }
/** * Looks up a system wide defined value * * @param string $key the key of the value, under which it was saved * @param mixed $default the default value to be returned if the value isn't set * @return mixed the value or $default */ public function getValue($key, $default = '') { return $this->config->getValue($key, $default); }
public function testGetValue() { $this->assertEquals('bar', $this->config->getValue('foo')); $this->assertEquals(null, $this->config->getValue('bar')); $this->assertEquals('moo', $this->config->getValue('bar', 'moo')); }