Use SystemConfig instead of AllConfig for DB stuff

* preparation for followup PRs to clean up the DB bootstrapping

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
Morris Jobke 2017-03-17 16:37:48 -06:00
parent c02527e414
commit edd55b0ea9
No known key found for this signature in database
GPG Key ID: 9CE5ED29E7FCD38A
17 changed files with 84 additions and 77 deletions

View File

@ -23,17 +23,17 @@
*/ */
namespace OC\Core\Command; namespace OC\Core\Command;
use OCP\IConfig; use OC\SystemConfig;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
class Check extends Base { class Check extends Base {
/** /**
* @var IConfig * @var SystemConfig
*/ */
private $config; private $config;
public function __construct(IConfig $config) { public function __construct(SystemConfig $config) {
parent::__construct(); parent::__construct();
$this->config = $config; $this->config = $config;
} }

View File

@ -29,7 +29,7 @@ namespace OC\Core\Command\Maintenance;
use InvalidArgumentException; use InvalidArgumentException;
use OC\Setup; use OC\Setup;
use OCP\IConfig; use OC\SystemConfig;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
@ -40,11 +40,11 @@ use Symfony\Component\Console\Question\Question;
class Install extends Command { class Install extends Command {
/** /**
* @var IConfig * @var SystemConfig
*/ */
private $config; private $config;
public function __construct(IConfig $config) { public function __construct(SystemConfig $config) {
parent::__construct(); parent::__construct();
$this->config = $config; $this->config = $config;
} }

View File

@ -35,7 +35,7 @@
/** @var $application Symfony\Component\Console\Application */ /** @var $application Symfony\Component\Console\Application */
$application->add(new \Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand()); $application->add(new \Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand());
$application->add(new OC\Core\Command\Status); $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(); $infoParser = new \OC\App\InfoParser();
$application->add(new OC\Core\Command\App\CheckCode($infoParser)); $application->add(new OC\Core\Command\App\CheckCode($infoParser));
$application->add(new OC\Core\Command\L10n\CreateJs()); $application->add(new OC\Core\Command\L10n\CreateJs());
@ -83,7 +83,7 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) {
$application->add(new OC\Core\Command\Config\System\SetConfig(\OC::$server->getSystemConfig())); $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\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\Disable(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Encryption\Enable(\OC::$server->getConfig(), \OC::$server->getEncryptionManager())); $application->add(new OC\Core\Command\Encryption\Enable(\OC::$server->getConfig(), \OC::$server->getEncryptionManager()));
@ -149,5 +149,5 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) {
$application->add(new OC\Core\Command\Security\ImportCertificate(\OC::$server->getCertificateManager(null))); $application->add(new OC\Core\Command\Security\ImportCertificate(\OC::$server->getCertificateManager(null)));
$application->add(new OC\Core\Command\Security\RemoveCertificate(\OC::$server->getCertificateManager(null))); $application->add(new OC\Core\Command\Security\RemoveCertificate(\OC::$server->getCertificateManager(null)));
} else { } else {
$application->add(new OC\Core\Command\Maintenance\Install(\OC::$server->getConfig())); $application->add(new OC\Core\Command\Maintenance\Install(\OC::$server->getSystemConfig()));
} }

View File

@ -658,7 +658,7 @@ class OC {
self::performSameSiteCookieProtection(); self::performSameSiteCookieProtection();
if (!defined('OC_CONSOLE')) { if (!defined('OC_CONSOLE')) {
$errors = OC_Util::checkServer(\OC::$server->getConfig()); $errors = OC_Util::checkServer(\OC::$server->getSystemConfig());
if (count($errors) > 0) { if (count($errors) > 0) {
if (self::$CLI) { if (self::$CLI) {
// Convert l10n string into regular string for usage in database // Convert l10n string into regular string for usage in database
@ -911,7 +911,7 @@ class OC {
// Check if Nextcloud is installed or in maintenance (update) mode // Check if Nextcloud is installed or in maintenance (update) mode
if (!$systemConfig->getValue('installed', false)) { if (!$systemConfig->getValue('installed', false)) {
\OC::$server->getSession()->clear(); \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->getL10N('lib'), \OC::$server->getThemingDefaults(), \OC::$server->getLogger(),
\OC::$server->getSecureRandom()); \OC::$server->getSecureRandom());
$controller = new OC\Core\Controller\SetupController($setupHelper); $controller = new OC\Core\Controller\SetupController($setupHelper);

View File

@ -134,7 +134,7 @@ class Application {
} }
if ($input->getFirstArgument() !== 'check') { if ($input->getFirstArgument() !== 'check') {
$errors = \OC_Util::checkServer(\OC::$server->getConfig()); $errors = \OC_Util::checkServer(\OC::$server->getSystemConfig());
if (!empty($errors)) { if (!empty($errors)) {
foreach ($errors as $error) { foreach ($errors as $error) {
$output->writeln((string)$error['error']); $output->writeln((string)$error['error']);

View File

@ -30,7 +30,7 @@ use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Event\Listeners\OracleSessionInit; use Doctrine\DBAL\Event\Listeners\OracleSessionInit;
use Doctrine\DBAL\Event\Listeners\SQLSessionInit; use Doctrine\DBAL\Event\Listeners\SQLSessionInit;
use OCP\IConfig; use OC\SystemConfig;
/** /**
* Takes care of creating and configuring Doctrine connections. * Takes care of creating and configuring Doctrine connections.
@ -67,8 +67,17 @@ class ConnectionFactory {
], ],
]; ];
public function __construct(IConfig $config) { /** @var SystemConfig */
if($config->getSystemValue('mysql.utf8mb4', false)) { 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'; $this->defaultConnectionParams['mysql']['charset'] = 'utf8mb4';
} }
} }
@ -154,23 +163,22 @@ class ConnectionFactory {
/** /**
* Create the connection parameters for the config * Create the connection parameters for the config
* *
* @param \OC\SystemConfig $config
* @return array * @return array
*/ */
public function createConnectionParams($config) { public function createConnectionParams() {
$type = $config->getValue('dbtype', 'sqlite'); $type = $this->config->getValue('dbtype', 'sqlite');
$connectionParams = [ $connectionParams = [
'user' => $config->getValue('dbuser', ''), 'user' => $this->config->getValue('dbuser', ''),
'password' => $config->getValue('dbpassword', ''), 'password' => $this->config->getValue('dbpassword', ''),
]; ];
$name = $config->getValue('dbname', 'owncloud'); $name = $this->config->getValue('dbname', 'owncloud');
if ($this->normalizeType($type) === 'sqlite3') { 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'; $connectionParams['path'] = $dataDir . '/' . $name . '.db';
} else { } else {
$host = $config->getValue('dbhost', ''); $host = $this->config->getValue('dbhost', '');
if (strpos($host, ':')) { if (strpos($host, ':')) {
// Host variable may carry a port or socket. // Host variable may carry a port or socket.
list($host, $portOrSocket) = explode(':', $host, 2); list($host, $portOrSocket) = explode(':', $host, 2);
@ -184,11 +192,11 @@ class ConnectionFactory {
$connectionParams['dbname'] = $name; $connectionParams['dbname'] = $name;
} }
$connectionParams['tablePrefix'] = $config->getValue('dbtableprefix', 'oc_'); $connectionParams['tablePrefix'] = $this->config->getValue('dbtableprefix', 'oc_');
$connectionParams['sqlite.journal_mode'] = $config->getValue('sqlite.journal_mode', 'WAL'); $connectionParams['sqlite.journal_mode'] = $this->config->getValue('sqlite.journal_mode', 'WAL');
//additional driver options, eg. for mysql ssl //additional driver options, eg. for mysql ssl
$driverOptions = $config->getValue('dbdriveroptions', null); $driverOptions = $this->config->getValue('dbdriveroptions', null);
if ($driverOptions) { if ($driverOptions) {
$connectionParams['driverOptions'] = $driverOptions; $connectionParams['driverOptions'] = $driverOptions;
} }

View File

@ -479,12 +479,12 @@ class Server extends ServerContainer implements IServerContainer {
}); });
$this->registerService('DatabaseConnection', function (Server $c) { $this->registerService('DatabaseConnection', function (Server $c) {
$systemConfig = $c->getSystemConfig(); $systemConfig = $c->getSystemConfig();
$factory = new \OC\DB\ConnectionFactory($c->getConfig()); $factory = new \OC\DB\ConnectionFactory($systemConfig);
$type = $systemConfig->getValue('dbtype', 'sqlite'); $type = $systemConfig->getValue('dbtype', 'sqlite');
if (!$factory->isValidType($type)) { if (!$factory->isValidType($type)) {
throw new \OC\DatabaseException('Invalid database type'); throw new \OC\DatabaseException('Invalid database type');
} }
$connectionParams = $factory->createConnectionParams($systemConfig); $connectionParams = $factory->createConnectionParams();
$connection = $factory->getConnection($type, $connectionParams); $connection = $factory->getConnection($type, $connectionParams);
$connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
return $connection; return $connection;

View File

@ -47,7 +47,7 @@ use OCP\ILogger;
use OCP\Security\ISecureRandom; use OCP\Security\ISecureRandom;
class Setup { class Setup {
/** @var \OCP\IConfig */ /** @var SystemConfig */
protected $config; protected $config;
/** @var IniGetWrapper */ /** @var IniGetWrapper */
protected $iniWrapper; protected $iniWrapper;
@ -61,11 +61,11 @@ class Setup {
protected $random; protected $random;
/** /**
* @param IConfig $config * @param SystemConfig $config
* @param IniGetWrapper $iniWrapper * @param IniGetWrapper $iniWrapper
* @param \OC_Defaults $defaults * @param \OC_Defaults $defaults
*/ */
function __construct(IConfig $config, function __construct(SystemConfig $config,
IniGetWrapper $iniWrapper, IniGetWrapper $iniWrapper,
IL10N $l10n, IL10N $l10n,
\OC_Defaults $defaults, \OC_Defaults $defaults,
@ -148,7 +148,7 @@ class Setup {
if ($allowAllDatabases) { if ($allowAllDatabases) {
$configuredDatabases = array_keys($availableDatabases); $configuredDatabases = array_keys($availableDatabases);
} else { } else {
$configuredDatabases = $this->config->getSystemValue('supportedDatabases', $configuredDatabases = $this->config->getValue('supportedDatabases',
array('sqlite', 'mysql', 'pgsql')); array('sqlite', 'mysql', 'pgsql'));
} }
if(!is_array($configuredDatabases)) { if(!is_array($configuredDatabases)) {
@ -187,7 +187,7 @@ class Setup {
public function getSystemInfo($allowAllDatabases = false) { public function getSystemInfo($allowAllDatabases = false) {
$databases = $this->getSupportedDatabases($allowAllDatabases); $databases = $this->getSupportedDatabases($allowAllDatabases);
$dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data'); $dataDir = $this->config->getValue('datadirectory', \OC::$SERVERROOT.'/data');
$errors = array(); $errors = array();
@ -315,7 +315,7 @@ class Setup {
$secret = $this->random->generate(48); $secret = $this->random->generate(48);
//write the config file //write the config file
$this->config->setSystemValues([ $this->config->setValues([
'passwordsalt' => $salt, 'passwordsalt' => $salt,
'secret' => $secret, 'secret' => $secret,
'trusted_domains' => $trustedDomains, 'trusted_domains' => $trustedDomains,
@ -407,11 +407,11 @@ class Setup {
* @return bool True when success, False otherwise * @return bool True when success, False otherwise
*/ */
public static function updateHtaccess() { public static function updateHtaccess() {
$config = \OC::$server->getConfig(); $config = \OC::$server->getSystemConfig();
// For CLI read the value from overwrite.cli.url // For CLI read the value from overwrite.cli.url
if(\OC::$CLI) { if(\OC::$CLI) {
$webRoot = $config->getSystemValue('overwrite.cli.url', ''); $webRoot = $config->getValue('overwrite.cli.url', '');
if($webRoot === '') { if($webRoot === '') {
return false; return false;
} }
@ -436,7 +436,7 @@ class Setup {
$content.= "\nErrorDocument 404 ".$webRoot."/core/templates/404.php"; $content.= "\nErrorDocument 404 ".$webRoot."/core/templates/404.php";
// Add rewrite rules if the RewriteBase is configured // Add rewrite rules if the RewriteBase is configured
$rewriteBase = $config->getSystemValue('htaccess.RewriteBase', ''); $rewriteBase = $config->getValue('htaccess.RewriteBase', '');
if($rewriteBase !== '') { if($rewriteBase !== '') {
$content .= "\n<IfModule mod_rewrite.c>"; $content .= "\n<IfModule mod_rewrite.c>";
$content .= "\n Options -MultiViews"; $content .= "\n Options -MultiViews";

View File

@ -28,7 +28,7 @@ namespace OC\Setup;
use OC\AllConfig; use OC\AllConfig;
use OC\DB\ConnectionFactory; use OC\DB\ConnectionFactory;
use OCP\IConfig; use OC\SystemConfig;
use OCP\IL10N; use OCP\IL10N;
use OCP\ILogger; use OCP\ILogger;
use OCP\Security\ISecureRandom; use OCP\Security\ISecureRandom;
@ -51,14 +51,14 @@ abstract class AbstractDatabase {
protected $dbPort; protected $dbPort;
/** @var string */ /** @var string */
protected $tablePrefix; protected $tablePrefix;
/** @var AllConfig */ /** @var SystemConfig */
protected $config; protected $config;
/** @var ILogger */ /** @var ILogger */
protected $logger; protected $logger;
/** @var ISecureRandom */ /** @var ISecureRandom */
protected $random; 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->trans = $trans;
$this->dbDefinitionFile = $dbDefinitionFile; $this->dbDefinitionFile = $dbDefinitionFile;
$this->config = $config; $this->config = $config;
@ -89,7 +89,7 @@ abstract class AbstractDatabase {
$dbPort = !empty($config['dbport']) ? $config['dbport'] : ''; $dbPort = !empty($config['dbport']) ? $config['dbport'] : '';
$dbTablePrefix = isset($config['dbtableprefix']) ? $config['dbtableprefix'] : 'oc_'; $dbTablePrefix = isset($config['dbtableprefix']) ? $config['dbtableprefix'] : 'oc_';
$this->config->setSystemValues([ $this->config->setValues([
'dbname' => $dbName, 'dbname' => $dbName,
'dbhost' => $dbHost, 'dbhost' => $dbHost,
'dbport' => $dbPort, 'dbport' => $dbPort,
@ -137,7 +137,7 @@ abstract class AbstractDatabase {
$connectionParams = array_merge($connectionParams, $configOverwrite); $connectionParams = array_merge($connectionParams, $configOverwrite);
$cf = new ConnectionFactory($this->config); $cf = new ConnectionFactory($this->config);
return $cf->getConnection($this->config->getSystemValue('dbtype', 'sqlite'), $connectionParams); return $cf->getConnection($this->config->getValue('dbtype', 'sqlite'), $connectionParams);
} }
/** /**

View File

@ -58,7 +58,7 @@ class MySQL extends AbstractDatabase {
$name = $this->dbName; $name = $this->dbName;
$user = $this->dbUser; $user = $this->dbUser;
//we can't use OC_DB functions here because we need to connect as the administrative user. //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;"; $query = "CREATE DATABASE IF NOT EXISTS `$name` CHARACTER SET $characterSet COLLATE ${characterSet}_bin;";
$connection->executeUpdate($query); $connection->executeUpdate($query);
} catch (\Exception $ex) { } catch (\Exception $ex) {
@ -112,7 +112,7 @@ class MySQL extends AbstractDatabase {
private function createSpecificUser($username, $connection) { private function createSpecificUser($username, $connection) {
try { try {
//user already specified in config //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 //we don't have a dbuser specified in config
if ($this->dbUser !== $oldUser) { if ($this->dbUser !== $oldUser) {
@ -157,7 +157,7 @@ class MySQL extends AbstractDatabase {
]); ]);
} }
$this->config->setSystemValues([ $this->config->setValues([
'dbuser' => $this->dbUser, 'dbuser' => $this->dbUser,
'dbpassword' => $this->dbPassword, 'dbpassword' => $this->dbPassword,
]); ]);

View File

@ -45,7 +45,7 @@ class OCI extends AbstractDatabase {
// allow empty hostname for oracle // allow empty hostname for oracle
$this->dbHost = $config['dbhost']; $this->dbHost = $config['dbhost'];
$this->config->setSystemValues([ $this->config->setValues([
'dbhost' => $this->dbHost, 'dbhost' => $this->dbHost,
'dbtablespace' => $this->dbtablespace, 'dbtablespace' => $this->dbtablespace,
]); ]);
@ -124,7 +124,7 @@ class OCI extends AbstractDatabase {
} }
} }
$this->config->setSystemValues([ $this->config->setValues([
'dbuser' => $this->dbUser, 'dbuser' => $this->dbUser,
'dbname' => $this->dbName, 'dbname' => $this->dbName,
'dbpassword' => $this->dbPassword, 'dbpassword' => $this->dbPassword,
@ -139,9 +139,9 @@ class OCI extends AbstractDatabase {
oci_close($connection); oci_close($connection);
// connect to the oracle database (schema=$this->dbuser) an check if the schema needs to be filled // 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->dbname = \OC_Config::getValue('dbname');
$this->dbPassword = $this->config->getSystemValue('dbpassword'); $this->dbPassword = $this->config->getValue('dbpassword');
$e_host = addslashes($this->dbHost); $e_host = addslashes($this->dbHost);
$e_dbname = addslashes($this->dbName); $e_dbname = addslashes($this->dbName);

View File

@ -35,7 +35,6 @@ class PostgreSQL extends AbstractDatabase {
public $dbprettyname = 'PostgreSQL'; public $dbprettyname = 'PostgreSQL';
public function setupDatabase($username) { public function setupDatabase($username) {
$systemConfig = $this->config->getSystemConfig();
try { try {
$connection = $this->connect([ $connection = $this->connect([
'dbname' => 'postgres' 'dbname' => 'postgres'
@ -67,7 +66,7 @@ class PostgreSQL extends AbstractDatabase {
$this->createDBUser($connection); $this->createDBUser($connection);
} }
$systemConfig->setValues([ $this->config->setValues([
'dbuser' => $this->dbUser, 'dbuser' => $this->dbUser,
'dbpassword' => $this->dbPassword, 'dbpassword' => $this->dbPassword,
]); ]);
@ -84,15 +83,15 @@ class PostgreSQL extends AbstractDatabase {
$this->logger->logException($e); $this->logger->logException($e);
$this->logger->warning('Error trying to connect as "postgres", assuming database is setup and tables need to be created'); $this->logger->warning('Error trying to connect as "postgres", assuming database is setup and tables need to be created');
$tablesSetup = false; $tablesSetup = false;
$systemConfig->setValues([ $this->config->setValues([
'dbuser' => $this->dbUser, 'dbuser' => $this->dbUser,
'dbpassword' => $this->dbPassword, 'dbpassword' => $this->dbPassword,
]); ]);
} }
// connect to the ownCloud database (dbname=$this->dbname) and check if it needs to be filled // connect to the ownCloud database (dbname=$this->dbname) and check if it needs to be filled
$this->dbUser = $systemConfig->getValue('dbuser'); $this->dbUser = $this->config->getValue('dbuser');
$this->dbPassword = $systemConfig->getValue('dbpassword'); $this->dbPassword = $this->config->getValue('dbpassword');
$connection = $this->connect(); $connection = $this->connect();
try { try {
$connection->connect(); $connection->connect();

View File

@ -33,7 +33,7 @@ class Sqlite extends AbstractDatabase {
} }
public function setupDatabase($username) { 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 //delete the old sqlite database first, might cause infinte loops otherwise
if(file_exists("$datadir/owncloud.db")) { if(file_exists("$datadir/owncloud.db")) {

View File

@ -631,15 +631,15 @@ class OC_Util {
/** /**
* check if the current server configuration is suitable for ownCloud * 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 * @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'); $l = \OC::$server->getL10N('lib');
$errors = array(); $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 // this check needs to be done every time
$errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY); $errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY);
} }
@ -677,7 +677,7 @@ class OC_Util {
} }
// Check if there is a writable install folder. // Check if there is a writable install folder.
if ($config->getSystemValue('appstoreenabled', true)) { if ($config->getValue('appstoreenabled', true)) {
if (OC_App::getInstallPath() === null if (OC_App::getInstallPath() === null
|| !is_writable(OC_App::getInstallPath()) || !is_writable(OC_App::getInstallPath())
|| !is_readable(OC_App::getInstallPath()) || !is_readable(OC_App::getInstallPath())
@ -692,7 +692,7 @@ class OC_Util {
} }
} }
// Create root dir. // Create root dir.
if ($config->getSystemValue('installed', false)) { if ($config->getValue('installed', false)) {
if (!is_dir($CONFIG_DATADIRECTORY)) { if (!is_dir($CONFIG_DATADIRECTORY)) {
$success = @mkdir($CONFIG_DATADIRECTORY); $success = @mkdir($CONFIG_DATADIRECTORY);
if ($success) { if ($success) {
@ -1401,18 +1401,18 @@ class OC_Util {
* either when the core version is higher or any app requires * either when the core version is higher or any app requires
* an upgrade. * an upgrade.
* *
* @param \OCP\IConfig $config * @param \OC\SystemConfig $config
* @return bool whether the core or any app needs an upgrade * @return bool whether the core or any app needs an upgrade
* @throws \OC\HintException When the upgrade from the given version is not allowed * @throws \OC\HintException When the upgrade from the given version is not allowed
*/ */
public static function needUpgrade(\OCP\IConfig $config) { public static function needUpgrade(\OC\SystemConfig $config) {
if ($config->getSystemValue('installed', false)) { if ($config->getValue('installed', false)) {
$installedVersion = $config->getSystemValue('version', '0.0.0'); $installedVersion = $config->getValue('version', '0.0.0');
$currentVersion = implode('.', \OCP\Util::getVersion()); $currentVersion = implode('.', \OCP\Util::getVersion());
$versionDiff = version_compare($currentVersion, $installedVersion); $versionDiff = version_compare($currentVersion, $installedVersion);
if ($versionDiff > 0) { if ($versionDiff > 0) {
return true; return true;
} else if ($config->getSystemValue('debug', false) && $versionDiff < 0) { } else if ($config->getValue('debug', false) && $versionDiff < 0) {
// downgrade with debug // downgrade with debug
$installedMajor = explode('.', $installedVersion); $installedMajor = explode('.', $installedVersion);
$installedMajor = $installedMajor[0] . '.' . $installedMajor[1]; $installedMajor = $installedMajor[0] . '.' . $installedMajor[1];

View File

@ -703,7 +703,7 @@ class Util {
*/ */
public static function needUpgrade() { public static function needUpgrade() {
if (!isset(self::$needUpgradeCache)) { if (!isset(self::$needUpgradeCache)) {
self::$needUpgradeCache=\OC_Util::needUpgrade(\OC::$server->getConfig()); self::$needUpgradeCache=\OC_Util::needUpgrade(\OC::$server->getSystemConfig());
} }
return self::$needUpgradeCache; return self::$needUpgradeCache;
} }

View File

@ -9,14 +9,14 @@
namespace Test; namespace Test;
use bantu\IniGetWrapper\IniGetWrapper; use bantu\IniGetWrapper\IniGetWrapper;
use OCP\IConfig; use OC\SystemConfig;
use OCP\IL10N; use OCP\IL10N;
use OCP\ILogger; use OCP\ILogger;
use OCP\Security\ISecureRandom; use OCP\Security\ISecureRandom;
class SetupTest extends \Test\TestCase { class SetupTest extends \Test\TestCase {
/** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */ /** @var SystemConfig | \PHPUnit_Framework_MockObject_MockObject */
protected $config; protected $config;
/** @var \bantu\IniGetWrapper\IniGetWrapper | \PHPUnit_Framework_MockObject_MockObject */ /** @var \bantu\IniGetWrapper\IniGetWrapper | \PHPUnit_Framework_MockObject_MockObject */
private $iniWrapper; private $iniWrapper;
@ -34,7 +34,7 @@ class SetupTest extends \Test\TestCase {
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
$this->config = $this->createMock(IConfig::class); $this->config = $this->createMock(SystemConfig::class);
$this->iniWrapper = $this->createMock(IniGetWrapper::class); $this->iniWrapper = $this->createMock(IniGetWrapper::class);
$this->l10n = $this->createMock(IL10N::class); $this->l10n = $this->createMock(IL10N::class);
$this->defaults = $this->createMock(\OC_Defaults::class); $this->defaults = $this->createMock(\OC_Defaults::class);
@ -49,7 +49,7 @@ class SetupTest extends \Test\TestCase {
public function testGetSupportedDatabasesWithOneWorking() { public function testGetSupportedDatabasesWithOneWorking() {
$this->config $this->config
->expects($this->once()) ->expects($this->once())
->method('getSystemValue') ->method('getValue')
->will($this->returnValue( ->will($this->returnValue(
array('sqlite', 'mysql', 'oci') array('sqlite', 'mysql', 'oci')
)); ));
@ -72,7 +72,7 @@ class SetupTest extends \Test\TestCase {
public function testGetSupportedDatabasesWithNoWorking() { public function testGetSupportedDatabasesWithNoWorking() {
$this->config $this->config
->expects($this->once()) ->expects($this->once())
->method('getSystemValue') ->method('getValue')
->will($this->returnValue( ->will($this->returnValue(
array('sqlite', 'mysql', 'oci', 'pgsql') array('sqlite', 'mysql', 'oci', 'pgsql')
)); ));
@ -92,7 +92,7 @@ class SetupTest extends \Test\TestCase {
public function testGetSupportedDatabasesWithAllWorking() { public function testGetSupportedDatabasesWithAllWorking() {
$this->config $this->config
->expects($this->once()) ->expects($this->once())
->method('getSystemValue') ->method('getValue')
->will($this->returnValue( ->will($this->returnValue(
array('sqlite', 'mysql', 'pgsql', 'oci') array('sqlite', 'mysql', 'pgsql', 'oci')
)); ));
@ -121,7 +121,7 @@ class SetupTest extends \Test\TestCase {
public function testGetSupportedDatabaseException() { public function testGetSupportedDatabaseException() {
$this->config $this->config
->expects($this->once()) ->expects($this->once())
->method('getSystemValue') ->method('getValue')
->will($this->returnValue('NotAnArray')); ->will($this->returnValue('NotAnArray'));
$this->setupClass->getSupportedDatabases(); $this->setupClass->getSupportedDatabases();
} }

View File

@ -19,17 +19,17 @@ class UtilCheckServerTest extends \Test\TestCase {
/** /**
* @param array $systemOptions * @param array $systemOptions
* @return \OCP\IConfig | \PHPUnit_Framework_MockObject_MockObject * @return \OC\SystemConfig | \PHPUnit_Framework_MockObject_MockObject
*/ */
protected function getConfig($systemOptions) { protected function getConfig($systemOptions) {
$systemOptions['datadirectory'] = $this->datadir; $systemOptions['datadirectory'] = $this->datadir;
$systemOptions['appstoreenabled'] = false; //it's likely that there is no app folder we can write in $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() ->disableOriginalConstructor()
->getMock(); ->getMock();
$config->expects($this->any()) $config->expects($this->any())
->method('getSystemValue') ->method('getValue')
->will($this->returnCallback(function ($key, $default) use ($systemOptions) { ->will($this->returnCallback(function ($key, $default) use ($systemOptions) {
return isset($systemOptions[$key]) ? $systemOptions[$key] : $default; return isset($systemOptions[$key]) ? $systemOptions[$key] : $default;
})); }));