move exceptions to new api structure, thought to catch an exception by its deprecated name, new exceptions have to extend deprecated ones

This commit is contained in:
Ralf Becker 2016-02-28 13:43:06 +00:00
parent 29e72a0bec
commit 1ab66dd811
29 changed files with 584 additions and 244 deletions

View File

@ -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!");
}
}

View File

@ -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).",<pre>".print_r($column_definitions,True)."</pre><b>nothing known about column '$key'!</b>");
throw new Api\Db\Exception\InvalidSql("db::column_data_implode('$glue',".print_r($array,True).",'$use_key',".print_r($only,True).",<pre>".print_r($column_definitions,True)."</pre><b>nothing known about column '$key'!</b>");
}
}
$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 "<p>adodb::UpdateBlob('$table','$col','$val','$where_str') = '$ret'</p>\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;

View File

@ -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 "<p>".$e->getMessage()."</p>\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 "<p>".$e->getMessage()."</p>\n";
}
}

View File

@ -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;
}

36
api/src/Db/Exception.php Normal file
View File

@ -0,0 +1,36 @@
<?php
/**
* EGroupware API - Db Exceptions
*
* @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @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);
}
}

View File

@ -0,0 +1,21 @@
<?php
/**
* EGroupware API - Db Exceptions
*
* @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @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 { }

View File

@ -0,0 +1,22 @@
<?php
/**
* EGroupware API - Db Exceptions
*
* @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @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 {}

View File

@ -0,0 +1,21 @@
<?php
/**
* EGroupware API - Db Exceptions
*
* @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @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 { }

View File

@ -0,0 +1,21 @@
<?php
/**
* EGroupware API - Db Exceptions
*
* @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @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 { }

View File

@ -0,0 +1,21 @@
<?php
/**
* EGroupware API - Db Exceptions
*
* @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @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 { }

View File

@ -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();
}

36
api/src/Exception.php Normal file
View File

@ -0,0 +1,36 @@
<?php
/**
* EGroupware API - Exceptions
*
* This file defines as set of Exceptions used in eGroupWare.
*
* Applications having the need for further exceptions should extends the from one defined in this file.
*
* @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @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);
}
}

View File

@ -0,0 +1,23 @@
<?php
/**
* EGroupware API - Exceptions
*
* @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @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 { }

View File

@ -0,0 +1,36 @@
<?php
/**
* EGroupware API - No Permission Exceptions
*
* @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @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);
}
}

View File

@ -0,0 +1,28 @@
<?php
/**
* EGroupware API - No Permission Exceptions
*
* @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @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);
}
}

View File

@ -0,0 +1,44 @@
<?php
/**
* EGroupware API - No Permission Exceptions
*
* @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @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);
}
}

View File

@ -0,0 +1,22 @@
<?php
/**
* EGroupware API - No Permission Exceptions
*
* @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @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 { }

View File

@ -0,0 +1,35 @@
<?php
/**
* EGroupware API - Exceptions
*
* @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @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);
}
}

View File

@ -0,0 +1,43 @@
<?php
/**
* EGroupware API - Exceptions
*
* @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @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);
}
}

View File

@ -0,0 +1,21 @@
<?php
/**
* EGroupware API - Exceptions
*
* @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @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 { }

View File

@ -0,0 +1,20 @@
<?php
/**
* EGroupware API - Exceptions
*
* @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @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 { }

View File

@ -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
{

View File

@ -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;

View File

@ -7,7 +7,7 @@
* @package api
* @subpackage vfs
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @copyright (c) 2008-15 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @copyright (c) 2008-16 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @version $Id$
*/
@ -17,8 +17,6 @@ use EGroupware\Api\Vfs;
// explicitly import old phpgwapi classes used:
use mime_magic;
use egw_exception_assertion_failed;
use schema_proc;
/**
* sqlfs stream wrapper utilities: migration db-fs, fsck
@ -69,7 +67,7 @@ class Utils extends StreamWrapper
}
if (!is_resource($content))
{
throw new egw_exception_assertion_failed(__METHOD__."(): fs_id=$fs_id ($fs_name, $fs_size bytes) content is NO resource! ".array2string($content));
throw new Api\Exception\AssertionFailed(__METHOD__."(): fs_id=$fs_id ($fs_name, $fs_size bytes) content is NO resource! ".array2string($content));
}
$filename = self::_fs_path($fs_id);
if (!file_exists($fs_dir=Vfs::dirname($filename)))
@ -78,11 +76,11 @@ class Utils extends StreamWrapper
}
if (!($dest = fopen($filename,'w')))
{
throw new egw_exception_assertion_failed(__METHOD__."(): fopen($filename,'w') failed!");
throw new Api\Exception\AssertionFailed(__METHOD__."(): fopen($filename,'w') failed!");
}
if (($bytes = stream_copy_to_stream($content,$dest)) != $fs_size)
{
throw new egw_exception_assertion_failed(__METHOD__."(): fs_id=$fs_id ($fs_name) $bytes bytes copied != size of $fs_size bytes!");
throw new Api\Exception\AssertionFailed(__METHOD__."(): fs_id=$fs_id ($fs_name) $bytes bytes copied != size of $fs_size bytes!");
}
if ($debug) error_log("$fs_id: $fs_name: $bytes bytes copied to fs");
fclose($dest);
@ -235,7 +233,7 @@ class Utils extends StreamWrapper
if (!$check_only && $msgs)
{
global $oProc;
if (!isset($oProc)) $oProc = new schema_proc();
if (!isset($oProc)) $oProc = new Api\Db\Schema();
// PostgreSQL seems to require to update the sequenz, after manually inserting id's
$oProc->UpdateSequence('egw_sqlfs', 'fs_id');
}

View File

@ -17,7 +17,6 @@ use EGroupware\Api\Vfs;
// explicitly import old phpgwapi classes used:
use mime_magic;
use egw_exception_db;
/**
* eGroupWare API: VFS - stream wrapper interface
@ -977,7 +976,7 @@ class StreamWrapper implements StreamWrapperIface
}
}
}
catch (egw_exception_db $e) {
catch (Api\Db\Exception $e) {
// some long running operations, eg. merge-print, run into situation that DB closes our separate sqlfs connection
// we try now to reconnect Vfs\Sqlfs\StreamWrapper once
// it's done here in vfs_stream_wrapper as situation can happen in sqlfs, links, stylite.links or stylite.versioning

View File

@ -12,6 +12,8 @@
* @version $Id$
*/
use EGroupware\Api;
/**
* New written class to create the eGW enviroment AND restore it from a php-session
*
@ -92,15 +94,15 @@ class egw extends egw_minimal
$this->db->connect();
$num_config = $this->db->select(config::TABLE,'COUNT(config_name)',false,__LINE__,__FILE__)->fetchColumn();
}
catch(egw_exception_db_connection $e) {
catch(Api\Db\Exception\Connection $e) {
// ignore exception, get handled below
}
catch(egw_exception_db_invalid_sql $e1) {
catch(Api\Db\Exception\InvalidSql $e1) {
unset($e1); // not used
try {
$phpgw_config = $this->db->select('phpgw_config','COUNT(config_name)',false,__LINE__,__FILE__)->fetchColumn();
}
catch (egw_exception_db_invalid_sql $e2) {
catch (Api\Db\Exception\InvalidSql $e2) {
unset($e2); // not used
// ignor error, get handled below
}
@ -114,10 +116,10 @@ class egw extends egw_minimal
}
if ($e)
{
throw new egw_exception_db_setup('Connection with '.$e->getMessage()."\n\n".
throw new Api\Db\Exception\Setup('Connection with '.$e->getMessage()."\n\n".
'Maybe you not created a database for EGroupware yet.',999);
}
throw new egw_exception_db_setup('It appears that you have not created the database tables for EGroupware.',999);
throw new Api\Db\Exception\Setup('It appears that you have not created the database tables for EGroupware.',999);
}
// Set the DB's client charset if a system-charset is set and some other values needed by egw_cache (used in config::read)
foreach($this->db->select(config::TABLE,'config_name,config_value',array(
@ -340,9 +342,9 @@ class egw extends egw_minimal
*
* If the user has no rights for the app (eg. called via URL) he get a permission denied page (this function does NOT return)
*
* @throws egw_exception_redirect for anonymous user accessing something he has no rights to
* @throws egw_exception_no_permission_admin
* @throws egw_exception_no_permission_app
* @throws Api\Exception\Redirect for anonymous user accessing something he has no rights to
* @throws Api\Exception\NoPermission\Admin
* @throws Api\Exception\NoPermission\App
*/
function check_app_rights()
{
@ -362,13 +364,13 @@ class egw extends egw_minimal
{
$GLOBALS['egw']->session->destroy($sessionid);
}
throw new egw_exception_redirect(egw::link('/logout.php'));
throw new Api\Exception\Redirect(egw::link('/logout.php'));
}
if ($currentapp == 'admin' || $GLOBALS['egw_info']['flags']['admin_only'])
{
throw new egw_exception_no_permission_admin();
throw new Api\Exception\NoPermission\Admin();
}
throw new egw_exception_no_permission_app($currentapp);
throw new Api\Exception\NoPermission\App($currentapp);
}
}
}
@ -492,7 +494,7 @@ class egw extends egw_minimal
$file = $line = null;
if (headers_sent($file,$line))
{
throw new egw_exception_assertion_failed(__METHOD__."('".htmlspecialchars($url)."') can NOT redirect, output already started at $file line $line!");
throw new Api\Exception\AssertionFailed(__METHOD__."('".htmlspecialchars($url)."') can NOT redirect, output already started at $file line $line!");
}
if ($GLOBALS['egw']->framework instanceof jdots_framework && !empty($link_app))
{

View File

@ -1,10 +1,6 @@
<?php
/**
* eGroupWare API - Exceptions
*
* This file defines as set of Exceptions used in eGroupWare.
*
* Applications having the need for further exceptions should extends the from one defined in this file.
* EGroupware API - old deprecated exceptions
*
* @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
@ -15,6 +11,8 @@
* @version $Id$
*/
use EGroupware\Api;
/**
* eGroupWare API - Exceptions
*
@ -23,191 +21,97 @@
* The messages for most exceptions should be translated and ready to be displayed to the user.
* Only exception to this are exceptions like egw_exception_assertion_fails, egw_exception_wrong_parameter
* or egw_exception_db, which are suppost to happen only during program development.
*
* @deprecated use Api\Exception
*/
class egw_exception extends Exception
{
// nothing fancy yet
function __construct($msg=null,$code=100,Exception $previous=null)
{
return parent::__construct($msg, $code, $previous);
}
}
class egw_exception extends Api\Exception {}
/**
* Base class for all exceptions about missing permissions
*
*/
class egw_exception_no_permission extends egw_exception
{
/**
* Constructor
* New NoPermisison excpetion has to extend deprecated egw_exception_no_permission
* to allow legacy code to catch them!
*
* @param string $msg =null message, default "Permission denied!"
* @param int $code =100 numerical code, default 100
* @deprecated use Api\Exception\NoPermission
*/
function __construct($msg=null,$code=100)
{
if (is_null($msg)) $msg = lang('Permisson denied!');
parent::__construct($msg,$code);
}
}
class egw_exception_no_permission extends Api\Exception {}
/**
* User lacks the right to run an application
*
* @deprecated use Api\Exception\NoPermission\App
*/
class egw_exception_no_permission_app extends egw_exception_no_permission
{
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);
}
}
class egw_exception_no_permission_app extends Api\Exception\NoPermission\App {}
/**
* User is no eGroupWare admin (no right to run the admin application)
*
* @deprecated use Api\Exception\NoPermission\Admin
*/
class egw_exception_no_permission_admin extends egw_exception_no_permission_app
{
function __construct($msg=null,$code=102)
{
if (is_null($msg)) $msg = 'admin';
parent::__construct($msg,$code);
}
}
class egw_exception_no_permission_admin extends Api\Exception\NoPermission\Admin {}
/**
* User lacks a record level permission, eg. he's not the owner and has no grant from the owner
*
* @deprecated use Api\Exception\NoPermission\Record
*/
class egw_exception_no_permission_record extends egw_exception_no_permission { }
class egw_exception_no_permission_record extends Api\Exception\NoPermission\Record {}
/**
* A record or application entry was not found for the given id
*
* @deprecated use Api\Exception\NotFound
*/
class egw_exception_not_found extends egw_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);
}
}
class egw_exception_not_found extends Api\Exception\NotFound {}
/**
* 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
*
* @deprecated use Api\Exception\AssertionFailed
*/
class egw_exception_assertion_failed extends egw_exception { }
class egw_exception_assertion_failed extends Api\Exception\AssertionFailed {}
/**
* 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
*
* @deprecated use Api\Exception\WrongParameter
*/
class egw_exception_wrong_parameter extends egw_exception_assertion_failed { }
class egw_exception_wrong_parameter extends Api\Exception\WrongParameter {}
/**
* Wrong or missing required user input: message should be translated so it can be shown directly to the user
*
* @deprecated use Api\Exception\WrongUserInput
*/
class egw_exception_wrong_userinput extends egw_exception_assertion_failed { }
class egw_exception_wrong_userinput extends Api\Exception\WrongUserinput {}
/**
* Exception thrown by the egw_db class for everything not covered by extended classed below
*/
class egw_exception_db extends egw_exception
{
/**
* Constructor
*
* @param string $msg =null message, default "Database error!"
* @param int $code =100
* New Db\Exception has to extend deprecated egw_exception_db to allow legacy code
* to catch exceptions thrown by Api\Db class!
*
* @deprecated use Api\Db\Exception
*/
function __construct($msg=null,$code=100)
{
if (is_null($msg)) $msg = lang('Database error!');
parent::__construct($msg,$code);
}
}
/**
* Storing the row violates a unique key constrain
*/
class egw_exception_db_not_unique extends egw_exception_db { }
/**
* Can not connect to database: eg. database down, wrong host, name or credentials
*/
class egw_exception_db_connection extends egw_exception_db { }
/**
* PHP lackst support for configured database type
*/
class egw_exception_db_support extends egw_exception_db { }
class egw_exception_db extends Api\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!
*
* @deprecated use Api\Db\Exception\InvalidSql
*/
class egw_exception_db_invalid_sql extends egw_exception_db { }
/**
* EGroupware not (fully) installed, visit setup
*/
class egw_exception_db_setup extends egw_exception_db { }
class egw_exception_db_invalid_sql extends Api\Db\Exception {}
/**
* Allow callbacks to request a redirect
*
* Can be caught be applications and is otherwise handled by global exception handler.
*/
class egw_exception_redirect extends egw_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);
}
}
class egw_exception_redirect extends Api\Exception\Redirect {}

View File

@ -14,6 +14,8 @@
* @version $Id$
*/
use EGroupware\Api;
// this is only neccessary, if header.inc.php is not included, but common_functions.inc.php directly
if (!defined('EGW_SERVER_ROOT'))
{
@ -1013,7 +1015,7 @@ function &CreateObject($class)
}
if (!file_exists($f=EGW_INCLUDE_ROOT.'/'.$appname.'/inc/class.'.$classname.'.inc.php'))
{
throw new egw_exception_assertion_failed(__FUNCTION__."($classname) file $f not found!");
throw new Api\Exception\AssertionFailed(__FUNCTION__."($classname) file $f not found!");
}
// this will stop php with a 500, if the class does not exist or there are errors in it (syntax error go into the error_log)
require_once(EGW_INCLUDE_ROOT.'/'.$appname.'/inc/class.'.$classname.'.inc.php');
@ -1783,15 +1785,15 @@ function json_php_unserialize($str, $allow_not_serialized=false)
function _egw_log_exception($e,&$headline=null)
{
$trace = explode("\n", $e->getTraceAsString());
if ($e instanceof egw_exception_no_permission)
if ($e instanceof Api\Exception\NoPermission)
{
$headline = try_lang('Permission denied!');
}
elseif ($e instanceof egw_exception_db)
elseif ($e instanceof Api\Db\Exception)
{
$headline = try_lang('Database error');
}
elseif ($e instanceof egw_exception_wrong_userinput)
elseif ($e instanceof Api\Exception\WrongUserinput)
{
$headline = ''; // message contains the whole message, it's usually no real error but some input validation
}
@ -1860,7 +1862,7 @@ function egw_exception_handler($e)
$message .= html::htmlspecialchars($e->getTraceAsString());
}
$message .= "</pre>\n";
if (is_a($e, 'egw_exception_db_setup'))
if (is_a($e, 'EGroupware\Api\Db\Exception\Setup'))
{
$setup_dir = str_replace(array('home/index.php','index.php'),'setup/',$_SERVER['PHP_SELF']);
$message .= '<a href="'.$setup_dir.'">Run setup to install or configure EGroupware.</a>';

View File

@ -11,6 +11,8 @@
* @version $Id$
*/
use EGroupware\Api;
/**
* Class detecting the current installation status of EGroupware
*/
@ -108,7 +110,7 @@ class setup_detection
}
}
}
catch (egw_exception_db $e) {
catch (Api\Db\Exception $e) {
unset($e);
// ignore db errors
}
@ -301,7 +303,7 @@ class setup_detection
$GLOBALS['egw_setup']->set_table_names();
}
}
catch(egw_exception_db $e) {
catch(Api\Db\Exception $e) {
// ignore error
}
@ -337,7 +339,7 @@ class setup_detection
$GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 3 (Install Applications)';
return 3;
}
catch (egw_exception_db $e) {
catch (Api\Db\Exception $e) {
$GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 1 (Create Database)';
return 1;
}
@ -363,7 +365,7 @@ class setup_detection
$config[$GLOBALS['egw_setup']->db->f(0)] = $GLOBALS['egw_setup']->db->f(1);
}
}
catch (egw_exception_db $e) {
catch (Api\Db\Exception $e) {
unset($e);
// ignore db errors
}
@ -443,7 +445,7 @@ class setup_detection
try {
$GLOBALS['egw_setup']->db->query($q = "SELECT DISTINCT lang FROM {$GLOBALS['egw_setup']->lang_table}",__LINE__,__FILE__);
}
catch (egw_exception_db $e) {
catch (Api\Db\Exception $e) {
// ignore db error
}
if($e || $GLOBALS['egw_setup']->db->num_rows() == 0)
@ -490,7 +492,7 @@ class setup_detection
$tables[] = $val['table_name'];
}
}
catch (egw_exception_db $e) {
catch (Api\Db\Exception $e) {
unset($e);
// ignore db error
}