Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions core/Command/Maintenance/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ protected function configure() {
->setName('maintenance:install')
->setDescription('Install ownCloud.')
->addOption('database', null, InputOption::VALUE_REQUIRED, 'Supported database type.', 'sqlite')
->addOption('database-connection-string', null, InputOption::VALUE_REQUIRED, 'Oracle specific connection string. As soon as this parameter is provided other parameters like database-host and database-name are not used and do not need to be provided')
->addOption('database-name', null, InputOption::VALUE_REQUIRED, 'Name of the database.')
->addOption('database-host', null, InputOption::VALUE_REQUIRED, 'Hostname of the database.', 'localhost')
->addOption('database-user', null, InputOption::VALUE_REQUIRED, 'User name to connect to the database.')
Expand Down Expand Up @@ -108,6 +109,7 @@ protected function validateInput(InputInterface $input, OutputInterface $output,
$dbUser = $input->getOption('database-user');
$dbPass = $input->getOption('database-pass');
$dbName = $input->getOption('database-name');
$dbConnectionString = $input->getOption('database-connection-string');
if ($db === 'oci') {
// an empty hostname needs to be read from the raw parameters
$dbHost = $input->getParameterOption('--database-host', '');
Expand All @@ -130,8 +132,8 @@ protected function validateInput(InputInterface $input, OutputInterface $output,
if ($dbUser === null) {
throw new InvalidArgumentException("Database user not provided.");
}
if ($dbName === null) {
throw new InvalidArgumentException("Database name not provided.");
if ($dbName === null && $dbConnectionString === null) {
throw new InvalidArgumentException('Database name and connection string not provided.');
}
if ($dbPass === null) {
/** @var $dialog \Symfony\Component\Console\Helper\QuestionHelper */
Expand All @@ -156,6 +158,7 @@ protected function validateInput(InputInterface $input, OutputInterface $output,
'dbpass' => $dbPass,
'dbname' => $dbName,
'dbhost' => $dbHost,
'dbconnectionstring' => $dbConnectionString,
'dbtableprefix' => $dbTablePrefix,
'adminlogin' => $adminLogin,
'adminpass' => $adminPassword,
Expand Down
9 changes: 6 additions & 3 deletions lib/private/DB/ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Event\Listeners\OracleSessionInit;
use Doctrine\DBAL\Event\Listeners\SQLSessionInit;
use Doctrine\DBAL\Events;
use OC\SystemConfig;

/**
Expand Down Expand Up @@ -116,7 +115,7 @@ public function getConnection($type, $additionalConnectionParams) {
switch ($normalizedType) {
case 'mysql':
$eventManager->addEventSubscriber(
new SQLSessionInit("SET SESSION AUTOCOMMIT=1"));
new SQLSessionInit('SET SESSION AUTOCOMMIT=1'));
break;
case 'oci':
$eventManager->addEventSubscriber(new OracleSessionInit);
Expand Down Expand Up @@ -172,10 +171,14 @@ public function createConnectionParams() {
'password' => $this->config->getValue('dbpassword', ''),
];
$name = $this->config->getValue('dbname', 'owncloud');
$connectString = $this->config->getValue('dbconnectionstring', '');

if ($this->normalizeType($type) === 'sqlite3') {
$dataDir = $this->config->getValue("datadirectory", \OC::$SERVERROOT . '/data');
$dataDir = $this->config->getValue('datadirectory', \OC::$SERVERROOT . '/data');
$connectionParams['path'] = $dataDir . '/' . $name . '.db';
} elseif ($type === 'oci' && $connectString !== '') {
$connectionParams['connectstring'] = $connectString;
$connectionParams['dbname'] = $name;
} else {
$host = $this->config->getValue('dbhost', '');
if (\strpos($host, ':')) {
Expand Down
5 changes: 5 additions & 0 deletions lib/private/Setup/AbstractDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ abstract class AbstractDatabase {
/** @var string */
protected $dbHost;
/** @var string */
protected $dbConnectionString;
/** @var string */
protected $tablePrefix;
/** @var string */
protected $dbprettyname;
Expand Down Expand Up @@ -80,11 +82,13 @@ public function initialize($config) {
$dbUser = $config['dbuser'];
$dbPass = $config['dbpass'];
$dbName = $config['dbname'];
$dbConnectionString = $config['dbconnectionstring'];
$dbHost = !empty($config['dbhost']) ? $config['dbhost'] : 'localhost';
$dbTablePrefix = isset($config['dbtableprefix']) ? $config['dbtableprefix'] : 'oc_';

$this->config->setSystemValues([
'dbname' => $dbName,
'dbconnectionstring' => $dbConnectionString,
'dbhost' => $dbHost,
'dbtableprefix' => $dbTablePrefix,
]);
Expand All @@ -93,6 +97,7 @@ public function initialize($config) {
$this->dbPassword = $dbPass;
$this->dbName = $dbName;
$this->dbHost = $dbHost;
$this->dbConnectionString = $dbConnectionString;
$this->tablePrefix = $dbTablePrefix;
}

Expand Down
34 changes: 15 additions & 19 deletions lib/private/Setup/OCI.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@ public function initialize($config) {

public function validate($config) {
$errors = [];
if (empty($config['dbuser']) && empty($config['dbname'])) {
$errors[] = $this->trans->t("%s enter the database username and name.", [$this->dbprettyname]);
} elseif (empty($config['dbuser'])) {
$errors[] = $this->trans->t("%s enter the database username.", [$this->dbprettyname]);
} elseif (empty($config['dbname'])) {
$errors[] = $this->trans->t("%s enter the database name.", [$this->dbprettyname]);
if (empty($config['dbuser'])) {
$errors[] = $this->trans->t('%s enter the database username.', [$this->dbprettyname]);
}
if (empty($config['dbname']) && empty($config['dbconnectionstring'])) {
$errors[] = $this->trans->t('%s enter the database name or connection string.', [$this->dbprettyname]);
}
return $errors;
}
Expand All @@ -65,7 +64,9 @@ public function setupDatabase($username) {
$e_host = \addslashes($this->dbHost);
$e_dbname = \addslashes($this->dbName);
//check if the database user has admin right
if ($e_host == '') {
if ($this->dbConnectionString !== null) {
$easy_connect_string = $this->dbConnectionString;
} elseif ($e_host === '') {
$easy_connect_string = $e_dbname; // use dbname as easy connect name
} else {
$easy_connect_string = '//'.$e_host.'/'.$e_dbname;
Expand Down Expand Up @@ -147,20 +148,12 @@ public function setupDatabase($username) {
//$this->dbname = \OC_Config::getValue('dbname');
$this->dbPassword = $this->config->getSystemValue('dbpassword');

$e_host = \addslashes($this->dbHost);
$e_dbname = \addslashes($this->dbName);

if ($e_host == '') {
$easy_connect_string = $e_dbname; // use dbname as easy connect name
} else {
$easy_connect_string = '//'.$e_host.'/'.$e_dbname;
}
$connection = @\oci_connect($this->dbUser, $this->dbPassword, $easy_connect_string);
if (!$connection) {
throw new \OC\DatabaseSetupException($this->trans->t('Oracle username and/or password not valid'),
$this->trans->t('You need to enter either an existing account or the administrator.'));
}
$query = "SELECT count(*) FROM user_tables WHERE table_name = :un";
$query = 'SELECT count(*) FROM user_tables WHERE table_name = :un';
$stmt = \oci_parse($connection, $query);
$un = $this->tablePrefix.'users';
\oci_bind_by_name($stmt, ':un', $un);
Expand All @@ -174,7 +167,10 @@ public function setupDatabase($username) {
if ($result) {
$row = \oci_fetch_row($stmt);
}
if (!$result or $row[0]==0) {
// the connection is not needed anymore
\oci_close($connection);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What issue triggered the need for closing the connection here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a long time dangling resource - we shall free any unused resources.

I discovered this while work on the code base


if (!$result || $row[0] == 0) {
\OC_DB::createDbFromStructure($this->dbDefinitionFile);
}
}
Expand All @@ -185,7 +181,7 @@ public function setupDatabase($username) {
private function createDBUser($connection) {
$name = $this->dbUser;
$password = $this->dbPassword;
$query = "SELECT * FROM all_users WHERE USERNAME = :un";
$query = 'SELECT * FROM all_users WHERE USERNAME = :un';
$stmt = \oci_parse($connection, $query);
if (!$stmt) {
$entry = $this->trans->t('DB Error: "%s"', [$this->getLastError($connection)]) . '<br />';
Expand Down Expand Up @@ -219,7 +215,7 @@ private function createDBUser($connection) {
$this->logger->warning($entry, ['app' => 'setup.oci']);
}
} else { // change password of the existing role
$query = "ALTER USER :un IDENTIFIED BY :pw";
$query = 'ALTER USER :un IDENTIFIED BY :pw';
$stmt = \oci_parse($connection, $query);
if (!$stmt) {
$entry = $this->trans->t('DB Error: "%s"', [$this->getLastError($connection)]) . '<br />';
Expand Down
12 changes: 9 additions & 3 deletions tests/drone/install-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,15 @@ install_cmd="maintenance:install -vvv \
--data-dir=${DATA_DIRECTORY} "

if [[ "${DB_TYPE}" != "sqlite" ]]; then
install_cmd+=" --database-host=${DB_TYPE} \
--database-user=${DB_USERNAME} \
--database-pass=${DB_PASSWORD}"
if [[ "${DB_TYPE}" != "oracle" ]]; then
install_cmd+=" --database-host=${DB_TYPE} \
--database-user=${DB_USERNAME} \
--database-pass=${DB_PASSWORD}"
else
install_cmd+=" --database-connection-string=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=${DB_TYPE})(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=XE))) \
--database-user=${DB_USERNAME} \
--database-pass=${DB_PASSWORD}"
fi
fi


Expand Down