Skip to content

Commit

Permalink
[OCI setup] remove static logger/config calls
Browse files Browse the repository at this point in the history
* logger/config object are already injected - this only uses it
  • Loading branch information
MorrisJobke committed Oct 20, 2015
1 parent dfd4494 commit 5944b33
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions lib/private/setup/oci.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function initialize($config) {
// allow empty hostname for oracle
$this->dbHost = $config['dbhost'];

\OC_Config::setValues([
$this->config->setSystemValues([
'dbhost' => $this->dbHost,
'dbtablespace' => $this->dbtablespace,
]);
Expand All @@ -66,7 +66,7 @@ public function setupDatabase($username) {
} else {
$easy_connect_string = '//'.$e_host.'/'.$e_dbname;
}
\OCP\Util::writeLog('setup oracle', 'connect string: ' . $easy_connect_string, \OCP\Util::DEBUG);
$this->logger->debug('connect string: ' . $easy_connect_string, ['app' => 'setup.oci']);
$connection = @oci_connect($this->dbUser, $this->dbPassword, $easy_connect_string);
if(!$connection) {
$errorMessage = $this->getLastError();
Expand All @@ -93,7 +93,7 @@ public function setupDatabase($username) {
if (!$stmt) {
$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
\OCP\Util::writeLog('setup.oci', $entry, \OCP\Util::WARN);
$this->logger->warning($entry, ['app' => 'setup.oci']);
}
$result = oci_execute($stmt);
if($result) {
Expand All @@ -116,7 +116,7 @@ public function setupDatabase($username) {
}
}

\OC_Config::setValues([
$this->config->setSystemValues([
'dbuser' => $this->dbUser,
'dbname' => $this->dbName,
'dbpassword' => $this->dbPassword,
Expand All @@ -131,9 +131,9 @@ public function setupDatabase($username) {
oci_close($connection);

// connect to the oracle database (schema=$this->dbuser) an check if the schema needs to be filled
$this->dbUser = \OC_Config::getValue('dbuser');
$this->dbUser = $this->config->getSystemValue('dbuser');
//$this->dbname = \OC_Config::getValue('dbname');
$this->dbPassword = \OC_Config::getValue('dbpassword');
$this->dbPassword = $this->config->getSystemValue('dbpassword');

$e_host = addslashes($this->dbHost);
$e_dbname = addslashes($this->dbName);
Expand All @@ -155,7 +155,7 @@ public function setupDatabase($username) {
if (!$stmt) {
$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
\OCP\Util::writeLog('setup.oci', $entry, \OCP\Util::WARN);
$this->logger->warning( $entry, ['app' => 'setup.oci']);
}
$result = oci_execute($stmt);

Expand All @@ -178,14 +178,14 @@ private function createDBUser($connection) {
if (!$stmt) {
$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
\OCP\Util::writeLog('setup.oci', $entry, \OCP\Util::WARN);
$this->logger->warning($entry, ['app' => 'setup.oci']);
}
oci_bind_by_name($stmt, ':un', $name);
$result = oci_execute($stmt);
if(!$result) {
$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
\OCP\Util::writeLog('setup.oci', $entry, \OCP\Util::WARN);
$this->logger->warning($entry, ['app' => 'setup.oci']);
}

if(! oci_fetch_row($stmt)) {
Expand All @@ -196,31 +196,33 @@ private function createDBUser($connection) {
if (!$stmt) {
$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
\OCP\Util::writeLog('setup.oci', $entry, \OCP\Util::WARN);
$this->logger->warning($entry, ['app' => 'setup.oci']);

}
//oci_bind_by_name($stmt, ':un', $name);
$result = oci_execute($stmt);
if(!$result) {
$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
$entry .= $this->trans->t('Offending command was: "%s", name: %s, password: %s',
array($query, $name, $password)) . '<br />';
\OCP\Util::writeLog('setup.oci', $entry, \OCP\Util::WARN);
$this->logger->warning($entry, ['app' => 'setup.oci']);

}
} else { // change password of the existing role
$query = "ALTER USER :un IDENTIFIED BY :pw";
$stmt = oci_parse($connection, $query);
if (!$stmt) {
$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
\OCP\Util::writeLog('setup.oci', $entry, \OCP\Util::WARN);
$this->logger->warning($entry, ['app' => 'setup.oci']);
}
oci_bind_by_name($stmt, ':un', $name);
oci_bind_by_name($stmt, ':pw', $password);
$result = oci_execute($stmt);
if(!$result) {
$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
\OCP\Util::writeLog('setup.oci', $entry, \OCP\Util::WARN);
$this->logger->warning($entry, ['app' => 'setup.oci']);
}
}
// grant necessary roles
Expand All @@ -229,14 +231,14 @@ private function createDBUser($connection) {
if (!$stmt) {
$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
\OCP\Util::writeLog('setup.oci', $entry, \OCP\Util::WARN);
$this->logger->warning($entry, ['app' => 'setup.oci']);
}
$result = oci_execute($stmt);
if(!$result) {
$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
$entry .= $this->trans->t('Offending command was: "%s", name: %s, password: %s',
array($query, $name, $password)) . '<br />';
\OCP\Util::writeLog('setup.oci', $entry, \OCP\Util::WARN);
$this->logger->warning($entry, ['app' => 'setup.oci']);
}
}

Expand Down

0 comments on commit 5944b33

Please sign in to comment.