*/
namespace OC\Core\Command;
-use OCP\IConfig;
+use OC\SystemConfig;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class Check extends Base {
/**
- * @var IConfig
+ * @var SystemConfig
*/
private $config;
- public function __construct(IConfig $config) {
+ public function __construct(SystemConfig $config) {
parent::__construct();
$this->config = $config;
}
use InvalidArgumentException;
use OC\Setup;
-use OCP\IConfig;
+use OC\SystemConfig;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
class Install extends Command {
/**
- * @var IConfig
+ * @var SystemConfig
*/
private $config;
- public function __construct(IConfig $config) {
+ public function __construct(SystemConfig $config) {
parent::__construct();
$this->config = $config;
}
/** @var $application Symfony\Component\Console\Application */
$application->add(new \Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand());
$application->add(new OC\Core\Command\Status);
-$application->add(new OC\Core\Command\Check(\OC::$server->getConfig()));
+$application->add(new OC\Core\Command\Check(\OC::$server->getSystemConfig()));
$infoParser = new \OC\App\InfoParser();
$application->add(new OC\Core\Command\App\CheckCode($infoParser));
$application->add(new OC\Core\Command\L10n\CreateJs());
$application->add(new OC\Core\Command\Config\System\SetConfig(\OC::$server->getSystemConfig()));
$application->add(new OC\Core\Command\Db\GenerateChangeScript());
- $application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->getConfig())));
+ $application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig())));
$application->add(new OC\Core\Command\Encryption\Disable(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Encryption\Enable(\OC::$server->getConfig(), \OC::$server->getEncryptionManager()));
$application->add(new OC\Core\Command\Security\ImportCertificate(\OC::$server->getCertificateManager(null)));
$application->add(new OC\Core\Command\Security\RemoveCertificate(\OC::$server->getCertificateManager(null)));
} else {
- $application->add(new OC\Core\Command\Maintenance\Install(\OC::$server->getConfig()));
+ $application->add(new OC\Core\Command\Maintenance\Install(\OC::$server->getSystemConfig()));
}
self::performSameSiteCookieProtection();
if (!defined('OC_CONSOLE')) {
- $errors = OC_Util::checkServer(\OC::$server->getConfig());
+ $errors = OC_Util::checkServer(\OC::$server->getSystemConfig());
if (count($errors) > 0) {
if (self::$CLI) {
// Convert l10n string into regular string for usage in database
// Check if Nextcloud is installed or in maintenance (update) mode
if (!$systemConfig->getValue('installed', false)) {
\OC::$server->getSession()->clear();
- $setupHelper = new OC\Setup(\OC::$server->getConfig(), \OC::$server->getIniWrapper(),
+ $setupHelper = new OC\Setup(\OC::$server->getSystemConfig(), \OC::$server->getIniWrapper(),
\OC::$server->getL10N('lib'), \OC::$server->getThemingDefaults(), \OC::$server->getLogger(),
\OC::$server->getSecureRandom());
$controller = new OC\Core\Controller\SetupController($setupHelper);
}
if ($input->getFirstArgument() !== 'check') {
- $errors = \OC_Util::checkServer(\OC::$server->getConfig());
+ $errors = \OC_Util::checkServer(\OC::$server->getSystemConfig());
if (!empty($errors)) {
foreach ($errors as $error) {
$output->writeln((string)$error['error']);
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Event\Listeners\OracleSessionInit;
use Doctrine\DBAL\Event\Listeners\SQLSessionInit;
-use OCP\IConfig;
+use OC\SystemConfig;
/**
* Takes care of creating and configuring Doctrine connections.
],
];
- public function __construct(IConfig $config) {
- if($config->getSystemValue('mysql.utf8mb4', false)) {
+ /** @var SystemConfig */
+ private $config;
+
+ /**
+ * ConnectionFactory constructor.
+ *
+ * @param SystemConfig $systemConfig
+ */
+ public function __construct(SystemConfig $systemConfig) {
+ $this->config = $systemConfig;
+ if($this->config->getValue('mysql.utf8mb4', false)) {
$this->defaultConnectionParams['mysql']['charset'] = 'utf8mb4';
}
}
/**
* Create the connection parameters for the config
*
- * @param \OC\SystemConfig $config
* @return array
*/
- public function createConnectionParams($config) {
- $type = $config->getValue('dbtype', 'sqlite');
+ public function createConnectionParams() {
+ $type = $this->config->getValue('dbtype', 'sqlite');
$connectionParams = [
- 'user' => $config->getValue('dbuser', ''),
- 'password' => $config->getValue('dbpassword', ''),
+ 'user' => $this->config->getValue('dbuser', ''),
+ 'password' => $this->config->getValue('dbpassword', ''),
];
- $name = $config->getValue('dbname', 'owncloud');
+ $name = $this->config->getValue('dbname', 'owncloud');
if ($this->normalizeType($type) === 'sqlite3') {
- $dataDir = $config->getValue("datadirectory", \OC::$SERVERROOT . '/data');
+ $dataDir = $this->config->getValue("datadirectory", \OC::$SERVERROOT . '/data');
$connectionParams['path'] = $dataDir . '/' . $name . '.db';
} else {
- $host = $config->getValue('dbhost', '');
+ $host = $this->config->getValue('dbhost', '');
if (strpos($host, ':')) {
// Host variable may carry a port or socket.
list($host, $portOrSocket) = explode(':', $host, 2);
$connectionParams['dbname'] = $name;
}
- $connectionParams['tablePrefix'] = $config->getValue('dbtableprefix', 'oc_');
- $connectionParams['sqlite.journal_mode'] = $config->getValue('sqlite.journal_mode', 'WAL');
+ $connectionParams['tablePrefix'] = $this->config->getValue('dbtableprefix', 'oc_');
+ $connectionParams['sqlite.journal_mode'] = $this->config->getValue('sqlite.journal_mode', 'WAL');
//additional driver options, eg. for mysql ssl
- $driverOptions = $config->getValue('dbdriveroptions', null);
+ $driverOptions = $this->config->getValue('dbdriveroptions', null);
if ($driverOptions) {
$connectionParams['driverOptions'] = $driverOptions;
}
});
$this->registerService('DatabaseConnection', function (Server $c) {
$systemConfig = $c->getSystemConfig();
- $factory = new \OC\DB\ConnectionFactory($c->getConfig());
+ $factory = new \OC\DB\ConnectionFactory($systemConfig);
$type = $systemConfig->getValue('dbtype', 'sqlite');
if (!$factory->isValidType($type)) {
throw new \OC\DatabaseException('Invalid database type');
}
- $connectionParams = $factory->createConnectionParams($systemConfig);
+ $connectionParams = $factory->createConnectionParams();
$connection = $factory->getConnection($type, $connectionParams);
$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
return $connection;
use OCP\Security\ISecureRandom;
class Setup {
- /** @var \OCP\IConfig */
+ /** @var SystemConfig */
protected $config;
/** @var IniGetWrapper */
protected $iniWrapper;
protected $random;
/**
- * @param IConfig $config
+ * @param SystemConfig $config
* @param IniGetWrapper $iniWrapper
* @param \OC_Defaults $defaults
*/
- function __construct(IConfig $config,
+ function __construct(SystemConfig $config,
IniGetWrapper $iniWrapper,
IL10N $l10n,
\OC_Defaults $defaults,
if ($allowAllDatabases) {
$configuredDatabases = array_keys($availableDatabases);
} else {
- $configuredDatabases = $this->config->getSystemValue('supportedDatabases',
+ $configuredDatabases = $this->config->getValue('supportedDatabases',
array('sqlite', 'mysql', 'pgsql'));
}
if(!is_array($configuredDatabases)) {
public function getSystemInfo($allowAllDatabases = false) {
$databases = $this->getSupportedDatabases($allowAllDatabases);
- $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data');
+ $dataDir = $this->config->getValue('datadirectory', \OC::$SERVERROOT.'/data');
$errors = array();
$secret = $this->random->generate(48);
//write the config file
- $this->config->setSystemValues([
+ $this->config->setValues([
'passwordsalt' => $salt,
'secret' => $secret,
'trusted_domains' => $trustedDomains,
* @return bool True when success, False otherwise
*/
public static function updateHtaccess() {
- $config = \OC::$server->getConfig();
+ $config = \OC::$server->getSystemConfig();
// For CLI read the value from overwrite.cli.url
if(\OC::$CLI) {
- $webRoot = $config->getSystemValue('overwrite.cli.url', '');
+ $webRoot = $config->getValue('overwrite.cli.url', '');
if($webRoot === '') {
return false;
}
$content.= "\nErrorDocument 404 ".$webRoot."/core/templates/404.php";
// Add rewrite rules if the RewriteBase is configured
- $rewriteBase = $config->getSystemValue('htaccess.RewriteBase', '');
+ $rewriteBase = $config->getValue('htaccess.RewriteBase', '');
if($rewriteBase !== '') {
$content .= "\n<IfModule mod_rewrite.c>";
$content .= "\n Options -MultiViews";
use OC\AllConfig;
use OC\DB\ConnectionFactory;
-use OCP\IConfig;
+use OC\SystemConfig;
use OCP\IL10N;
use OCP\ILogger;
use OCP\Security\ISecureRandom;
protected $dbPort;
/** @var string */
protected $tablePrefix;
- /** @var AllConfig */
+ /** @var SystemConfig */
protected $config;
/** @var ILogger */
protected $logger;
/** @var ISecureRandom */
protected $random;
- public function __construct(IL10N $trans, $dbDefinitionFile, IConfig $config, ILogger $logger, ISecureRandom $random) {
+ public function __construct(IL10N $trans, $dbDefinitionFile, SystemConfig $config, ILogger $logger, ISecureRandom $random) {
$this->trans = $trans;
$this->dbDefinitionFile = $dbDefinitionFile;
$this->config = $config;
$dbPort = !empty($config['dbport']) ? $config['dbport'] : '';
$dbTablePrefix = isset($config['dbtableprefix']) ? $config['dbtableprefix'] : 'oc_';
- $this->config->setSystemValues([
+ $this->config->setValues([
'dbname' => $dbName,
'dbhost' => $dbHost,
'dbport' => $dbPort,
$connectionParams = array_merge($connectionParams, $configOverwrite);
$cf = new ConnectionFactory($this->config);
- return $cf->getConnection($this->config->getSystemValue('dbtype', 'sqlite'), $connectionParams);
+ return $cf->getConnection($this->config->getValue('dbtype', 'sqlite'), $connectionParams);
}
/**
$name = $this->dbName;
$user = $this->dbUser;
//we can't use OC_DB functions here because we need to connect as the administrative user.
- $characterSet = \OC::$server->getSystemConfig()->getValue('mysql.utf8mb4', false) ? 'utf8mb4' : 'utf8';
+ $characterSet = $this->config->getValue('mysql.utf8mb4', false) ? 'utf8mb4' : 'utf8';
$query = "CREATE DATABASE IF NOT EXISTS `$name` CHARACTER SET $characterSet COLLATE ${characterSet}_bin;";
$connection->executeUpdate($query);
} catch (\Exception $ex) {
private function createSpecificUser($username, $connection) {
try {
//user already specified in config
- $oldUser = $this->config->getSystemValue('dbuser', false);
+ $oldUser = $this->config->getValue('dbuser', false);
//we don't have a dbuser specified in config
if ($this->dbUser !== $oldUser) {
]);
}
- $this->config->setSystemValues([
+ $this->config->setValues([
'dbuser' => $this->dbUser,
'dbpassword' => $this->dbPassword,
]);
// allow empty hostname for oracle
$this->dbHost = $config['dbhost'];
- $this->config->setSystemValues([
+ $this->config->setValues([
'dbhost' => $this->dbHost,
'dbtablespace' => $this->dbtablespace,
]);
}
}
- $this->config->setSystemValues([
+ $this->config->setValues([
'dbuser' => $this->dbUser,
'dbname' => $this->dbName,
'dbpassword' => $this->dbPassword,
oci_close($connection);
// connect to the oracle database (schema=$this->dbuser) an check if the schema needs to be filled
- $this->dbUser = $this->config->getSystemValue('dbuser');
+ $this->dbUser = $this->config->getValue('dbuser');
//$this->dbname = \OC_Config::getValue('dbname');
- $this->dbPassword = $this->config->getSystemValue('dbpassword');
+ $this->dbPassword = $this->config->getValue('dbpassword');
$e_host = addslashes($this->dbHost);
$e_dbname = addslashes($this->dbName);
public $dbprettyname = 'PostgreSQL';
public function setupDatabase($username) {
- $systemConfig = $this->config->getSystemConfig();
try {
$connection = $this->connect([
'dbname' => 'postgres'
$this->createDBUser($connection);
}
- $systemConfig->setValues([
+ $this->config->setValues([
'dbuser' => $this->dbUser,
'dbpassword' => $this->dbPassword,
]);
$this->logger->logException($e);
$this->logger->warning('Error trying to connect as "postgres", assuming database is setup and tables need to be created');
$tablesSetup = false;
- $systemConfig->setValues([
+ $this->config->setValues([
'dbuser' => $this->dbUser,
'dbpassword' => $this->dbPassword,
]);
}
// connect to the ownCloud database (dbname=$this->dbname) and check if it needs to be filled
- $this->dbUser = $systemConfig->getValue('dbuser');
- $this->dbPassword = $systemConfig->getValue('dbpassword');
+ $this->dbUser = $this->config->getValue('dbuser');
+ $this->dbPassword = $this->config->getValue('dbpassword');
$connection = $this->connect();
try {
$connection->connect();
}
public function setupDatabase($username) {
- $datadir = \OC::$server->getSystemConfig()->getValue('datadirectory', \OC::$SERVERROOT . '/data');
+ $datadir = $this->config->getValue('datadirectory', \OC::$SERVERROOT . '/data');
//delete the old sqlite database first, might cause infinte loops otherwise
if(file_exists("$datadir/owncloud.db")) {
/**
* check if the current server configuration is suitable for ownCloud
*
- * @param \OCP\IConfig $config
+ * @param \OC\SystemConfig $config
* @return array arrays with error messages and hints
*/
- public static function checkServer(\OCP\IConfig $config) {
+ public static function checkServer(\OC\SystemConfig $config) {
$l = \OC::$server->getL10N('lib');
$errors = array();
- $CONFIG_DATADIRECTORY = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data');
+ $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data');
- if (!self::needUpgrade($config) && $config->getSystemValue('installed', false)) {
+ if (!self::needUpgrade($config) && $config->getValue('installed', false)) {
// this check needs to be done every time
$errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY);
}
}
// Check if there is a writable install folder.
- if ($config->getSystemValue('appstoreenabled', true)) {
+ if ($config->getValue('appstoreenabled', true)) {
if (OC_App::getInstallPath() === null
|| !is_writable(OC_App::getInstallPath())
|| !is_readable(OC_App::getInstallPath())
}
}
// Create root dir.
- if ($config->getSystemValue('installed', false)) {
+ if ($config->getValue('installed', false)) {
if (!is_dir($CONFIG_DATADIRECTORY)) {
$success = @mkdir($CONFIG_DATADIRECTORY);
if ($success) {
* either when the core version is higher or any app requires
* an upgrade.
*
- * @param \OCP\IConfig $config
+ * @param \OC\SystemConfig $config
* @return bool whether the core or any app needs an upgrade
* @throws \OC\HintException When the upgrade from the given version is not allowed
*/
- public static function needUpgrade(\OCP\IConfig $config) {
- if ($config->getSystemValue('installed', false)) {
- $installedVersion = $config->getSystemValue('version', '0.0.0');
+ public static function needUpgrade(\OC\SystemConfig $config) {
+ if ($config->getValue('installed', false)) {
+ $installedVersion = $config->getValue('version', '0.0.0');
$currentVersion = implode('.', \OCP\Util::getVersion());
$versionDiff = version_compare($currentVersion, $installedVersion);
if ($versionDiff > 0) {
return true;
- } else if ($config->getSystemValue('debug', false) && $versionDiff < 0) {
+ } else if ($config->getValue('debug', false) && $versionDiff < 0) {
// downgrade with debug
$installedMajor = explode('.', $installedVersion);
$installedMajor = $installedMajor[0] . '.' . $installedMajor[1];
*/
public static function needUpgrade() {
if (!isset(self::$needUpgradeCache)) {
- self::$needUpgradeCache=\OC_Util::needUpgrade(\OC::$server->getConfig());
+ self::$needUpgradeCache=\OC_Util::needUpgrade(\OC::$server->getSystemConfig());
}
return self::$needUpgradeCache;
}
namespace Test;
use bantu\IniGetWrapper\IniGetWrapper;
-use OCP\IConfig;
+use OC\SystemConfig;
use OCP\IL10N;
use OCP\ILogger;
use OCP\Security\ISecureRandom;
class SetupTest extends \Test\TestCase {
- /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */
+ /** @var SystemConfig | \PHPUnit_Framework_MockObject_MockObject */
protected $config;
/** @var \bantu\IniGetWrapper\IniGetWrapper | \PHPUnit_Framework_MockObject_MockObject */
private $iniWrapper;
protected function setUp() {
parent::setUp();
- $this->config = $this->createMock(IConfig::class);
+ $this->config = $this->createMock(SystemConfig::class);
$this->iniWrapper = $this->createMock(IniGetWrapper::class);
$this->l10n = $this->createMock(IL10N::class);
$this->defaults = $this->createMock(\OC_Defaults::class);
public function testGetSupportedDatabasesWithOneWorking() {
$this->config
->expects($this->once())
- ->method('getSystemValue')
+ ->method('getValue')
->will($this->returnValue(
array('sqlite', 'mysql', 'oci')
));
public function testGetSupportedDatabasesWithNoWorking() {
$this->config
->expects($this->once())
- ->method('getSystemValue')
+ ->method('getValue')
->will($this->returnValue(
array('sqlite', 'mysql', 'oci', 'pgsql')
));
public function testGetSupportedDatabasesWithAllWorking() {
$this->config
->expects($this->once())
- ->method('getSystemValue')
+ ->method('getValue')
->will($this->returnValue(
array('sqlite', 'mysql', 'pgsql', 'oci')
));
public function testGetSupportedDatabaseException() {
$this->config
->expects($this->once())
- ->method('getSystemValue')
+ ->method('getValue')
->will($this->returnValue('NotAnArray'));
$this->setupClass->getSupportedDatabases();
}
/**
* @param array $systemOptions
- * @return \OCP\IConfig | \PHPUnit_Framework_MockObject_MockObject
+ * @return \OC\SystemConfig | \PHPUnit_Framework_MockObject_MockObject
*/
protected function getConfig($systemOptions) {
$systemOptions['datadirectory'] = $this->datadir;
$systemOptions['appstoreenabled'] = false; //it's likely that there is no app folder we can write in
- $config = $this->getMockBuilder('\OCP\IConfig')
+ $config = $this->getMockBuilder('\OC\SystemConfig')
->disableOriginalConstructor()
->getMock();
$config->expects($this->any())
- ->method('getSystemValue')
+ ->method('getValue')
->will($this->returnCallback(function ($key, $default) use ($systemOptions) {
return isset($systemOptions[$key]) ? $systemOptions[$key] : $default;
}));