Merge pull request #12449 from owncloud/issue/12444-namespace-exceptions
Issue/12444 namespace exceptions
This commit is contained in:
commit
a2172786a8
|
@ -21,9 +21,6 @@
|
|||
|
||||
namespace OC;
|
||||
|
||||
class SyntaxException extends \Exception {
|
||||
}
|
||||
|
||||
class ArrayParser {
|
||||
const TYPE_NUM = 1;
|
||||
const TYPE_BOOL = 2;
|
||||
|
@ -209,7 +206,7 @@ class ArrayParser {
|
|||
$bracketDepth++;
|
||||
} elseif ($char === ')') {
|
||||
if ($bracketDepth <= 0) {
|
||||
throw new SyntaxException;
|
||||
throw new UnexpectedValueException();
|
||||
} else {
|
||||
$bracketDepth--;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (c) 2012 Frank Karlitschek <frank@owncloud.com>
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
namespace OC;
|
||||
|
||||
class DatabaseException extends \Exception {
|
||||
private $query;
|
||||
|
||||
//FIXME getQuery seems to be unused, maybe use parent constructor with $message, $code and $previous
|
||||
public function __construct($message, $query = null){
|
||||
parent::__construct($message);
|
||||
$this->query = $query;
|
||||
}
|
||||
|
||||
public function getQuery() {
|
||||
return $this->query;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com>
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
namespace OC;
|
||||
|
||||
class DatabaseSetupException extends HintException {
|
||||
}
|
|
@ -22,20 +22,6 @@
|
|||
|
||||
define('MDB2_SCHEMA_DUMP_STRUCTURE', '1');
|
||||
|
||||
class DatabaseException extends Exception {
|
||||
private $query;
|
||||
|
||||
//FIXME getQuery seems to be unused, maybe use parent constructor with $message, $code and $previous
|
||||
public function __construct($message, $query = null){
|
||||
parent::__construct($message);
|
||||
$this->query = $query;
|
||||
}
|
||||
|
||||
public function getQuery() {
|
||||
return $this->query;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class manages the access to the database. It basically is a wrapper for
|
||||
* Doctrine with some adaptions.
|
||||
|
@ -65,7 +51,7 @@ class OC_DB {
|
|||
* @param int $limit
|
||||
* @param int $offset
|
||||
* @param bool $isManipulation
|
||||
* @throws DatabaseException
|
||||
* @throws \OC\DatabaseException
|
||||
* @return OC_DB_StatementWrapper prepared SQL query
|
||||
*
|
||||
* SQL query via Doctrine prepare(), needs to be execute()'d!
|
||||
|
@ -82,7 +68,7 @@ class OC_DB {
|
|||
try {
|
||||
$result =$connection->prepare($query, $limit, $offset);
|
||||
} catch (\Doctrine\DBAL\DBALException $e) {
|
||||
throw new \DatabaseException($e->getMessage(), $query);
|
||||
throw new \OC\DatabaseException($e->getMessage(), $query);
|
||||
}
|
||||
// differentiate between query and manipulation
|
||||
$result = new OC_DB_StatementWrapper($result, $isManipulation);
|
||||
|
@ -123,7 +109,7 @@ class OC_DB {
|
|||
* .. or a simple sql query string
|
||||
* @param array $parameters
|
||||
* @return OC_DB_StatementWrapper
|
||||
* @throws DatabaseException
|
||||
* @throws \OC\DatabaseException
|
||||
*/
|
||||
static public function executeAudited( $stmt, array $parameters = null) {
|
||||
if (is_string($stmt)) {
|
||||
|
@ -132,7 +118,7 @@ class OC_DB {
|
|||
// TODO try to convert LIMIT OFFSET notation to parameters, see fixLimitClauseForMSSQL
|
||||
$message = 'LIMIT and OFFSET are forbidden for portability reasons,'
|
||||
. ' pass an array with \'limit\' and \'offset\' instead';
|
||||
throw new DatabaseException($message);
|
||||
throw new \OC\DatabaseException($message);
|
||||
}
|
||||
$stmt = array('sql' => $stmt, 'limit' => null, 'offset' => null);
|
||||
}
|
||||
|
@ -140,7 +126,7 @@ class OC_DB {
|
|||
// convert to prepared statement
|
||||
if ( ! array_key_exists('sql', $stmt) ) {
|
||||
$message = 'statement array must at least contain key \'sql\'';
|
||||
throw new DatabaseException($message);
|
||||
throw new \OC\DatabaseException($message);
|
||||
}
|
||||
if ( ! array_key_exists('limit', $stmt) ) {
|
||||
$stmt['limit'] = null;
|
||||
|
@ -160,7 +146,7 @@ class OC_DB {
|
|||
} else {
|
||||
$message = 'Expected a prepared statement or array got ' . gettype($stmt);
|
||||
}
|
||||
throw new DatabaseException($message);
|
||||
throw new \OC\DatabaseException($message);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
@ -169,7 +155,7 @@ class OC_DB {
|
|||
* gets last value of autoincrement
|
||||
* @param string $table The optional table name (will replace *PREFIX*) and add sequence suffix
|
||||
* @return string id
|
||||
* @throws DatabaseException
|
||||
* @throws \OC\DatabaseException
|
||||
*
|
||||
* \Doctrine\DBAL\Connection lastInsertId
|
||||
*
|
||||
|
@ -312,7 +298,7 @@ class OC_DB {
|
|||
* @param mixed $result
|
||||
* @param string $message
|
||||
* @return void
|
||||
* @throws DatabaseException
|
||||
* @throws \OC\DatabaseException
|
||||
*/
|
||||
public static function raiseExceptionOnError($result, $message = null) {
|
||||
if(self::isError($result)) {
|
||||
|
@ -321,7 +307,7 @@ class OC_DB {
|
|||
} else {
|
||||
$message .= ', Root cause:' . self::getErrorMessage($result);
|
||||
}
|
||||
throw new DatabaseException($message, self::getErrorCode($result));
|
||||
throw new \OC\DatabaseException($message, self::getErrorCode($result));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -345,7 +331,7 @@ class OC_DB {
|
|||
*
|
||||
* @param string $table
|
||||
* @return bool
|
||||
* @throws DatabaseException
|
||||
* @throws \OC\DatabaseException
|
||||
*/
|
||||
public static function tableExists($table) {
|
||||
|
||||
|
@ -381,7 +367,7 @@ class OC_DB {
|
|||
$result = \OC_DB::executeAudited($sql, array($table));
|
||||
break;
|
||||
default:
|
||||
throw new DatabaseException("Unknown database type: $dbType");
|
||||
throw new \OC\DatabaseException("Unknown database type: $dbType");
|
||||
}
|
||||
|
||||
return $result->fetchOne() === $table;
|
||||
|
|
|
@ -220,7 +220,7 @@ class OC_Group_Database extends OC_Group_Backend {
|
|||
* @param string $gid
|
||||
* @param string $search
|
||||
* @return int|false
|
||||
* @throws DatabaseException
|
||||
* @throws \OC\DatabaseException
|
||||
*/
|
||||
public function countUsersInGroup($gid, $search = '') {
|
||||
$stmt = OC_DB::prepare('SELECT COUNT(`uid`) AS `count` FROM `*PREFIX*group_user` WHERE `gid` = ? AND `uid` LIKE ?');
|
||||
|
|
|
@ -205,7 +205,7 @@ class Server extends SimpleContainer implements IServerContainer {
|
|||
$factory = new \OC\DB\ConnectionFactory();
|
||||
$type = $c->getConfig()->getSystemValue('dbtype', 'sqlite');
|
||||
if (!$factory->isValidType($type)) {
|
||||
throw new \DatabaseException('Invalid database type');
|
||||
throw new \OC\DatabaseException('Invalid database type');
|
||||
}
|
||||
$connectionParams = $factory->createConnectionParams($c->getConfig());
|
||||
$connection = $factory->getConnection($type, $connectionParams);
|
||||
|
|
|
@ -8,9 +8,6 @@
|
|||
|
||||
use OCP\IConfig;
|
||||
|
||||
class DatabaseSetupException extends \OC\HintException {
|
||||
}
|
||||
|
||||
class OC_Setup {
|
||||
/** @var IConfig */
|
||||
protected $config;
|
||||
|
@ -195,7 +192,7 @@ class OC_Setup {
|
|||
try {
|
||||
$dbSetup->initialize($options);
|
||||
$dbSetup->setupDatabase($username);
|
||||
} catch (DatabaseSetupException $e) {
|
||||
} catch (\OC\DatabaseSetupException $e) {
|
||||
$error[] = array(
|
||||
'error' => $e->getMessage(),
|
||||
'hint' => $e->getHint()
|
||||
|
|
|
@ -17,7 +17,7 @@ class MSSQL extends AbstractDatabase {
|
|||
} else {
|
||||
$entry = '';
|
||||
}
|
||||
throw new \DatabaseSetupException($this->trans->t('MS SQL username and/or password not valid: %s', array($entry)),
|
||||
throw new \OC\DatabaseSetupException($this->trans->t('MS SQL username and/or password not valid: %s', array($entry)),
|
||||
$this->trans->t('You need to enter either an existing account or the administrator.'));
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ class MySQL extends AbstractDatabase {
|
|||
//check if the database user has admin right
|
||||
$connection = @mysql_connect($this->dbhost, $this->dbuser, $this->dbpassword);
|
||||
if(!$connection) {
|
||||
throw new \DatabaseSetupException($this->trans->t('MySQL/MariaDB username and/or password not valid'),
|
||||
throw new \OC\DatabaseSetupException($this->trans->t('MySQL/MariaDB username and/or password not valid'),
|
||||
$this->trans->t('You need to enter either an existing account or the administrator.'));
|
||||
}
|
||||
//user already specified in config
|
||||
|
@ -96,13 +96,13 @@ class MySQL extends AbstractDatabase {
|
|||
$query = "CREATE USER '$name'@'localhost' IDENTIFIED BY '$password'";
|
||||
$result = mysql_query($query, $connection);
|
||||
if (!$result) {
|
||||
throw new \DatabaseSetupException($this->trans->t("MySQL/MariaDB user '%s'@'localhost' exists already.", array($name)),
|
||||
throw new \OC\DatabaseSetupException($this->trans->t("MySQL/MariaDB user '%s'@'localhost' exists already.", array($name)),
|
||||
$this->trans->t("Drop this user from MySQL/MariaDB", array($name)));
|
||||
}
|
||||
$query = "CREATE USER '$name'@'%' IDENTIFIED BY '$password'";
|
||||
$result = mysql_query($query, $connection);
|
||||
if (!$result) {
|
||||
throw new \DatabaseSetupException($this->trans->t("MySQL/MariaDB user '%s'@'%%' already exists", array($name)),
|
||||
throw new \OC\DatabaseSetupException($this->trans->t("MySQL/MariaDB user '%s'@'%%' already exists", array($name)),
|
||||
$this->trans->t("Drop this user from MySQL/MariaDB."));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,14 +45,14 @@ class OCI extends AbstractDatabase {
|
|||
if(!$connection) {
|
||||
$errorMessage = $this->getLastError();
|
||||
if ($errorMessage) {
|
||||
throw new \DatabaseSetupException($this->trans->t('Oracle connection could not be established'),
|
||||
throw new \OC\DatabaseSetupException($this->trans->t('Oracle connection could not be established'),
|
||||
$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')
|
||||
.' tnsnames.ora is '.(is_readable(getenv('ORACLE_HOME').'/network/admin/tnsnames.ora')?'':'not ').'readable');
|
||||
}
|
||||
throw new \DatabaseSetupException($this->trans->t('Oracle username and/or password not valid'),
|
||||
throw new \OC\DatabaseSetupException($this->trans->t('Oracle username and/or password not valid'),
|
||||
'Check environment: ORACLE_HOME='.getenv('ORACLE_HOME')
|
||||
.' ORACLE_SID='.getenv('ORACLE_SID')
|
||||
.' LD_LIBRARY_PATH='.getenv('LD_LIBRARY_PATH')
|
||||
|
@ -124,7 +124,7 @@ class OCI extends AbstractDatabase {
|
|||
}
|
||||
$connection = @oci_connect($this->dbuser, $this->dbpassword, $easy_connect_string);
|
||||
if(!$connection) {
|
||||
throw new \DatabaseSetupException($this->trans->t('Oracle username and/or password not valid'),
|
||||
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";
|
||||
|
|
|
@ -27,7 +27,7 @@ class PostgreSQL extends AbstractDatabase {
|
|||
$connection = @pg_connect($connection_string);
|
||||
|
||||
if(!$connection)
|
||||
throw new \DatabaseSetupException($this->trans->t('PostgreSQL username and/or password not valid'),
|
||||
throw new \OC\DatabaseSetupException($this->trans->t('PostgreSQL username and/or password not valid'),
|
||||
$this->trans->t('You need to enter either an existing account or the administrator.'));
|
||||
}
|
||||
$e_user = pg_escape_string($this->dbuser);
|
||||
|
@ -80,7 +80,7 @@ class PostgreSQL extends AbstractDatabase {
|
|||
$connection_string = "host='$e_host' dbname='$e_dbname' user='$e_user' port='$port' password='$e_password'";
|
||||
$connection = @pg_connect($connection_string);
|
||||
if(!$connection) {
|
||||
throw new \DatabaseSetupException($this->trans->t('PostgreSQL username and/or password not valid'),
|
||||
throw new \OC\DatabaseSetupException($this->trans->t('PostgreSQL username and/or password not valid'),
|
||||
$this->trans->t('You need to enter either an existing account or the administrator.'));
|
||||
}
|
||||
$query = "select count(*) FROM pg_class WHERE relname='".$this->tableprefix."users' limit 1";
|
||||
|
|
|
@ -64,7 +64,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
|
|||
|
||||
/**
|
||||
* Remove all entries from the storages table
|
||||
* @throws \DatabaseException
|
||||
* @throws \OC\DatabaseException
|
||||
*/
|
||||
static protected function tearDownAfterClassCleanStorages() {
|
||||
$sql = 'DELETE FROM `*PREFIX*storages`';
|
||||
|
@ -74,7 +74,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
|
|||
|
||||
/**
|
||||
* Remove all entries from the filecache table
|
||||
* @throws \DatabaseException
|
||||
* @throws \OC\DatabaseException
|
||||
*/
|
||||
static protected function tearDownAfterClassCleanFileCache() {
|
||||
$sql = 'DELETE FROM `*PREFIX*filecache`';
|
||||
|
|
Loading…
Reference in New Issue