]> source.dussan.org Git - nextcloud-server.git/commitdiff
Use setConfigs() instead of calling setConfig() multiple times
authorJoas Schilling <nickvergessen@gmx.de>
Fri, 23 Jan 2015 10:13:47 +0000 (11:13 +0100)
committerJoas Schilling <nickvergessen@gmx.de>
Fri, 23 Jan 2015 13:52:21 +0000 (14:52 +0100)
core/command/db/converttype.php
lib/private/setup.php
lib/private/setup/abstractdatabase.php
lib/private/setup/mssql.php
lib/private/setup/mysql.php
lib/private/setup/oci.php
lib/private/setup/postgresql.php
settings/controller/mailsettingscontroller.php
tests/settings/controller/mailsettingscontrollertest.php

index 9d03b705d12734cb413430c9a58e09cf2d2613a4..cbce1c371019f0c741aa66cadf104201931db701 100644 (file)
@@ -289,10 +289,12 @@ class ConvertType extends Command {
                        $dbhost .= ':'.$input->getOption('port');
                }
 
-               $this->config->setSystemValue('dbtype', $type);
-               $this->config->setSystemValue('dbname', $dbname);
-               $this->config->setSystemValue('dbhost', $dbhost);
-               $this->config->setSystemValue('dbuser', $username);
-               $this->config->setSystemValue('dbpassword', $password);
+               $this->config->setSystemValues([
+                       'dbtype'                => $type,
+                       'dbname'                => $dbname,
+                       'dbhost'                => $dbhost,
+                       'dbuser'                => $username,
+                       'dbpassword'    => $password,
+               ]);
        }
 }
index b9ba8d906c2339346f7f08a608939b2041fef60a..e5f84d4c02af3b1412bd49c4791e266c6b4759d3 100644 (file)
@@ -176,18 +176,19 @@ class OC_Setup {
 
                //generate a random salt that is used to salt the local user passwords
                $salt = \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate(30);
-               \OC::$server->getConfig()->setSystemValue('passwordsalt', $salt);
-
                // generate a secret
                $secret = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(48);
-               \OC::$server->getConfig()->setSystemValue('secret', $secret);
 
                //write the config file
-               \OC::$server->getConfig()->setSystemValue('trusted_domains', $trustedDomains);
-               \OC::$server->getConfig()->setSystemValue('datadirectory', $dataDir);
-               \OC::$server->getConfig()->setSystemValue('overwrite.cli.url', \OC_Request::serverProtocol() . '://' . \OC_Request::serverHost() . OC::$WEBROOT);
-               \OC::$server->getConfig()->setSystemValue('dbtype', $dbType);
-               \OC::$server->getConfig()->setSystemValue('version', implode('.', OC_Util::getVersion()));
+               \OC::$server->getConfig()->setSystemValues([
+                       'passwordsalt'          => $salt,
+                       'secret'                        => $secret,
+                       'trusted_domains'       => $trustedDomains,
+                       'datadirectory'         => $dataDir,
+                       'overwrite.cli.url'     => \OC_Request::serverProtocol() . '://' . \OC_Request::serverHost() . OC::$WEBROOT,
+                       'dbtype'                        => $dbType,
+                       'version'                       => implode('.', OC_Util::getVersion()),
+               ]);
 
                try {
                        $dbSetup->initialize($options);
index 84625a217ee974968479c13feb6c54fb027d4812..e421efe80287c7897fe6755d943c3a11c4b62412 100644 (file)
@@ -41,9 +41,11 @@ abstract class AbstractDatabase {
                $dbhost = !empty($config['dbhost']) ? $config['dbhost'] : 'localhost';
                $dbtableprefix = isset($config['dbtableprefix']) ? $config['dbtableprefix'] : 'oc_';
 
-               \OC_Config::setValue('dbname', $dbname);
-               \OC_Config::setValue('dbhost', $dbhost);
-               \OC_Config::setValue('dbtableprefix', $dbtableprefix);
+               \OC_Config::setValues([
+                       'dbname'                => $dbname,
+                       'dbhost'                => $dbhost,
+                       'dbtableprefix' => $dbtableprefix,
+               ]);
 
                $this->dbuser = $dbuser;
                $this->dbpassword = $dbpass;
index 5143545b76ffdbd11bdaa9e138631ecd4815b74e..f1699c36f9607c87ccf8773226a3b9c3fe26fdc5 100644 (file)
@@ -21,8 +21,10 @@ class MSSQL extends AbstractDatabase {
                                        $this->trans->t('You need to enter either an existing account or the administrator.'));
                }
 
-               \OC_Config::setValue('dbuser', $this->dbuser);
-               \OC_Config::setValue('dbpassword', $this->dbpassword);
+               \OC_Config::setValues([
+                       'dbuser'                => $this->dbuser,
+                       'dbpassword'    => $this->dbpassword,
+               ]);
 
                $this->createDBLogin($masterConnection);
 
index 8f8d86d388ce2963678ac973fb530e4547a14f15..97f75e2f676026432dc0bc6afcfbed1e1d5978e2 100644 (file)
@@ -51,8 +51,10 @@ class MySQL extends AbstractDatabase {
                                }
                        };
 
-                       \OC_Config::setValue('dbuser', $this->dbuser);
-                       \OC_Config::setValue('dbpassword', $this->dbpassword);
+                       \OC_Config::setValues([
+                               'dbuser'                => $this->dbuser,
+                               'dbpassword'    => $this->dbpassword,
+                       ]);
                }
 
                //create the database
index b75b658bae22b9e67f8e987122b8230a7fc54f8f..d4f71f18ab4f9379d30c4668398ef13f7889955b 100644 (file)
@@ -16,8 +16,11 @@ class OCI extends AbstractDatabase {
                }
                // allow empty hostname for oracle
                $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) {
@@ -72,37 +75,32 @@ class OCI extends AbstractDatabase {
                $result = oci_execute($stmt);
                if($result) {
                        $row = oci_fetch_row($stmt);
-               }
-               if($result and $row[0] > 0) {
-                       //use the admin login data for the new database user
 
-                       //add prefix to the oracle user name to prevent collisions
-                       $this->dbuser='oc_'.$username;
-                       //create a new password so we don't need to store the admin config in the config file
-                       $this->dbpassword=\OC_Util::generateRandomBytes(30);
+                       if ($row[0] > 0) {
+                               //use the admin login data for the new database user
 
-                       //oracle passwords are treated as identifiers:
-                       //  must start with alphanumeric char
-                       //  needs to be shortened to 30 bytes, as the two " needed to escape the identifier count towards the identifier length.
-                       $this->dbpassword=substr($this->dbpassword, 0, 30);
+                               //add prefix to the oracle user name to prevent collisions
+                               $this->dbuser='oc_'.$username;
+                               //create a new password so we don't need to store the admin config in the config file
+                               $this->dbpassword=\OC_Util::generateRandomBytes(30);
 
-                       $this->createDBUser($connection);
+                               //oracle passwords are treated as identifiers:
+                               //  must start with alphanumeric char
+                               //  needs to be shortened to 30 bytes, as the two " needed to escape the identifier count towards the identifier length.
+                               $this->dbpassword=substr($this->dbpassword, 0, 30);
 
-                       \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 {
+                               $this->createDBUser($connection);
+                       }
+               }
 
-                       \OC_Config::setValue('dbuser', $this->dbuser);
-                       \OC_Config::setValue('dbname', $this->dbname);
-                       \OC_Config::setValue('dbpassword', $this->dbpassword);
+               \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);
-               }
+               //create the database not necessary, oracle implies user = schema
+               //$this->createDatabase($this->dbname, $this->dbuser, $connection);
 
                //FIXME check tablespace exists: select * from user_tablespaces
 
index 3777d1620bcd6ff8256b38b01826b55f11bc4dfa..5fb6b85fc892618fd5bd72bfa8fa9ba5299aab21 100644 (file)
@@ -43,20 +43,15 @@ class PostgreSQL extends AbstractDatabase {
                        $this->dbpassword=\OC_Util::generateRandomBytes(30);
 
                        $this->createDBUser($connection);
-
-                       \OC_Config::setValue('dbuser', $this->dbuser);
-                       \OC_Config::setValue('dbpassword', $this->dbpassword);
-
-                       //create the database
-                       $this->createDatabase($connection);
                }
-               else {
-                       \OC_Config::setValue('dbuser', $this->dbuser);
-                       \OC_Config::setValue('dbpassword', $this->dbpassword);
 
-                       //create the database
-                       $this->createDatabase($connection);
-               }
+               \OC_Config::setValues([
+                       'dbuser'                => $this->dbuser,
+                       'dbpassword'    => $this->dbpassword,
+               ]);
+
+               //create the database
+               $this->createDatabase($connection);
 
                // the connection to dbname=postgres is not needed anymore
                pg_close($connection);
index d050a5ea03e74ef9e1629e9aa6de769ba2c23c45..5874e644abb75e04cbe02aad0a89d83a4b2e26ce 100644 (file)
@@ -84,20 +84,19 @@ class MailSettingsController extends Controller {
                                                                        $mail_smtpport) {
 
                $params = get_defined_vars();
+               $configs = [];
                foreach($params as $key => $value) {
-                       if(empty($value)) {
-                               $this->config->deleteSystemValue($key);
-                       } else {
-                               $this->config->setSystemValue($key, $value);
-                       }
+                       $configs[$key] = (empty($value)) ? null : $value;
                }
 
                // Delete passwords from config in case no auth is specified
-               if($params['mail_smtpauth'] !== 1) {
-                       $this->config->deleteSystemValue('mail_smtpname');
-                       $this->config->deleteSystemValue('mail_smtppassword');
+               if ($params['mail_smtpauth'] !== 1) {
+                       $configs['mail_smtpname'] = null;
+                       $configs['mail_smtppassword'] = null;
                }
 
+               $this->config->setSystemValues($configs);
+
                return array('data' =>
                        array('message' =>
                                (string) $this->l10n->t('Saved')
@@ -113,8 +112,10 @@ class MailSettingsController extends Controller {
         * @return array
         */
        public function storeCredentials($mail_smtpname, $mail_smtppassword) {
-               $this->config->setSystemValue('mail_smtpname', $mail_smtpname);
-               $this->config->setSystemValue('mail_smtppassword', $mail_smtppassword);
+               $this->config->setSystemValues([
+                       'mail_smtpname'         => $mail_smtpname,
+                       'mail_smtppassword'     => $mail_smtppassword,
+               ]);
 
                return array('data' =>
                        array('message' =>
index f6ebade7b171740075cd0b0972eca87a322099b1..ed33d7fbe49bee56f4ee5dfea485f91a2ee567f5 100644 (file)
@@ -69,26 +69,37 @@ class MailSettingsControllerTest extends \Test\TestCase {
                        );
                 */
 
-               $this->container['Config']
-                       ->expects($this->exactly(15))
-                       ->method('setSystemValue');
-
+               /** @var \PHPUnit_Framework_MockObject_MockObject $config */
+               $config = $this->container['Config'];
+               $config->expects($this->exactly(2))
+                       ->method('setSystemValues');
                /**
                 * FIXME: Use the following block once Jenkins uses PHPUnit >= 4.1
-                */
-               /*
-               $this->container['Config']
-                       ->expects($this->exactly(3))
-                       ->method('deleteSystemValue')
                        ->withConsecutive(
-                               array($this->equalTo('mail_smtpauth')),
-                               array($this->equalTo('mail_smtpname')),
-                               array($this->equalTo('mail_smtppassword'))
+                               [[
+                                       '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' => 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
                $response = $this->container['MailSettingsController']->setMailSettings(
@@ -126,21 +137,13 @@ class MailSettingsControllerTest extends \Test\TestCase {
                        ->method('t')
                        ->will($this->returnValue('Saved'));
 
-               /**
-                * FIXME: Use this block once Jenkins uses PHPUnit >= 4.1
-                */
-               /*
                $this->container['Config']
-                       ->expects($this->exactly(2))
-                       ->method('setSystemValue')
-                       ->withConsecutive(
-                               array($this->equalTo('mail_smtpname'), $this->equalTo('UsernameToStore')),
-                               array($this->equalTo('mail_smtppassword'), $this->equalTo('PasswordToStore'))
-                       );
-               */
-               $this->container['Config']
-                       ->expects($this->exactly(2))
-                       ->method('setSystemValue');
+                       ->expects($this->once())
+                       ->method('setSystemValues')
+                       ->with([
+                               'mail_smtpname' => 'UsernameToStore',
+                               'mail_smtppassword' => 'PasswordToStore',
+                       ]);
 
                $response = $this->container['MailSettingsController']->storeCredentials('UsernameToStore', 'PasswordToStore');
                $expectedResponse = array('data' => array('message' =>'Saved'), 'status' => 'success');