diff --git a/api/src/Cache.php b/api/src/Cache.php index e0215da9ad..2c0d0c5a03 100644 --- a/api/src/Cache.php +++ b/api/src/Cache.php @@ -13,9 +13,8 @@ namespace EGroupware\Api; -use egw_exception_db; -use egw_exception_wrong_parameter; use egw_session; +use config; /** * Class to manage caching in eGroupware. @@ -119,7 +118,7 @@ class Cache { case self::SESSION: case self::REQUEST: - throw new egw_exception_wrong_parameter(__METHOD__."('$level', ...) unsupported level parameter!"); + throw new Api\Exception\WrongParameter(__METHOD__."('$level', ...) unsupported level parameter!"); case self::INSTANCE: case self::TREE: @@ -135,7 +134,7 @@ class Cache } return $provider->add(self::keys($level,$app,$location),$data,$expiration); } - throw new egw_exception_wrong_parameter(__METHOD__."() unknown level '$level'!"); + throw new Api\Exception\WrongParameter(__METHOD__."() unknown level '$level'!"); } /** @@ -171,7 +170,7 @@ class Cache } return $provider->set(self::keys($level,$app,$location),$data,$expiration); } - throw new egw_exception_wrong_parameter(__METHOD__."() unknown level '$level'!"); + throw new Api\Exception\WrongParameter(__METHOD__."() unknown level '$level'!"); } /** @@ -210,7 +209,7 @@ class Cache { if (!is_null($callback)) { - throw new egw_exception_wrong_parameter(__METHOD__."() you can NOT use multiple locations (\$location parameter is an array) together with a callback!"); + throw new Api\Exception\WrongParameter(__METHOD__."() you can NOT use multiple locations (\$location parameter is an array) together with a callback!"); } if (is_a($provider, 'EGroupware\Api\Cache\ProviderMultiple')) { @@ -247,7 +246,7 @@ class Cache } return $data; } - throw new egw_exception_wrong_parameter(__METHOD__."() unknown level '$level'!"); + throw new Api\Exception\WrongParameter(__METHOD__."() unknown level '$level'!"); } /** @@ -275,7 +274,7 @@ class Cache } return $provider->delete(self::keys($level,$app,$location)); } - throw new egw_exception_wrong_parameter(__METHOD__."() unknown level '$level'!"); + throw new Api\Exception\WrongParameter(__METHOD__."() unknown level '$level'!"); } /** @@ -591,7 +590,7 @@ class Cache error_log(__METHOD__."('$name', $throw) config value NOT found!");//.function_backtrace()); } } - catch(egw_exception_db $e) + catch(Api\Db\Exception $e) { if ($throw) error_log(__METHOD__."('$name', $throw) cound NOT query value: ".$e->getMessage());//.function_backtrace()); } @@ -730,7 +729,7 @@ class Cache */ function __construct() { - throw new egw_exception_wrong_parameter("All methods of class ".__CLASS__." should be called static!"); + throw new Api\Exception\WrongParameter("All methods of class ".__CLASS__." should be called static!"); } } diff --git a/api/src/Db.php b/api/src/Db.php index 03dfc95ad6..915f8527ba 100644 --- a/api/src/Db.php +++ b/api/src/Db.php @@ -13,10 +13,6 @@ namespace EGroupware\Api; -use egw_exception_db_connection; -use egw_exception_db_invalid_sql; -use egw_exception_wrong_parameter; - if(empty($GLOBALS['egw_info']['server']['db_type'])) { $GLOBALS['egw_info']['server']['db_type'] = 'mysql'; @@ -170,7 +166,7 @@ class Db /** * Callback to check if selected node is healty / should be used * - * @var callback throwing egw_exception_db_connection, if connected node should NOT be used + * @var callback throwing Api\Db\Exception\Connection, if connected node should NOT be used */ static $health_check; @@ -299,7 +295,7 @@ class Db * @param string $User name of database user (optional) * @param string $Password password for database user (optional) * @param string $Type type of database (optional) - * @throws egw_exception_db_connection + * @throws Api\Db\Exception\Connection * @return ADOConnection */ function connect($Database = NULL, $Host = NULL, $Port = NULL, $User = NULL, $Password = NULL,$Type = NULL) @@ -350,7 +346,7 @@ class Db //error_log(__METHOD__."() host=$host, new_connection=$new_connection, this->Type=$this->Type, this->Host=$this->Host, wsrep_local_state=".array2string($state)); return $this->Link_ID; } - catch(egw_exception_db_connection $e) { + catch(Api\Db\Exception\Connection $e) { _egw_log_exception($e); $this->disconnect(); // force a new connect $this->Type = $this->setupType; // get set to "mysql" for "mysqli" @@ -359,7 +355,7 @@ class Db } if (!isset($e)) { - $e = new egw_exception_db_connection('No DB host set!'); + $e = new Api\Db\Exception\Connection('No DB host set!'); } throw $e; } @@ -376,7 +372,7 @@ class Db * EGroupware\Api\Db::$health_check = array('EGroupware\Api\Db', 'galera_cluster_health'); * * @param Api\Db $db already connected Api\Db instance to check - * @throws egw_exception_db_connection if node should NOT be used + * @throws Api\Db\Exception\Connection if node should NOT be used */ static function galera_cluster_health(Db $db) { @@ -389,7 +385,7 @@ class Db $state['wsrep_local_state_comment'] == 'Donor/Desynced' && $state['wsrep_cluster_size'] == 2) return; - throw new egw_exception_db_connection('Node is NOT Synced! '.array2string($state)); + throw new Api\Db\Exception\Connection('Node is NOT Synced! '.array2string($state)); } } @@ -426,7 +422,7 @@ class Db * * @param string $Host host to connect to * @return ADOConnection - * @throws egw_exception_db_connection + * @throws Api\Db\Exception\Connection */ protected function _connect($Host) { @@ -503,7 +499,7 @@ class Db { if (!check_load_extension($php_extension)) { - throw new egw_exception_db_connection("Necessary php database support for $this->Type (".PHP_SHLIB_PREFIX.$php_extension.'.'.PHP_SHLIB_SUFFIX.") not loaded and can't be loaded, exiting !!!"); + throw new Api\Db\Exception\Connection("Necessary php database support for $this->Type (".PHP_SHLIB_PREFIX.$php_extension.'.'.PHP_SHLIB_SUFFIX.") not loaded and can't be loaded, exiting !!!"); } if (!isset($GLOBALS['egw']->ADOdb)) // use the global object to store the connection { @@ -516,7 +512,7 @@ class Db $this->Link_ID = ADONewConnection($Type); if (!$this->Link_ID) { - throw new egw_exception_db_connection("No ADOdb support for '$Type' ($this->Type) !!!"); + throw new Api\Db\Exception\Connection("No ADOdb support for '$Type' ($this->Type) !!!"); } if ($Type == 'mysqli') { @@ -532,7 +528,7 @@ class Db if (!$Ok) { $Host = preg_replace('/password=[^ ]+/','password=$Password',$Host); // eg. postgres dsn contains password - throw new egw_exception_db_connection("ADOdb::$connect($Host, $User, \$Password, $Database) failed."); + throw new Api\Db\Exception\Connection("ADOdb::$connect($Host, $User, \$Password, $Database) failed."); } if ($this->Debug) { @@ -563,7 +559,7 @@ class Db if (!$this->Link_ID->isConnected() && !$this->Link_ID->Connect()) { $Host = preg_replace('/password=[^ ]+/','password=$Password',$Host); // eg. postgres dsn contains password - throw new egw_exception_db_connection("ADOdb::$connect($Host, $User, \$Password, $Database) reconnect failed."); + throw new Api\Db\Exception\Connection("ADOdb::$connect($Host, $User, \$Password, $Database) reconnect failed."); } // fix due to caching and reusing of connection not correctly set $this->Type == 'mysql' if ($this->Type == 'mysqli') @@ -724,7 +720,7 @@ class Db * @param int $fetchmode =self::FETCH_BOTH self::FETCH_BOTH (default), self::FETCH_ASSOC or self::FETCH_NUM * @param boolean $reconnect =true true: try reconnecting if server closes connection, false: dont (mysql only!) * @return ADORecordSet or false, if the query fails - * @throws egw_exception_db_invalid_sql with $this->Link_ID->ErrorNo() as code + * @throws Api\Db\Exception\InvalidSql with $this->Link_ID->ErrorNo() as code */ function query($Query_String, $line = '', $file = '', $offset=0, $num_rows=-1, $inputarr=false, $fetchmode=self::FETCH_BOTH, $reconnect=true) { @@ -781,7 +777,7 @@ class Db $this->disconnect(); return $this->query($Query_String, $line, $file, $offset, $num_rows, $inputarr, $fetchmode, false); } - throw new egw_exception_db_invalid_sql("Invalid SQL: ".(is_array($Query_String)?$Query_String[0]:$Query_String). + throw new Api\Db\Exception\InvalidSql("Invalid SQL: ".(is_array($Query_String)?$Query_String[0]:$Query_String). "\n$this->Error ($this->Errno)". ($inputarr ? "\nParameters: '".implode("','",$inputarr)."'":''), $this->Errno); } @@ -1473,7 +1469,7 @@ class Db if (strpos($key, '.') !== false) list(, $col) = explode('.', $key); if (!isset($column_definitions[$col])) { - throw new egw_exception_db_invalid_sql("db::column_data_implode('$glue',".print_r($array,True).",'$use_key',".print_r($only,True).",
".print_r($column_definitions,True)."nothing known about column '$key'!"); + throw new Api\Db\Exception\InvalidSql("db::column_data_implode('$glue',".print_r($array,True).",'$use_key',".print_r($only,True).",
".print_r($column_definitions,True)."nothing known about column '$key'!"); } } $column_type = is_array($column_definitions) ? @$column_definitions[$col]['type'] : False; @@ -1566,7 +1562,7 @@ class Db if ($this === $GLOBALS['egw']->db && $app != self::API_APPNAME) { // prevent that anyone switches the global db object to an other app - throw new egw_exception_wrong_parameter('You are not allowed to call set_app for $GLOBALS[egw]->db or a refence to it, you have to clone it!'); + throw new Api\Exception\WrongParameter('You are not allowed to call set_app for $GLOBALS[egw]->db or a refence to it, you have to clone it!'); } $this->app = $app; } @@ -1739,7 +1735,7 @@ class Db $inputarr = false; if (isset($data[0]) && is_array($data[0])) // multiple data rows { - if ($where) throw new egw_exception_wrong_parameter('Can NOT use $where together with multiple data rows in $data!'); + if ($where) throw new Api\Exception\WrongParameter('Can NOT use $where together with multiple data rows in $data!'); $sql = "$cmd INTO $table "; foreach($data as $k => $d) @@ -1869,7 +1865,7 @@ class Db { $ret = $this->Link_ID->UpdateBlob($table,$col,$val,$where_str,$table_def['fd'][$col]['type'] == 'blob' ? 'BLOB' : 'CLOB'); if ($this->Debug) echo "
adodb::UpdateBlob('$table','$col','$val','$where_str') = '$ret'
\n"; - if (!$ret) throw new egw_exception_db_invalid_sql("Error in UpdateBlob($table,$col,\$val,$where_str)",$line,$file); + if (!$ret) throw new Api\Db\Exception\InvalidSql("Error in UpdateBlob($table,$col,\$val,$where_str)",$line,$file); } } return $ret; diff --git a/api/src/Db/Backup.php b/api/src/Db/Backup.php index e070ab0263..16953bd6b4 100644 --- a/api/src/Db/Backup.php +++ b/api/src/Db/Backup.php @@ -15,7 +15,6 @@ namespace EGroupware\Api\Db; use EGroupware\Api; -use egw_exception_db_invalid_sql; use config; use translation; use html; @@ -667,7 +666,7 @@ class Backup try { $this->db->insert($table,$data,False,__LINE__,__FILE__,false,false,$this->schemas[$table]); } - catch(egw_exception_db_invalid_sql $e) { + catch(Exception\InvalidSql $e) { echo "".$e->getMessage()."
\n"; } } @@ -715,7 +714,7 @@ class Backup try { $this->db->insert($table, $rows, False, __LINE__, __FILE__, false, false, $schema); } - catch(egw_exception_db_invalid_sql $e) + catch(Exception\InvalidSql $e) { // try inserting them one by one, ignoring doublicates foreach($rows as $data) @@ -723,7 +722,7 @@ class Backup try { $this->db->insert($table, $data, False, __LINE__, __FILE__, false, false, $schema); } - catch(egw_exception_db_invalid_sql $e) { + catch(Exception\InvalidSql $e) { echo "".$e->getMessage()."
\n"; } } diff --git a/api/src/Db/Deprecated.php b/api/src/Db/Deprecated.php index 675ca68ca3..7ada4ba3f8 100644 --- a/api/src/Db/Deprecated.php +++ b/api/src/Db/Deprecated.php @@ -14,7 +14,6 @@ namespace EGroupware\Api\Db; use EGroupware\Api; -use egw_exception_db; /** * Deprecated functionality we still need to support :-( @@ -53,7 +52,7 @@ class Deprecated extends Api\Db * @param int $fetchmode =self::FETCH_BOTH self::FETCH_BOTH (default), self::FETCH_ASSOC or self::FETCH_NUM * @param boolean $reconnect =true true: try reconnecting if server closes connection, false: dont (mysql only!) * @return ADORecordSet or false, if the query fails - * @throws egw_exception_db_invalid_sql with $this->Link_ID->ErrorNo() as code + * @throws EGroupware\Api\Db\Exception\InvalidSql with $this->Link_ID->ErrorNo() as code */ function query($Query_String, $line = '', $file = '', $offset=0, $num_rows=-1, $inputarr=false, $fetchmode=self::FETCH_BOTH, $reconnect=true) { @@ -120,7 +119,7 @@ class Deprecated extends Api\Db { if (!$this->Query_ID) { - throw new egw_exception_db('next_record called with no query pending.'); + throw new Exception\Db('next_record called with no query pending.'); } if ($this->Row) // first row is already fetched { @@ -175,7 +174,7 @@ class Deprecated extends Api\Db { if (!$this->Query_ID || !$this->Query_ID->Move($this->Row = $pos)) { - throw new egw_exception_db("seek($pos) failed: resultset has " . $this->num_rows() . " rows"); + throw new Exception\Db("seek($pos) failed: resultset has " . $this->num_rows() . " rows"); } return True; } diff --git a/api/src/Db/Exception.php b/api/src/Db/Exception.php new file mode 100644 index 0000000000..2de481eaa7 --- /dev/null +++ b/api/src/Db/Exception.php @@ -0,0 +1,36 @@ + + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @package api + * @subpackage db + * @access public + * @version $Id$ + */ + +namespace EGroupware\Api\Db; + +/** + * Exception thrown by the egw_db class for everything not covered by extended classed below + * + * New Db\Exception has to extend deprecated egw_exception_db to allow legacy code + * to catch exceptions thrown by Api\Db class! + */ +class Exception extends \egw_exception_db +{ + /** + * Constructor + * + * @param string $msg =null message, default "Database error!" + * @param int $code =100 + */ + function __construct($msg=null,$code=100) + { + if (is_null($msg)) $msg = lang('Database error!'); + + parent::__construct($msg,$code); + } +} diff --git a/api/src/Db/Exception/Connection.php b/api/src/Db/Exception/Connection.php new file mode 100644 index 0000000000..6eab46dcd9 --- /dev/null +++ b/api/src/Db/Exception/Connection.php @@ -0,0 +1,21 @@ + + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @package api + * @subpackage db + * @access public + * @version $Id$ + */ + +namespace EGroupware\Api\Db\Exception; + +use EGroupware\Api\Db; + +/** + * Can not connect to database: eg. database down, wrong host, name or credentials + */ +class Connection extends Db\Exception { } diff --git a/api/src/Db/Exception/InvalidSql.php b/api/src/Db/Exception/InvalidSql.php new file mode 100644 index 0000000000..fb06a94773 --- /dev/null +++ b/api/src/Db/Exception/InvalidSql.php @@ -0,0 +1,22 @@ + + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @package api + * @subpackage db + * @access public + * @version $Id$ + */ + +namespace EGroupware\Api\Db\Exception; + +/** + * Classic invalid SQL error + * + * New InvalidSql exception has to extend deprecated egw_exception_db_invalid_sql + * to allow legacy code to catch exceptions thrown by Api\Db! + */ +class InvalidSql extends \egw_exception_db_invalid_sql {} diff --git a/api/src/Db/Exception/NotUnique.php b/api/src/Db/Exception/NotUnique.php new file mode 100644 index 0000000000..e3f7470221 --- /dev/null +++ b/api/src/Db/Exception/NotUnique.php @@ -0,0 +1,21 @@ + + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @package api + * @subpackage db + * @access public + * @version $Id$ + */ + +namespace EGroupware\Api\Db\Exception; + +use EGroupware\Api\Db; + +/** + * Storing the row violates a unique key constrain + */ +class NotUnique extends Db\Exception { } diff --git a/api/src/Db/Exception/Setup.php b/api/src/Db/Exception/Setup.php new file mode 100644 index 0000000000..b4a5c6fb07 --- /dev/null +++ b/api/src/Db/Exception/Setup.php @@ -0,0 +1,21 @@ + + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @package api + * @subpackage db + * @access public + * @version $Id$ + */ + +namespace EGroupware\Api\Db\Exception; + +use EGroupware\Api\Db; + +/** + * EGroupware not (fully) installed, visit setup + */ +class Setup extends Db\Exception { } diff --git a/api/src/Db/Exception/Support.php b/api/src/Db/Exception/Support.php new file mode 100644 index 0000000000..a723a21cb8 --- /dev/null +++ b/api/src/Db/Exception/Support.php @@ -0,0 +1,21 @@ + + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @package api + * @subpackage db + * @access public + * @version $Id$ + */ + +namespace EGroupware\Api\Db\Exception; + +use EGroupware\Api\Db; + +/** + * PHP lacks support for configured database type + */ +class Support extends Db\Exception { } diff --git a/api/src/Db/Schema.php b/api/src/Db/Schema.php index af7dc0e525..c98ff92a6e 100644 --- a/api/src/Db/Schema.php +++ b/api/src/Db/Schema.php @@ -18,7 +18,6 @@ namespace EGroupware\Api\Db; use EGroupware\Api; -use egw_exception_assertion_failed; /** * eGW's ADOdb based schema-processor @@ -112,7 +111,7 @@ class Schema } if (!($this->m_odb instanceof Api\Db)) { - throw new egw_exception_assertion_failed('no EGroupware\Api\Db object!'); + throw new Api\Exception\AssertionFailed('no EGroupware\Api\Db object!'); } $this->m_odb->connect(); $this->capabilities =& $this->m_odb->capabilities; @@ -840,7 +839,7 @@ class Schema { if (!($this->m_odb instanceof Deprecated)) { - throw new egw_exception_assertion_failed(__METHOD__.' requires an EGroupware\Api\Db\Deprecated object!'); + throw new Api\Exception\AssertionFailed(__METHOD__.' requires an EGroupware\Api\Db\Deprecated object!'); } return $this->m_odb->f($value,$strip_slashes); } @@ -855,7 +854,7 @@ class Schema { if (!($this->m_odb instanceof Deprecated)) { - throw new egw_exception_assertion_failed(__METHOD__.' requires an EGroupware\Api\Db\Deprecated object!'); + throw new Api\Exception\AssertionFailed(__METHOD__.' requires an EGroupware\Api\Db\Deprecated object!'); } return $this->m_odb->num_rows(); } @@ -870,7 +869,7 @@ class Schema { if (!($this->m_odb instanceof Deprecated)) { - throw new egw_exception_assertion_failed(__METHOD__.' requires an EGroupware\Api\Db\Deprecated object!'); + throw new Api\Exception\AssertionFailed(__METHOD__.' requires an EGroupware\Api\Db\Deprecated object!'); } return $this->m_odb->next_record(); } diff --git a/api/src/Exception.php b/api/src/Exception.php new file mode 100644 index 0000000000..70e550db66 --- /dev/null +++ b/api/src/Exception.php @@ -0,0 +1,36 @@ + + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @package api + * @subpackage exception + * @access public + * @version $Id$ + */ + +namespace EGroupware\Api; + +/** + * EGroupware API - Exceptions + * + * All eGroupWare exceptions should extended this class, so we are able to eg. add some logging later. + * + * The messages for most exceptions should be translated and ready to be displayed to the user. + * Only exception to this are exceptions like Exception\AssertionFailed, Exception\WrongParameter + * or Db\Exception, which are suppost to happen only during program development. + */ +class Exception extends \Exception +{ + // nothing fancy yet + function __construct($msg=null,$code=100,\Exception $previous=null) + { + return parent::__construct($msg, $code, $previous); + } +} diff --git a/api/src/Exception/AssertionFailed.php b/api/src/Exception/AssertionFailed.php new file mode 100644 index 0000000000..014fb721f5 --- /dev/null +++ b/api/src/Exception/AssertionFailed.php @@ -0,0 +1,23 @@ + + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @package api + * @subpackage exception + * @access public + * @version $Id$ + */ + +namespace EGroupware\Api\Exception; + +use EGroupware\Api; + +/** + * An necessary assumption the developer made failed, regular execution can not continue + * + * As you get this only by an error in the code or during development, the message does not need to be translated + */ +class AssertionFailed extends Api\Exception { } diff --git a/api/src/Exception/NoPermission.php b/api/src/Exception/NoPermission.php new file mode 100644 index 0000000000..589c5eba2d --- /dev/null +++ b/api/src/Exception/NoPermission.php @@ -0,0 +1,36 @@ + + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @package api + * @subpackage exception + * @access public + * @version $Id$ + */ + +namespace EGroupware\Api\Exception; + +/** + * Base class for all exceptions about missing permissions + * + * New NoPermisison excpetion has to extend deprecated egw_exception_no_permission + * to allow legacy code to catch them! + */ +class NoPermission extends \egw_exception_no_permission +{ + /** + * Constructor + * + * @param string $msg =null message, default "Permission denied!" + * @param int $code =100 numerical code, default 100 + */ + function __construct($msg=null,$code=100) + { + if (is_null($msg)) $msg = lang('Permisson denied!'); + + parent::__construct($msg,$code); + } +} diff --git a/api/src/Exception/NoPermission/Admin.php b/api/src/Exception/NoPermission/Admin.php new file mode 100644 index 0000000000..32f7092cde --- /dev/null +++ b/api/src/Exception/NoPermission/Admin.php @@ -0,0 +1,28 @@ + + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @package api + * @subpackage exception + * @access public + * @version $Id$ + */ + +namespace EGroupware\Api\Exception\NoPermission; + +/** + * User is no eGroupWare admin (no right to run the admin application) + * + */ +class Admin extends App +{ + function __construct($msg=null,$code=102) + { + if (is_null($msg)) $msg = 'admin'; + + parent::__construct($msg,$code); + } +} diff --git a/api/src/Exception/NoPermission/App.php b/api/src/Exception/NoPermission/App.php new file mode 100644 index 0000000000..62ce6f19c1 --- /dev/null +++ b/api/src/Exception/NoPermission/App.php @@ -0,0 +1,44 @@ + + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @package api + * @subpackage exception + * @access public + * @version $Id$ + */ + +namespace EGroupware\Api\Exception\NoPermission; + +use EGroupware\Api\Exception; + +/** + * User lacks the right to run an application + * + */ +class App extends Exception\NoPermission +{ + function __construct($msg=null,$code=101) + { + if (isset($GLOBALS['egw_info']['apps'][$msg])) + { + if ($msg == 'admin') + { + $msg = lang('You need to be an eGroupWare administrator to access this functionality!'); + } + else + { + $currentapp = $GLOBALS['egw_info']['flags']['currentapp']; + $app = isset($GLOBALS['egw_info']['apps'][$currentapp]['title']) ? + $GLOBALS['egw_info']['apps'][$currentapp]['title'] : $msg; + + $msg = lang('You\'ve tried to open the eGroupWare application: %1, but you have no permission to access this application.', + '"'.$app.'"'); + } + } + parent::__construct($msg,$code); + } +} diff --git a/api/src/Exception/NoPermission/Record.php b/api/src/Exception/NoPermission/Record.php new file mode 100644 index 0000000000..8f653d85ac --- /dev/null +++ b/api/src/Exception/NoPermission/Record.php @@ -0,0 +1,22 @@ + + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @package api + * @subpackage exception + * @access public + * @version $Id$ + */ + +namespace EGroupware\Api\Exception\NoPermission; + +use EGroupware\Api\Exception; + +/** + * User lacks a record level permission, eg. he's not the owner and has no grant from the owner + * + */ +class Record extends Exception\NoPermission { } diff --git a/api/src/Exception/NotFound.php b/api/src/Exception/NotFound.php new file mode 100644 index 0000000000..81588fab0a --- /dev/null +++ b/api/src/Exception/NotFound.php @@ -0,0 +1,35 @@ + + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @package api + * @subpackage exception + * @access public + * @version $Id$ + */ + +namespace EGroupware\Api\Exception; + +use EGroupware\Api; + +/** + * A record or application entry was not found for the given id + */ +class NotFound extends Api\Exception +{ + /** + * Constructor + * + * @param string $msg =null message, default "Entry not found!" + * @param int $code =99 numerical code, default 2 + */ + function __construct($msg=null,$code=2) + { + if (is_null($msg)) $msg = lang('Entry not found!'); + + parent::__construct($msg,$code); + } +} diff --git a/api/src/Exception/Redirect.php b/api/src/Exception/Redirect.php new file mode 100644 index 0000000000..5076a956ba --- /dev/null +++ b/api/src/Exception/Redirect.php @@ -0,0 +1,43 @@ + + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @package api + * @subpackage exception + * @access public + * @version $Id$ + */ + +namespace EGroupware\Api\Exception; + +use EGroupware\Api; + +/** + * Allow callbacks to request a redirect + * + * Can be caught be applications and is otherwise handled by global exception handler. + */ +class Redirect extends Api\Exception +{ + public $url; + public $app; + + /** + * Constructor + * + * @param string $url + * @param string $app + * @param string $msg + * @param int $code + */ + function __construct($url,$app=null,$msg=null,$code=301) + { + $this->url = $url; + $this->app = $app; + + parent::__construct($msg, $code); + } +} diff --git a/api/src/Exception/WrongParameter.php b/api/src/Exception/WrongParameter.php new file mode 100644 index 0000000000..13bb66d5e9 --- /dev/null +++ b/api/src/Exception/WrongParameter.php @@ -0,0 +1,21 @@ + + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @package api + * @subpackage exception + * @access public + * @version $Id$ + */ + +namespace EGroupware\Api\Exception; + +/** + * A method or function was called with a wrong or missing parameter + * + * As you get this only by an error in the code or during development, the message does not need to be translated + */ +class WrongParameter extends AssertionFailed { } diff --git a/api/src/Exception/WrongUserInput.php b/api/src/Exception/WrongUserInput.php new file mode 100644 index 0000000000..c3be506496 --- /dev/null +++ b/api/src/Exception/WrongUserInput.php @@ -0,0 +1,20 @@ + + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @package api + * @subpackage exception + * @access public + * @version $Id$ + */ + +namespace EGroupware\Api\Exception; + +/** + * Wrong or missing required user input: message should be translated so it can be shown directly to the user + * + */ +class WrongUserinput extends AssertionFailed { } diff --git a/api/src/Vfs.php b/api/src/Vfs.php index 09980cc09b..0ab5bc45b2 100644 --- a/api/src/Vfs.php +++ b/api/src/Vfs.php @@ -18,14 +18,8 @@ use mime_magic; use common; use config; use html; -use egw_db; use translation; use HTTP_WebDAV_Server; -use egw_exception_assertion_failed; -use egw_exception_db; -use egw_exception_wrong_parameter; -use egw_exception_wrong_userinput; -use egw_exception; use egw_time; /** @@ -125,7 +119,7 @@ class Vfs extends Vfs\StreamWrapper /** * Reference to the global db object * - * @var egw_db + * @var Api\Db */ static $db; @@ -140,7 +134,7 @@ class Vfs extends Vfs\StreamWrapper { if ($path[0] != '/') { - throw new egw_exception_assertion_failed("Filename '$path' is not an absolute path!"); + throw new Api\Exception\AssertionFailed("Filename '$path' is not an absolute path!"); } return fopen(self::PREFIX.$path,$mode); } @@ -155,7 +149,7 @@ class Vfs extends Vfs\StreamWrapper { if ($path[0] != '/') { - throw new egw_exception_assertion_failed("Directory '$path' is not an absolute path!"); + throw new Api\Exception\AssertionFailed("Directory '$path' is not an absolute path!"); } return opendir(self::PREFIX.$path); } @@ -170,7 +164,7 @@ class Vfs extends Vfs\StreamWrapper { if ($path[0] != '/') { - throw new egw_exception_assertion_failed("Directory '$path' is not an absolute path!"); + throw new Api\Exception\AssertionFailed("Directory '$path' is not an absolute path!"); } return dir(self::PREFIX.$path); } @@ -186,7 +180,7 @@ class Vfs extends Vfs\StreamWrapper { if ($path[0] != '/') { - throw new egw_exception_assertion_failed("Directory '$path' is not an absolute path!"); + throw new Api\Exception\AssertionFailed("Directory '$path' is not an absolute path!"); } return scandir(self::PREFIX.$path,$sorting_order); } @@ -249,7 +243,7 @@ class Vfs extends Vfs\StreamWrapper { if ($path[0] != '/') { - throw new egw_exception_assertion_failed("File '$path' is not an absolute path!"); + throw new Api\Exception\AssertionFailed("File '$path' is not an absolute path!"); } if (($stat = self::url_stat($path,0,$try_create_home))) { @@ -269,7 +263,7 @@ class Vfs extends Vfs\StreamWrapper { if ($path[0] != '/') { - throw new egw_exception_assertion_failed("File '$path' is not an absolute path!"); + throw new Api\Exception\AssertionFailed("File '$path' is not an absolute path!"); } if (($stat = self::url_stat($path,STREAM_URL_STAT_LINK,$try_create_home))) { @@ -764,7 +758,7 @@ class Vfs extends Vfs\StreamWrapper * * @param string|array $urls url or array of url's * @param boolean $allow_urls =false allow to use url's, default no only pathes (to stay within the vfs) - * @throws egw_exception_assertion_failed when trainig to remove /, /apps or /home + * @throws Api\Exception\AssertionFailed when trainig to remove /, /apps or /home * @return array */ static function remove($urls,$allow_urls=false) @@ -775,7 +769,7 @@ class Vfs extends Vfs\StreamWrapper { if (preg_match('/^\/?(home|apps|)\/*$/',self::parse_url($url,PHP_URL_PATH))) { - throw new egw_exception_assertion_failed(__METHOD__.'('.array2string($urls).") Cautiously rejecting to remove folder '$url'!"); + throw new Api\Exception\AssertionFailed(__METHOD__.'('.array2string($urls).") Cautiously rejecting to remove folder '$url'!"); } } return self::find($urls,array('depth'=>true,'url'=>$allow_urls,'hidden'=>true),array(__CLASS__,'_rm_rmdir')); @@ -875,7 +869,7 @@ class Vfs extends Vfs\StreamWrapper // throw exception if stat array is used insead of path, can be removed soon if (is_array($path)) { - throw new egw_exception_wrong_parameter('path has to be string, use check_access($path,$check,$stat=null)!'); + throw new Api\Exception\WrongParameter('path has to be string, use check_access($path,$check,$stat=null)!'); } // query stat array, if not given if (is_null($stat)) @@ -1097,7 +1091,7 @@ class Vfs extends Vfs\StreamWrapper if (!preg_match($use='/^([ugoa]*)([+=-]+)([rwx]+)$/',$s,$matches)) { $use = str_replace(array('/','^','$','(',')'),'',$use); - throw new egw_exception_wrong_userinput("$s is not an allowed mode, use $use !"); + throw new Api\Exception\WrongUserInput("$s is not an allowed mode, use $use !"); } $base = (strpos($matches[3],'r') !== false ? self::READABLE : 0) | (strpos($matches[3],'w') !== false ? self::WRITABLE : 0) | @@ -1442,7 +1436,7 @@ class Vfs extends Vfs\StreamWrapper $zip = new \ZipArchive(); if (!$zip->open($zip_file, \ZipArchive::OVERWRITE)) { - throw new egw_exception("Cannot open zip file for writing."); + throw new Api\Exception("Cannot open zip file for writing."); } // Find lowest common directory, to use relative paths @@ -1654,8 +1648,8 @@ class Vfs extends Vfs\StreamWrapper ),__LINE__,__FILE__)->fetch()))) { $owner = $row['lock_owner']; - $scope = egw_db::from_bool($row['lock_exclusive']) ? 'exclusive' : 'shared'; - $type = egw_db::from_bool($row['lock_write']) ? 'write' : 'read'; + $scope = Api\Db::from_bool($row['lock_exclusive']) ? 'exclusive' : 'shared'; + $type = Api\Db::from_bool($row['lock_write']) ? 'write' : 'read'; self::$db->update(self::LOCK_TABLE,array( 'lock_expires' => $timeout, @@ -1700,7 +1694,7 @@ class Vfs extends Vfs\StreamWrapper ),false,__LINE__,__FILE__); $ret = true; } - catch(egw_exception_db $e) { + catch(Api\Db\Exception $e) { unset($e); $ret = false; // there's already a lock } @@ -1755,10 +1749,10 @@ class Vfs extends Vfs\StreamWrapper // ToDo: shared locks can return multiple rows if (($result = self::$db->select(self::LOCK_TABLE,'*',$where,__LINE__,__FILE__)->fetch())) { - $result = egw_db::strip_array_keys($result,'lock_'); - $result['type'] = egw_db::from_bool($result['write']) ? 'write' : 'read'; - $result['scope'] = egw_db::from_bool($result['exclusive']) ? 'exclusive' : 'shared'; - $result['depth'] = egw_db::from_bool($result['recursive']) ? 'infinite' : 0; + $result = Api\Db::strip_array_keys($result,'lock_'); + $result['type'] = Api\Db::from_bool($result['write']) ? 'write' : 'read'; + $result['scope'] = Api\Db::from_bool($result['exclusive']) ? 'exclusive' : 'shared'; + $result['depth'] = Api\Db::from_bool($result['recursive']) ? 'infinite' : 0; } if ($result && $result['expires'] < time()) // lock is expired --> remove it { diff --git a/api/src/Vfs/Sqlfs/StreamWrapper.php b/api/src/Vfs/Sqlfs/StreamWrapper.php index dce5bec684..338f4c8ac2 100644 --- a/api/src/Vfs/Sqlfs/StreamWrapper.php +++ b/api/src/Vfs/Sqlfs/StreamWrapper.php @@ -19,9 +19,6 @@ use EGroupware\Api; // explicitly import old phpgwapi classes used: use mime_magic; use config; -use egw_exception_db; -use egw_exception_wrong_parameter; -use egw_exception_assertion_failed; /** @@ -1184,7 +1181,7 @@ class StreamWrapper implements Vfs\StreamWrapperIface // decrement subquery limit by 1 and try again, if not already smaller then 3 if ($max_subquery_depth < 3) { - throw new egw_exception_db($e->getMessage()); + throw new Api\Db\Exception($e->getMessage()); } $GLOBALS['egw_info']['server']['max_subquery_depth'] = --$max_subquery_depth; error_log(__METHOD__."() decremented max_subquery_depth to $max_subquery_depth"); @@ -1699,7 +1696,7 @@ class StreamWrapper implements Vfs\StreamWrapperIface \PDO::ATTR_ERRMODE=>\PDO::ERRMODE_EXCEPTION, )); } - catch(Exception $e) + catch(\PDOException $e) { unset($e); // Exception reveals password, so we ignore the exception and connect again without pw, to get the right exception without pw @@ -1766,7 +1763,7 @@ class StreamWrapper implements Vfs\StreamWrapperIface { if (!is_numeric($id)) { - throw new egw_exception_wrong_parameter(__METHOD__."(id=$id) id has to be an integer!"); + throw new Api\Exception\WrongParameter(__METHOD__."(id=$id) id has to be an integer!"); } if (!isset($GLOBALS['egw_info']['server']['files_dir'])) { @@ -1780,7 +1777,7 @@ class StreamWrapper implements Vfs\StreamWrapperIface } if (!$GLOBALS['egw_info']['server']['files_dir']) { - throw new egw_exception_assertion_failed("\$GLOBALS['egw_info']['server']['files_dir'] not set!"); + throw new Api\Exception\AssertionFailed("\$GLOBALS['egw_info']['server']['files_dir'] not set!"); } $hash = array(); $n = $id; diff --git a/api/src/Vfs/Sqlfs/Utils.php b/api/src/Vfs/Sqlfs/Utils.php index aafea5508c..ef510690d4 100644 --- a/api/src/Vfs/Sqlfs/Utils.php +++ b/api/src/Vfs/Sqlfs/Utils.php @@ -7,7 +7,7 @@ * @package api * @subpackage vfs * @author Ralf Becker