From 005c98e46c92b6c02a19abe6f9c26c939475faf2 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 27 Nov 2013 00:08:07 +0100 Subject: [PATCH 1/7] Correct property name. It's just 'tableprefix', without the 'db' prefix. --- lib/private/setup/oci.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/setup/oci.php b/lib/private/setup/oci.php index 326d7a00531..f53d986d7db 100644 --- a/lib/private/setup/oci.php +++ b/lib/private/setup/oci.php @@ -115,7 +115,7 @@ class OCI extends AbstractDatabase { } $query = "SELECT count(*) FROM user_tables WHERE table_name = :un"; $stmt = oci_parse($connection, $query); - $un = $this->dbtableprefix.'users'; + $un = $this->tableprefix.'users'; oci_bind_by_name($stmt, ':un', $un); if (!$stmt) { $entry = $this->trans->t('DB Error: "%s"', array(oci_error($connection))) . '
'; From b90f88f939ec67eca548c123494288dbf79d9159 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 28 Nov 2013 11:27:05 +0100 Subject: [PATCH 2/7] Correct property name. It's 'dbpassword', with the 'db' prefix. --- lib/private/setup/oci.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/setup/oci.php b/lib/private/setup/oci.php index f53d986d7db..e6475d97460 100644 --- a/lib/private/setup/oci.php +++ b/lib/private/setup/oci.php @@ -140,7 +140,7 @@ class OCI extends AbstractDatabase { */ private function createDBUser($connection) { $name = $this->dbuser; - $password = $this->password; + $password = $this->dbpassword; $query = "SELECT * FROM all_users WHERE USERNAME = :un"; $stmt = oci_parse($connection, $query); if (!$stmt) { From fcf332abbfcec2e61103eff8b36c833b6da16bf4 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 28 Nov 2013 11:29:04 +0100 Subject: [PATCH 3/7] There is no property such as dbusername. It's 'dbuser'. --- lib/private/setup/oci.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/private/setup/oci.php b/lib/private/setup/oci.php index e6475d97460..997d50c8afb 100644 --- a/lib/private/setup/oci.php +++ b/lib/private/setup/oci.php @@ -74,12 +74,12 @@ class OCI extends AbstractDatabase { $this->createDBUser($connection); - \OC_Config::setValue('dbuser', $this->dbusername); - \OC_Config::setValue('dbname', $this->dbusername); + \OC_Config::setValue('dbuser', $this->dbuser); + \OC_Config::setValue('dbname', $this->dbuser); \OC_Config::setValue('dbpassword', $this->dbpassword); //create the database not neccessary, oracle implies user = schema - //$this->createDatabase($this->dbname, $this->dbusername, $connection); + //$this->createDatabase($this->dbname, $this->dbuser, $connection); } else { \OC_Config::setValue('dbuser', $this->dbuser); From 955127231ad4adb248f2cbfdb9eabdc56b58a183 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 28 Nov 2013 11:37:29 +0100 Subject: [PATCH 4/7] No function as oci_last_error. It's oci_error. --- lib/private/setup/oci.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/setup/oci.php b/lib/private/setup/oci.php index 997d50c8afb..f4ecb22de5f 100644 --- a/lib/private/setup/oci.php +++ b/lib/private/setup/oci.php @@ -51,7 +51,7 @@ class OCI extends AbstractDatabase { ." WHERE user_role_privs.granted_role = role_sys_privs.role AND privilege = 'CREATE ROLE'"; $stmt = oci_parse($connection, $query); if (!$stmt) { - $entry = $this->trans->t('DB Error: "%s"', array(oci_last_error($connection))) . '
'; + $entry = $this->trans->t('DB Error: "%s"', array(oci_error($connection))) . '
'; $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '
'; \OC_Log::write('setup.oci', $entry, \OC_Log::WARN); } From 904573d0d079d93cb6a0b1153c4a6cf127a8ddce Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 28 Nov 2013 12:04:28 +0100 Subject: [PATCH 5/7] Add getLastError() --- lib/private/setup/oci.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/private/setup/oci.php b/lib/private/setup/oci.php index f4ecb22de5f..3676a54c50d 100644 --- a/lib/private/setup/oci.php +++ b/lib/private/setup/oci.php @@ -29,10 +29,10 @@ class OCI extends AbstractDatabase { \OC_Log::write('setup oracle', 'connect string: ' . $easy_connect_string, \OC_Log::DEBUG); $connection = @oci_connect($this->dbuser, $this->dbpassword, $easy_connect_string); if(!$connection) { - $e = oci_error(); - if (is_array ($e) && isset ($e['message'])) { + $errorMessage = $this->getLastError(); + if ($errorMessage) { throw new \DatabaseSetupException($this->trans->t('Oracle connection could not be established'), - $e['message'].' Check environment: ORACLE_HOME='.getenv('ORACLE_HOME') + $errorMessage.' Check environment: ORACLE_HOME='.getenv('ORACLE_HOME') .' ORACLE_SID='.getenv('ORACLE_SID') .' LD_LIBRARY_PATH='.getenv('LD_LIBRARY_PATH') .' NLS_LANG='.getenv('NLS_LANG') @@ -207,4 +207,21 @@ class OCI extends AbstractDatabase { \OC_Log::write('setup.oci', $entry, \OC_Log::WARN); } } + + /** + * @param resource $connection + */ + protected function getLastError($connection = null) { + if ($connection) { + $error = oci_error($connection); + } else { + $error = oci_error(); + } + foreach (array('message', 'code') as $key) { + if (isset($error[$key])) { + return $error[$key]; + } + } + return ''; + } } From 93b0bd0a9e0c5f4986eb305126e29ca6d9a08cf9 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 28 Nov 2013 12:05:46 +0100 Subject: [PATCH 6/7] Use getLastError() everywhere. --- lib/private/setup/oci.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/private/setup/oci.php b/lib/private/setup/oci.php index 3676a54c50d..a19206ecf3d 100644 --- a/lib/private/setup/oci.php +++ b/lib/private/setup/oci.php @@ -51,7 +51,7 @@ class OCI extends AbstractDatabase { ." WHERE user_role_privs.granted_role = role_sys_privs.role AND privilege = 'CREATE ROLE'"; $stmt = oci_parse($connection, $query); if (!$stmt) { - $entry = $this->trans->t('DB Error: "%s"', array(oci_error($connection))) . '
'; + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '
'; $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '
'; \OC_Log::write('setup.oci', $entry, \OC_Log::WARN); } @@ -118,7 +118,7 @@ class OCI extends AbstractDatabase { $un = $this->tableprefix.'users'; oci_bind_by_name($stmt, ':un', $un); if (!$stmt) { - $entry = $this->trans->t('DB Error: "%s"', array(oci_error($connection))) . '
'; + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '
'; $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '
'; \OC_Log::write('setup.oci', $entry, \OC_Log::WARN); } @@ -144,14 +144,14 @@ class OCI extends AbstractDatabase { $query = "SELECT * FROM all_users WHERE USERNAME = :un"; $stmt = oci_parse($connection, $query); if (!$stmt) { - $entry = $this->trans->t('DB Error: "%s"', array(oci_error($connection))) . '
'; + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '
'; $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '
'; \OC_Log::write('setup.oci', $entry, \OC_Log::WARN); } oci_bind_by_name($stmt, ':un', $name); $result = oci_execute($stmt); if(!$result) { - $entry = $this->trans->t('DB Error: "%s"', array(oci_error($connection))) . '
'; + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '
'; $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '
'; \OC_Log::write('setup.oci', $entry, \OC_Log::WARN); } @@ -162,14 +162,14 @@ class OCI extends AbstractDatabase { $query = 'CREATE USER '.$name.' IDENTIFIED BY "'.$password.'" DEFAULT TABLESPACE '.$this->dbtablespace; $stmt = oci_parse($connection, $query); if (!$stmt) { - $entry = $this->trans->t('DB Error: "%s"', array(oci_error($connection))) . '
'; + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '
'; $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '
'; \OC_Log::write('setup.oci', $entry, \OC_Log::WARN); } //oci_bind_by_name($stmt, ':un', $name); $result = oci_execute($stmt); if(!$result) { - $entry = $this->trans->t('DB Error: "%s"', array(oci_error($connection))) . '
'; + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '
'; $entry .= $this->trans->t('Offending command was: "%s", name: %s, password: %s', array($query, $name, $password)) . '
'; \OC_Log::write('setup.oci', $entry, \OC_Log::WARN); @@ -178,7 +178,7 @@ class OCI extends AbstractDatabase { $query = "ALTER USER :un IDENTIFIED BY :pw"; $stmt = oci_parse($connection, $query); if (!$stmt) { - $entry = $this->trans->t('DB Error: "%s"', array(oci_error($connection))) . '
'; + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '
'; $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '
'; \OC_Log::write('setup.oci', $entry, \OC_Log::WARN); } @@ -186,7 +186,7 @@ class OCI extends AbstractDatabase { oci_bind_by_name($stmt, ':pw', $password); $result = oci_execute($stmt); if(!$result) { - $entry = $this->trans->t('DB Error: "%s"', array(oci_error($connection))) . '
'; + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '
'; $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '
'; \OC_Log::write('setup.oci', $entry, \OC_Log::WARN); } @@ -195,13 +195,13 @@ class OCI extends AbstractDatabase { $query = 'GRANT CREATE SESSION, CREATE TABLE, CREATE SEQUENCE, CREATE TRIGGER, UNLIMITED TABLESPACE TO '.$name; $stmt = oci_parse($connection, $query); if (!$stmt) { - $entry = $this->trans->t('DB Error: "%s"', array(oci_error($connection))) . '
'; + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '
'; $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '
'; \OC_Log::write('setup.oci', $entry, \OC_Log::WARN); } $result = oci_execute($stmt); if(!$result) { - $entry = $this->trans->t('DB Error: "%s"', array(oci_error($connection))) . '
'; + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '
'; $entry .= $this->trans->t('Offending command was: "%s", name: %s, password: %s', array($query, $name, $password)) . '
'; \OC_Log::write('setup.oci', $entry, \OC_Log::WARN); From 87e795a693c9671d5564815e71f3821348f2b9d5 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Mon, 2 Dec 2013 08:42:28 +0100 Subject: [PATCH 7/7] fixing PHPDoc and spelling --- lib/private/setup/abstractdatabase.php | 4 ++++ lib/private/setup/oci.php | 10 ++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/private/setup/abstractdatabase.php b/lib/private/setup/abstractdatabase.php index 0beada7bd29..84625a217ee 100644 --- a/lib/private/setup/abstractdatabase.php +++ b/lib/private/setup/abstractdatabase.php @@ -3,6 +3,10 @@ namespace OC\Setup; abstract class AbstractDatabase { + + /** + * @var \OC_L10N + */ protected $trans; protected $dbDefinitionFile; protected $dbuser; diff --git a/lib/private/setup/oci.php b/lib/private/setup/oci.php index a19206ecf3d..24863b9e38a 100644 --- a/lib/private/setup/oci.php +++ b/lib/private/setup/oci.php @@ -68,7 +68,7 @@ class OCI extends AbstractDatabase { $this->dbpassword=\OC_Util::generateRandomBytes(30); //oracle passwords are treated as identifiers: - // must start with aphanumeric char + // 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); @@ -78,7 +78,7 @@ class OCI extends AbstractDatabase { \OC_Config::setValue('dbname', $this->dbuser); \OC_Config::setValue('dbpassword', $this->dbpassword); - //create the database not neccessary, oracle implies user = schema + //create the database not necessary, oracle implies user = schema //$this->createDatabase($this->dbname, $this->dbuser, $connection); } else { @@ -86,7 +86,7 @@ class OCI extends AbstractDatabase { \OC_Config::setValue('dbname', $this->dbname); \OC_Config::setValue('dbpassword', $this->dbpassword); - //create the database not neccessary, oracle implies user = schema + //create the database not necessary, oracle implies user = schema //$this->createDatabase($this->dbname, $this->dbuser, $connection); } @@ -133,9 +133,6 @@ class OCI extends AbstractDatabase { } /** - * - * @param String $name - * @param String $password * @param resource $connection */ private function createDBUser($connection) { @@ -210,6 +207,7 @@ class OCI extends AbstractDatabase { /** * @param resource $connection + * @return string */ protected function getLastError($connection = null) { if ($connection) {