Use setConfigs() instead of calling setConfig() multiple times
This commit is contained in:
parent
c61e9f3912
commit
039397bd31
|
@ -289,10 +289,12 @@ class ConvertType extends Command {
|
||||||
$dbhost .= ':'.$input->getOption('port');
|
$dbhost .= ':'.$input->getOption('port');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->config->setSystemValue('dbtype', $type);
|
$this->config->setSystemValues([
|
||||||
$this->config->setSystemValue('dbname', $dbname);
|
'dbtype' => $type,
|
||||||
$this->config->setSystemValue('dbhost', $dbhost);
|
'dbname' => $dbname,
|
||||||
$this->config->setSystemValue('dbuser', $username);
|
'dbhost' => $dbhost,
|
||||||
$this->config->setSystemValue('dbpassword', $password);
|
'dbuser' => $username,
|
||||||
|
'dbpassword' => $password,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,18 +176,19 @@ class OC_Setup {
|
||||||
|
|
||||||
//generate a random salt that is used to salt the local user passwords
|
//generate a random salt that is used to salt the local user passwords
|
||||||
$salt = \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate(30);
|
$salt = \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate(30);
|
||||||
\OC::$server->getConfig()->setSystemValue('passwordsalt', $salt);
|
|
||||||
|
|
||||||
// generate a secret
|
// generate a secret
|
||||||
$secret = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(48);
|
$secret = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(48);
|
||||||
\OC::$server->getConfig()->setSystemValue('secret', $secret);
|
|
||||||
|
|
||||||
//write the config file
|
//write the config file
|
||||||
\OC::$server->getConfig()->setSystemValue('trusted_domains', $trustedDomains);
|
\OC::$server->getConfig()->setSystemValues([
|
||||||
\OC::$server->getConfig()->setSystemValue('datadirectory', $dataDir);
|
'passwordsalt' => $salt,
|
||||||
\OC::$server->getConfig()->setSystemValue('overwrite.cli.url', \OC_Request::serverProtocol() . '://' . \OC_Request::serverHost() . OC::$WEBROOT);
|
'secret' => $secret,
|
||||||
\OC::$server->getConfig()->setSystemValue('dbtype', $dbType);
|
'trusted_domains' => $trustedDomains,
|
||||||
\OC::$server->getConfig()->setSystemValue('version', implode('.', OC_Util::getVersion()));
|
'datadirectory' => $dataDir,
|
||||||
|
'overwrite.cli.url' => \OC_Request::serverProtocol() . '://' . \OC_Request::serverHost() . OC::$WEBROOT,
|
||||||
|
'dbtype' => $dbType,
|
||||||
|
'version' => implode('.', OC_Util::getVersion()),
|
||||||
|
]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$dbSetup->initialize($options);
|
$dbSetup->initialize($options);
|
||||||
|
|
|
@ -41,9 +41,11 @@ abstract class AbstractDatabase {
|
||||||
$dbhost = !empty($config['dbhost']) ? $config['dbhost'] : 'localhost';
|
$dbhost = !empty($config['dbhost']) ? $config['dbhost'] : 'localhost';
|
||||||
$dbtableprefix = isset($config['dbtableprefix']) ? $config['dbtableprefix'] : 'oc_';
|
$dbtableprefix = isset($config['dbtableprefix']) ? $config['dbtableprefix'] : 'oc_';
|
||||||
|
|
||||||
\OC_Config::setValue('dbname', $dbname);
|
\OC_Config::setValues([
|
||||||
\OC_Config::setValue('dbhost', $dbhost);
|
'dbname' => $dbname,
|
||||||
\OC_Config::setValue('dbtableprefix', $dbtableprefix);
|
'dbhost' => $dbhost,
|
||||||
|
'dbtableprefix' => $dbtableprefix,
|
||||||
|
]);
|
||||||
|
|
||||||
$this->dbuser = $dbuser;
|
$this->dbuser = $dbuser;
|
||||||
$this->dbpassword = $dbpass;
|
$this->dbpassword = $dbpass;
|
||||||
|
|
|
@ -21,8 +21,10 @@ class MSSQL extends AbstractDatabase {
|
||||||
$this->trans->t('You need to enter either an existing account or the administrator.'));
|
$this->trans->t('You need to enter either an existing account or the administrator.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
\OC_Config::setValue('dbuser', $this->dbuser);
|
\OC_Config::setValues([
|
||||||
\OC_Config::setValue('dbpassword', $this->dbpassword);
|
'dbuser' => $this->dbuser,
|
||||||
|
'dbpassword' => $this->dbpassword,
|
||||||
|
]);
|
||||||
|
|
||||||
$this->createDBLogin($masterConnection);
|
$this->createDBLogin($masterConnection);
|
||||||
|
|
||||||
|
|
|
@ -51,8 +51,10 @@ class MySQL extends AbstractDatabase {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
\OC_Config::setValue('dbuser', $this->dbuser);
|
\OC_Config::setValues([
|
||||||
\OC_Config::setValue('dbpassword', $this->dbpassword);
|
'dbuser' => $this->dbuser,
|
||||||
|
'dbpassword' => $this->dbpassword,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
//create the database
|
//create the database
|
||||||
|
|
|
@ -16,8 +16,11 @@ class OCI extends AbstractDatabase {
|
||||||
}
|
}
|
||||||
// allow empty hostname for oracle
|
// allow empty hostname for oracle
|
||||||
$this->dbhost = $config['dbhost'];
|
$this->dbhost = $config['dbhost'];
|
||||||
\OC_Config::setValue('dbhost', $this->dbhost);
|
|
||||||
\OC_Config::setValue('dbtablespace', $this->dbtablespace);
|
\OC_Config::setValues([
|
||||||
|
'dbhost' => $this->dbhost,
|
||||||
|
'dbtablespace' => $this->dbtablespace,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validate($config) {
|
public function validate($config) {
|
||||||
|
@ -72,8 +75,8 @@ class OCI extends AbstractDatabase {
|
||||||
$result = oci_execute($stmt);
|
$result = oci_execute($stmt);
|
||||||
if($result) {
|
if($result) {
|
||||||
$row = oci_fetch_row($stmt);
|
$row = oci_fetch_row($stmt);
|
||||||
}
|
|
||||||
if($result and $row[0] > 0) {
|
if ($row[0] > 0) {
|
||||||
//use the admin login data for the new database user
|
//use the admin login data for the new database user
|
||||||
|
|
||||||
//add prefix to the oracle user name to prevent collisions
|
//add prefix to the oracle user name to prevent collisions
|
||||||
|
@ -87,22 +90,17 @@ class OCI extends AbstractDatabase {
|
||||||
$this->dbpassword=substr($this->dbpassword, 0, 30);
|
$this->dbpassword=substr($this->dbpassword, 0, 30);
|
||||||
|
|
||||||
$this->createDBUser($connection);
|
$this->createDBUser($connection);
|
||||||
|
|
||||||
\OC_Config::setValue('dbuser', $this->dbuser);
|
|
||||||
\OC_Config::setValue('dbname', $this->dbuser);
|
|
||||||
\OC_Config::setValue('dbpassword', $this->dbpassword);
|
|
||||||
|
|
||||||
//create the database not necessary, oracle implies user = schema
|
|
||||||
//$this->createDatabase($this->dbname, $this->dbuser, $connection);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
\OC_Config::setValue('dbuser', $this->dbuser);
|
|
||||||
\OC_Config::setValue('dbname', $this->dbname);
|
|
||||||
\OC_Config::setValue('dbpassword', $this->dbpassword);
|
|
||||||
|
|
||||||
//create the database not necessary, oracle implies user = schema
|
|
||||||
//$this->createDatabase($this->dbname, $this->dbuser, $connection);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
\OC_Config::setValues([
|
||||||
|
'dbuser' => $this->dbuser,
|
||||||
|
'dbname' => $this->dbname,
|
||||||
|
'dbpassword' => $this->dbpassword,
|
||||||
|
]);
|
||||||
|
|
||||||
|
//create the database not necessary, oracle implies user = schema
|
||||||
|
//$this->createDatabase($this->dbname, $this->dbuser, $connection);
|
||||||
|
|
||||||
//FIXME check tablespace exists: select * from user_tablespaces
|
//FIXME check tablespace exists: select * from user_tablespaces
|
||||||
|
|
||||||
|
|
|
@ -43,20 +43,15 @@ class PostgreSQL extends AbstractDatabase {
|
||||||
$this->dbpassword=\OC_Util::generateRandomBytes(30);
|
$this->dbpassword=\OC_Util::generateRandomBytes(30);
|
||||||
|
|
||||||
$this->createDBUser($connection);
|
$this->createDBUser($connection);
|
||||||
|
}
|
||||||
|
|
||||||
\OC_Config::setValue('dbuser', $this->dbuser);
|
\OC_Config::setValues([
|
||||||
\OC_Config::setValue('dbpassword', $this->dbpassword);
|
'dbuser' => $this->dbuser,
|
||||||
|
'dbpassword' => $this->dbpassword,
|
||||||
|
]);
|
||||||
|
|
||||||
//create the database
|
//create the database
|
||||||
$this->createDatabase($connection);
|
$this->createDatabase($connection);
|
||||||
}
|
|
||||||
else {
|
|
||||||
\OC_Config::setValue('dbuser', $this->dbuser);
|
|
||||||
\OC_Config::setValue('dbpassword', $this->dbpassword);
|
|
||||||
|
|
||||||
//create the database
|
|
||||||
$this->createDatabase($connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
// the connection to dbname=postgres is not needed anymore
|
// the connection to dbname=postgres is not needed anymore
|
||||||
pg_close($connection);
|
pg_close($connection);
|
||||||
|
|
|
@ -84,20 +84,19 @@ class MailSettingsController extends Controller {
|
||||||
$mail_smtpport) {
|
$mail_smtpport) {
|
||||||
|
|
||||||
$params = get_defined_vars();
|
$params = get_defined_vars();
|
||||||
|
$configs = [];
|
||||||
foreach($params as $key => $value) {
|
foreach($params as $key => $value) {
|
||||||
if(empty($value)) {
|
$configs[$key] = (empty($value)) ? null : $value;
|
||||||
$this->config->deleteSystemValue($key);
|
|
||||||
} else {
|
|
||||||
$this->config->setSystemValue($key, $value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete passwords from config in case no auth is specified
|
// Delete passwords from config in case no auth is specified
|
||||||
if ($params['mail_smtpauth'] !== 1) {
|
if ($params['mail_smtpauth'] !== 1) {
|
||||||
$this->config->deleteSystemValue('mail_smtpname');
|
$configs['mail_smtpname'] = null;
|
||||||
$this->config->deleteSystemValue('mail_smtppassword');
|
$configs['mail_smtppassword'] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->config->setSystemValues($configs);
|
||||||
|
|
||||||
return array('data' =>
|
return array('data' =>
|
||||||
array('message' =>
|
array('message' =>
|
||||||
(string) $this->l10n->t('Saved')
|
(string) $this->l10n->t('Saved')
|
||||||
|
@ -113,8 +112,10 @@ class MailSettingsController extends Controller {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function storeCredentials($mail_smtpname, $mail_smtppassword) {
|
public function storeCredentials($mail_smtpname, $mail_smtppassword) {
|
||||||
$this->config->setSystemValue('mail_smtpname', $mail_smtpname);
|
$this->config->setSystemValues([
|
||||||
$this->config->setSystemValue('mail_smtppassword', $mail_smtppassword);
|
'mail_smtpname' => $mail_smtpname,
|
||||||
|
'mail_smtppassword' => $mail_smtppassword,
|
||||||
|
]);
|
||||||
|
|
||||||
return array('data' =>
|
return array('data' =>
|
||||||
array('message' =>
|
array('message' =>
|
||||||
|
|
|
@ -69,26 +69,37 @@ class MailSettingsControllerTest extends \Test\TestCase {
|
||||||
);
|
);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$this->container['Config']
|
/** @var \PHPUnit_Framework_MockObject_MockObject $config */
|
||||||
->expects($this->exactly(15))
|
$config = $this->container['Config'];
|
||||||
->method('setSystemValue');
|
$config->expects($this->exactly(2))
|
||||||
|
->method('setSystemValues');
|
||||||
/**
|
/**
|
||||||
* FIXME: Use the following block once Jenkins uses PHPUnit >= 4.1
|
* FIXME: Use the following block once Jenkins uses PHPUnit >= 4.1
|
||||||
*/
|
|
||||||
/*
|
|
||||||
$this->container['Config']
|
|
||||||
->expects($this->exactly(3))
|
|
||||||
->method('deleteSystemValue')
|
|
||||||
->withConsecutive(
|
->withConsecutive(
|
||||||
array($this->equalTo('mail_smtpauth')),
|
[[
|
||||||
array($this->equalTo('mail_smtpname')),
|
'mail_domain' => 'owncloud.com',
|
||||||
array($this->equalTo('mail_smtppassword'))
|
'mail_from_address' => 'demo@owncloud.com',
|
||||||
|
'mail_smtpmode' => 'smtp',
|
||||||
|
'mail_smtpsecure' => 'ssl',
|
||||||
|
'mail_smtphost' => 'mx.owncloud.org',
|
||||||
|
'mail_smtpauthtype' => 'NTLM',
|
||||||
|
'mail_smtpauth' => 1,
|
||||||
|
'mail_smtpport' => '25',
|
||||||
|
]],
|
||||||
|
[[
|
||||||
|
'mail_domain' => 'owncloud.com',
|
||||||
|
'mail_from_address' => 'demo@owncloud.com',
|
||||||
|
'mail_smtpmode' => 'smtp',
|
||||||
|
'mail_smtpsecure' => 'ssl',
|
||||||
|
'mail_smtphost' => 'mx.owncloud.org',
|
||||||
|
'mail_smtpauthtype' => 'NTLM',
|
||||||
|
'mail_smtpauth' => null,
|
||||||
|
'mail_smtpport' => '25',
|
||||||
|
'mail_smtpname' => null,
|
||||||
|
'mail_smtppassword' => null,
|
||||||
|
]]
|
||||||
);
|
);
|
||||||
*/
|
*/
|
||||||
$this->container['Config']
|
|
||||||
->expects($this->exactly(3))
|
|
||||||
->method('deleteSystemValue');
|
|
||||||
|
|
||||||
// With authentication
|
// With authentication
|
||||||
$response = $this->container['MailSettingsController']->setMailSettings(
|
$response = $this->container['MailSettingsController']->setMailSettings(
|
||||||
|
@ -126,21 +137,13 @@ class MailSettingsControllerTest extends \Test\TestCase {
|
||||||
->method('t')
|
->method('t')
|
||||||
->will($this->returnValue('Saved'));
|
->will($this->returnValue('Saved'));
|
||||||
|
|
||||||
/**
|
|
||||||
* FIXME: Use this block once Jenkins uses PHPUnit >= 4.1
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
$this->container['Config']
|
$this->container['Config']
|
||||||
->expects($this->exactly(2))
|
->expects($this->once())
|
||||||
->method('setSystemValue')
|
->method('setSystemValues')
|
||||||
->withConsecutive(
|
->with([
|
||||||
array($this->equalTo('mail_smtpname'), $this->equalTo('UsernameToStore')),
|
'mail_smtpname' => 'UsernameToStore',
|
||||||
array($this->equalTo('mail_smtppassword'), $this->equalTo('PasswordToStore'))
|
'mail_smtppassword' => 'PasswordToStore',
|
||||||
);
|
]);
|
||||||
*/
|
|
||||||
$this->container['Config']
|
|
||||||
->expects($this->exactly(2))
|
|
||||||
->method('setSystemValue');
|
|
||||||
|
|
||||||
$response = $this->container['MailSettingsController']->storeCredentials('UsernameToStore', 'PasswordToStore');
|
$response = $this->container['MailSettingsController']->storeCredentials('UsernameToStore', 'PasswordToStore');
|
||||||
$expectedResponse = array('data' => array('message' =>'Saved'), 'status' => 'success');
|
$expectedResponse = array('data' => array('message' =>'Saved'), 'status' => 'success');
|
||||||
|
|
Loading…
Reference in New Issue