Sfoglia il codice sorgente

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>
tags/v12.0.0beta1
Morris Jobke 7 anni fa
parent
commit
edd55b0ea9
Nessun account collegato all'indirizzo email del committer

+ 3
- 3
core/Command/Check.php Vedi File

@@ -23,17 +23,17 @@
*/
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;
}

+ 3
- 3
core/Command/Maintenance/Install.php Vedi File

@@ -29,7 +29,7 @@ namespace OC\Core\Command\Maintenance;

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;
@@ -40,11 +40,11 @@ use Symfony\Component\Console\Question\Question;
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;
}

+ 3
- 3
core/register_command.php Vedi File

@@ -35,7 +35,7 @@
/** @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());
@@ -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\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()));
@@ -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\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()));
}

+ 2
- 2
lib/base.php Vedi File

@@ -658,7 +658,7 @@ class OC {
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
@@ -911,7 +911,7 @@ class OC {
// 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);

+ 1
- 1
lib/private/Console/Application.php Vedi File

@@ -134,7 +134,7 @@ class Application {
}

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']);

+ 22
- 14
lib/private/DB/ConnectionFactory.php Vedi File

@@ -30,7 +30,7 @@ use Doctrine\DBAL\Configuration;
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.
@@ -67,8 +67,17 @@ class ConnectionFactory {
],
];

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';
}
}
@@ -154,23 +163,22 @@ class ConnectionFactory {
/**
* 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);
@@ -184,11 +192,11 @@ class ConnectionFactory {
$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;
}

+ 2
- 2
lib/private/Server.php Vedi File

@@ -479,12 +479,12 @@ class Server extends ServerContainer implements IServerContainer {
});
$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;

+ 9
- 9
lib/private/Setup.php Vedi File

@@ -47,7 +47,7 @@ use OCP\ILogger;
use OCP\Security\ISecureRandom;

class Setup {
/** @var \OCP\IConfig */
/** @var SystemConfig */
protected $config;
/** @var IniGetWrapper */
protected $iniWrapper;
@@ -61,11 +61,11 @@ class Setup {
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,
@@ -148,7 +148,7 @@ class Setup {
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)) {
@@ -187,7 +187,7 @@ class Setup {
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();

@@ -315,7 +315,7 @@ class Setup {
$secret = $this->random->generate(48);

//write the config file
$this->config->setSystemValues([
$this->config->setValues([
'passwordsalt' => $salt,
'secret' => $secret,
'trusted_domains' => $trustedDomains,
@@ -407,11 +407,11 @@ class Setup {
* @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;
}
@@ -436,7 +436,7 @@ class Setup {
$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";

+ 5
- 5
lib/private/Setup/AbstractDatabase.php Vedi File

@@ -28,7 +28,7 @@ namespace OC\Setup;

use OC\AllConfig;
use OC\DB\ConnectionFactory;
use OCP\IConfig;
use OC\SystemConfig;
use OCP\IL10N;
use OCP\ILogger;
use OCP\Security\ISecureRandom;
@@ -51,14 +51,14 @@ abstract class AbstractDatabase {
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;
@@ -89,7 +89,7 @@ abstract class AbstractDatabase {
$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,
@@ -137,7 +137,7 @@ abstract class AbstractDatabase {

$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);
}

/**

+ 3
- 3
lib/private/Setup/MySQL.php Vedi File

@@ -58,7 +58,7 @@ class MySQL extends AbstractDatabase {
$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) {
@@ -112,7 +112,7 @@ class MySQL extends AbstractDatabase {
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) {
@@ -157,7 +157,7 @@ class MySQL extends AbstractDatabase {
]);
}

$this->config->setSystemValues([
$this->config->setValues([
'dbuser' => $this->dbUser,
'dbpassword' => $this->dbPassword,
]);

+ 4
- 4
lib/private/Setup/OCI.php Vedi File

@@ -45,7 +45,7 @@ class OCI extends AbstractDatabase {
// allow empty hostname for oracle
$this->dbHost = $config['dbhost'];

$this->config->setSystemValues([
$this->config->setValues([
'dbhost' => $this->dbHost,
'dbtablespace' => $this->dbtablespace,
]);
@@ -124,7 +124,7 @@ class OCI extends AbstractDatabase {
}
}

$this->config->setSystemValues([
$this->config->setValues([
'dbuser' => $this->dbUser,
'dbname' => $this->dbName,
'dbpassword' => $this->dbPassword,
@@ -139,9 +139,9 @@ class OCI extends AbstractDatabase {
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);

+ 4
- 5
lib/private/Setup/PostgreSQL.php Vedi File

@@ -35,7 +35,6 @@ class PostgreSQL extends AbstractDatabase {
public $dbprettyname = 'PostgreSQL';

public function setupDatabase($username) {
$systemConfig = $this->config->getSystemConfig();
try {
$connection = $this->connect([
'dbname' => 'postgres'
@@ -67,7 +66,7 @@ class PostgreSQL extends AbstractDatabase {
$this->createDBUser($connection);
}

$systemConfig->setValues([
$this->config->setValues([
'dbuser' => $this->dbUser,
'dbpassword' => $this->dbPassword,
]);
@@ -84,15 +83,15 @@ class PostgreSQL extends AbstractDatabase {
$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();

+ 1
- 1
lib/private/Setup/Sqlite.php Vedi File

@@ -33,7 +33,7 @@ class Sqlite extends AbstractDatabase {
}

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")) {

+ 11
- 11
lib/private/legacy/util.php Vedi File

@@ -631,15 +631,15 @@ class OC_Util {
/**
* 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);
}
@@ -677,7 +677,7 @@ class OC_Util {
}

// 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())
@@ -692,7 +692,7 @@ class OC_Util {
}
}
// Create root dir.
if ($config->getSystemValue('installed', false)) {
if ($config->getValue('installed', false)) {
if (!is_dir($CONFIG_DATADIRECTORY)) {
$success = @mkdir($CONFIG_DATADIRECTORY);
if ($success) {
@@ -1401,18 +1401,18 @@ class OC_Util {
* 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];

+ 1
- 1
lib/public/Util.php Vedi File

@@ -703,7 +703,7 @@ class Util {
*/
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;
}

+ 7
- 7
tests/lib/SetupTest.php Vedi File

@@ -9,14 +9,14 @@
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;
@@ -34,7 +34,7 @@ class SetupTest extends \Test\TestCase {
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);
@@ -49,7 +49,7 @@ class SetupTest extends \Test\TestCase {
public function testGetSupportedDatabasesWithOneWorking() {
$this->config
->expects($this->once())
->method('getSystemValue')
->method('getValue')
->will($this->returnValue(
array('sqlite', 'mysql', 'oci')
));
@@ -72,7 +72,7 @@ class SetupTest extends \Test\TestCase {
public function testGetSupportedDatabasesWithNoWorking() {
$this->config
->expects($this->once())
->method('getSystemValue')
->method('getValue')
->will($this->returnValue(
array('sqlite', 'mysql', 'oci', 'pgsql')
));
@@ -92,7 +92,7 @@ class SetupTest extends \Test\TestCase {
public function testGetSupportedDatabasesWithAllWorking() {
$this->config
->expects($this->once())
->method('getSystemValue')
->method('getValue')
->will($this->returnValue(
array('sqlite', 'mysql', 'pgsql', 'oci')
));
@@ -121,7 +121,7 @@ class SetupTest extends \Test\TestCase {
public function testGetSupportedDatabaseException() {
$this->config
->expects($this->once())
->method('getSystemValue')
->method('getValue')
->will($this->returnValue('NotAnArray'));
$this->setupClass->getSupportedDatabases();
}

+ 3
- 3
tests/lib/UtilCheckServerTest.php Vedi File

@@ -19,17 +19,17 @@ class UtilCheckServerTest extends \Test\TestCase {

/**
* @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;
}));

Loading…
Annulla
Salva