public function testSavingDebugMode() { $this->config->setDebugMode(true); $this->config->deleteKey('foo'); // change something so we save to the config file $this->assertAttributeEquals(array(), 'cache', $this->config); $this->assertAttributeEquals(true, 'debugMode', $this->config); $content = file_get_contents(self::CONFIG_FILE); $expected = "<?php\ndefine('DEBUG',true);\n\$CONFIG = array (\n);\n"; $this->assertEquals($expected, $content); }
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); }
protected function saveDBInfo(InputInterface $input) { $type = $input->getArgument('type'); $username = $input->getArgument('username'); $dbhost = $input->getArgument('hostname'); $dbname = $input->getArgument('database'); $password = $input->getOption('password'); if ($input->getOption('port')) { $dbhost .= ':' . $input->getOption('port'); } $this->config->setValue('dbtype', $type); $this->config->setValue('dbname', $dbname); $this->config->setValue('dbhost', $dbhost); $this->config->setValue('dbuser', $username); $this->config->setValue('dbpassword', $password); }
/** * @brief Removes a key from the config * @param string $key key * * This function removes a key from the config.php. * */ public static function deleteKey($key) { self::$object->deleteKey($key); }
/** * @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); }
/** * Delete a system wide defined value * * @param string $key the key of the value, under which it was saved */ public function deleteValue($key) { $this->config->deleteKey($key); }