/**
* Handle for the current database connection.
*
- * @var DB
+ * @var Horde_Db_Adapter_Base
*/
protected $_db;
/**
- * Handle for the current database connection, used for writing. Defaults
- * to the same handle as $_db if a separate write database is not required.
- *
- * @var DB
- */
- protected $_write_db;
-
- /**
* Constructor.
*
* @param array $params Configuration parameters:
* <pre>
- * 'db' - (DB) [REQUIRED] The DB instance.
+ * 'db' - (Horde_Db_Adapter_Base) [REQUIRED] The DB instance.
* 'table' - (string) The name of the tokens table in 'database'.
* DEFAULT: 'horde_alarms'
- * 'write_db' - (DB) The write DB instance.
* </pre>
*
* @throws Horde_Alarm_Exception
throw new Horde_Alarm_Exception('Missing db parameter.');
}
$this->_db = $params['db'];
-
- $this->_write_db = isset($params['write_db'])
- ? $params['write_db']
- : $this->_db;
-
- unset($params['db'], $params['write_db']);
+ unset($params['db']);
$params = array_merge(array(
'table' => 'horde_alarms'
$values[] = (string)$user;
}
- if ($this->_logger) {
- $this->_logger->log('SQL query by Horde_Alarm_sql::_list(): ' . $query, 'DEBUG');
- }
- $alarms = array();
- $result = $this->_db->query($query, $values);
- if ($result instanceof PEAR_Error) {
- if ($this->_logger) {
- $this->_logger->log($result, 'INFO');
- }
- throw new Horde_Alarm_Exception($result);
+ try {
+ $result = $this->_db->selectAll($query, $values);
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Alarm_Exception($e);
}
- while ($alarm = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
- if ($alarm instanceof PEAR_Error) {
- if ($this->_logger) {
- $this->_logger->log($alarm, 'INFO');
- }
- throw new Horde_Alarm_Exception($alarm);
- }
-
- $alarms[] = $this->_getHash($alarm);
+ $alarms = array();
+ foreach ($result as $val) {
+ $alarms[] = $this->_getHash($val);
}
return $alarms;
$this->_params['table'],
!empty($user) ? 'alarm_uid = ?' : '(alarm_uid = ? OR alarm_uid IS NULL)');
- if ($this->_logger) {
- $this->_logger->log('SQL query by Horde_Alarm_sql::_get(): ' . $query, 'DEBUG');
- }
-
- $alarm = $this->_db->getRow($query, array($id, $user), DB_FETCHMODE_ASSOC);
- if ($alarm instanceof PEAR_Error) {
- if ($this->_logger) {
- $this->_logger->log($alarm, 'INFO');
- }
- throw new Horde_Alarm_Exception($alarm);
+ try {
+ $alarm = $this->_db->selectOne($query, array($id, $user));
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Alarm_Exception($e);
}
if (empty($alarm)) {
empty($alarm['text']) ? null : $this->_toDriver($alarm['text']),
null
);
- if ($this->_logger) {
- $this->_logger->log('SQL query by Horde_Alarm_sql::_add(): ' . $query, 'DEBUG');
- }
- $result = $this->_write_db->query($query, $values);
- if ($result instanceof PEAR_Error) {
- if ($this->_logger) {
- $this->_logger->log($result, 'INFO');
- }
- throw new Horde_Alarm_Exception($result);
+ try {
+ $this->_db->insert($query, $values);
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Alarm_Exception($e);
}
}
$alarm['id'],
isset($alarm['user']) ? $alarm['user'] : '');
- if ($this->_logger) {
- $this->_logger->log('SQL query by Horde_Alarm_sql::_update(): ' . $query, 'DEBUG');
- }
-
- $result = $this->_write_db->query($query, $values);
- if ($result instanceof PEAR_Error) {
- if ($this->_logger) {
- $this->_logger->log($result, 'INFO');
- }
- throw new Horde_Alarm_Exception($result);
+ try {
+ $this->_db->update($query, $values);
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Alarm_Exception($e);
}
}
!empty($user) ? 'alarm_uid = ?' : '(alarm_uid = ? OR alarm_uid IS NULL)');
$values = array(serialize($internal), $id, $user);
- if ($this->_logger) {
- $this->_logger->log('SQL query by Horde_Alarm_sql::internal(): ' . $query, 'DEBUG');
- }
-
- $result = $this->_write_db->query($query, $values);
- if ($result instanceof PEAR_Error) {
- if ($this->_logger) {
- $this->_logger->log($result, 'INFO');
- }
- throw new Horde_Alarm_Exception($result);
+ try {
+ $this->_db->query($query, $values);
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Alarm_Exception($e);
}
}
$this->_params['table'],
!empty($user) ? 'alarm_uid = ?' : '(alarm_uid = ? OR alarm_uid IS NULL)');
- if ($this->_logger) {
- $this->_logger->log('SQL query by Horde_Alarm_sql::_exists(): ' . $query, 'DEBUG');
+ try {
+ return ($this->_db->selectValue($query, array($id, $user)) == 1);
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Alarm_Exception($e);
}
-
- $result = $this->_db->getOne($query, array($id, $user));
- if ($result instanceof PEAR_Error) {
- if ($this->_logger) {
- $this->_logger->log($result, 'INFO');
- }
- throw new Horde_Alarm_Exception($result);
- }
-
- return $result == 1;
}
/**
!empty($user) ? 'alarm_uid = ?' : '(alarm_uid = ? OR alarm_uid IS NULL)');
$values = array((string)$snooze->setTimezone('UTC'), $id, $user);
- if ($this->_logger) {
- $this->_logger->log('SQL query by Horde_Alarm_sql::_snooze(): ' . $query, 'DEBUG');
- }
-
- $result = $this->_write_db->query($query, $values);
- if ($result instanceof PEAR_Error) {
- if ($this->_logger) {
- $this->_logger->log($result, 'INFO');
- }
- throw new Horde_Alarm_Exception($result);
+ try {
+ $this->_db->update($query, $values);
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Alarm_Exception($e);
}
}
$this->_params['table'],
!empty($user) ? 'alarm_uid = ?' : '(alarm_uid = ? OR alarm_uid IS NULL)');
- if ($this->_logger) {
- $this->_logger->log('SQL query by Horde_Alarm_sql::_isSnoozed(): ' . $query, 'DEBUG');
+ try {
+ return $this->_db->selectValue($query, array($id, $user, (string)$time->setTimezone('UTC')));
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Alarm_Exception($e);
}
-
- $result = $this->_db->getOne($query, array($id, $user, (string)$time->setTimezone('UTC')));
- if ($result instanceof PEAR_Error) {
- if ($this->_logger) {
- $this->_logger->log($result, 'INFO');
- }
- throw new Horde_Alarm_Exception($result);
- }
-
- return $result;
}
/**
!empty($user) ? 'alarm_uid = ?' : '(alarm_uid = ? OR alarm_uid IS NULL)');
$values = array($id, $user);
- if ($this->_logger) {
- $this->_logger->log('SQL query by Horde_Alarm_sql::_dismiss(): ' . $query, 'DEBUG');
- }
-
- $result = $this->_write_db->query($query, $values);
- if ($result instanceof PEAR_Error) {
- if ($this->_logger) {
- $this->_logger->log($result, 'INFO');
- }
- throw new Horde_Alarm_Exception($result);
+ try {
+ $this->_db->update($query, $values);
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Alarm_Exception($e);
}
}
$values[] = $user;
}
- if ($this->_logger) {
- $this->_logger->log('SQL query by Horde_Alarm_sql::_delete(): ' . $query, 'DEBUG');
- }
-
- $result = $this->_write_db->query($query, $values);
- if ($result instanceof PEAR_Error) {
- if ($this->_logger) {
- $this->_logger->log($result, 'INFO');
- }
- throw new Horde_Alarm_Exception($result);
+ try {
+ $this->_db->delete($query, $values);
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Alarm_Exception($e);
}
}
/**
* Garbage collects old alarms in the backend.
- *
- * @throws Horde_Alarm_Exception
*/
protected function _gc()
{
$query = sprintf('DELETE FROM %s WHERE alarm_end IS NOT NULL AND alarm_end < ?', $this->_params['table']);
- if ($this->_logger) {
- $this->_logger->log('SQL query by Horde_Alarm_sql::_gc(): ' . $query, 'DEBUG');
- }
-
$end = new Horde_Date(time());
- $result = $this->_write_db->query($query, (string)$end->setTimezone('UTC'));
- if ($result instanceof PEAR_Error) {
- if ($this->_logger) {
- $this->_logger->log($result, 'INFO');
- }
- throw new Horde_Alarm_Exception($result);
- }
-
- return $result;
+ try {
+ $this->_db->delete($query, (string)$end->setTimezone('UTC'));
+ } catch (Horde_Db_Exception $e) {}
}
/**
*/
public function initialize()
{
- $this->_initConn($this->_db);
- if ($this->_write_db) {
- $this->_initConn($this->_write_db);
- }
- }
-
- /**
- * Alarm specific initialization tasks.
- */
- protected function _initConn(DB_common $db)
- {
/* Handle any database specific initialization code to run. */
- switch ($db->dbsyntax) {
- case 'oci8':
+ switch ($this->_db->adapterName()) {
+ case 'PDO_Oci':
$query = "ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'";
-
- if ($this->_logger) {
- $this->_logger->log(sprintf('SQL connection setup for Alarms, query = "%s"', $query), 'DEBUG');
- }
-
- $db->query($query);
+ $db->execute($query);
break;
- case 'pgsql':
+ case 'PDO_PostrgreSQL':
$query = "SET datestyle TO 'iso'";
-
- if ($this->_logger) {
- $this->_logger->log(sprintf('SQL connection setup for Alarms, query = "%s"', $query), 'DEBUG');
- }
-
- $db->query($query);
+ $db->execute($query);
break;
}
}
</required>
<optional>
<package>
- <name>DB</name>
- <channel>pear.php.net</channel>
+ <name>Db</name>
+ <channel>pear.horde.org</channel>
</package>
<package>
- <name>Mail</name>
+ <name>Log</name>
<channel>pear.horde.org</channel>
</package>
<package>
- <name>Mime</name>
+ <name>Mail</name>
<channel>pear.horde.org</channel>
</package>
<package>
- <name>Notification</name>
+ <name>Mime</name>
<channel>pear.horde.org</channel>
</package>
<package>
- <name>Log</name>
+ <name>Notification</name>
<channel>pear.horde.org</channel>
</package>
<package>
/**
* Handle for the current database connection.
*
- * @var DB
+ * @var Horde_Db_Adapter_Base
*/
protected $_db;
/**
- * Handle for the current database connection, used for writing. Defaults
- * to the same handle as $_db if a separate write database isn't required.
- *
- * @var DB
- */
- protected $_write_db;
-
- /**
* The memory cache object to use, if configured.
*
* @var Horde_Cache
*
* @param array $params Parameters:
* <pre>
- * 'db' - (DB) [REQUIRED] The DB instance.
- * 'table' - (string) The name of the cache table in 'database'.
+ * 'db' - (Horde_Db_Adapter_Base) [REQUIRED] The DB instance.
+ * 'table' - (string) The name of the cache table.
* DEFAULT: 'horde_cache'
* 'use_memorycache' - (Horde_Cache) Use this memory caching object to
* cache the data (to avoid DB accesses).
- * 'write_db' - (DB) The write DB instance.
* </pre>
*
* @throws Horde_Cache_Exception
}
$this->_db = $params['db'];
- $this->_write_db = isset($params['write_db'])
- ? $params['write_db']
- : $this->_db;
-
if (isset($params['use_memorycache'])) {
$this->_mc = $params['use_memorycache'];
}
- unset($params['db'], $params['use_memorycache'], $params['write_db']);
+ unset($params['db'], $params['use_memorycache']);
$params = array_merge(array(
'table' => 'horde_cache',
' WHERE cache_expiration < ? AND cache_expiration <> 0';
$values = array(time());
- $result = $this->_write_db->query($query, $values);
- if (is_a($result, 'PEAR_Error')) {
- if ($this->_logger) {
- $this->_logger->log($result, 'ERR');
- }
- }
+ try {
+ $this->_db->delete($query, $values);
+ } catch (Horde_Db_Exception $e) {}
}
/**
$values[] = $maxage;
}
- $result = $this->_db->getOne($query, $values);
- if (is_a($result, 'PEAR_Error')) {
- if ($this->_logger) {
- $this->_logger->log($result, 'ERR');
- }
+ try {
+ $result = $this->_db->selectValue($query, $values);
+ } catch (Horde_Db_Exception $e) (
return false;
- } elseif (is_null($result)) {
+ }
+
+ if (is_null($result)) {
/* No rows were found - cache miss */
if ($this->_logger) {
$this->_logger->log(sprintf('Cache miss: %s (Id %s newer than %d)', $okey, $key, $maxage), 'DEBUG');
// Remove any old cache data and prevent duplicate keys
$query = 'DELETE FROM ' . $this->_params['table'] . ' WHERE cache_id=?';
$values = array($key);
- $this->_write_db->query($query, $values);
+ try {
+ $this->_db->query($query, $values);
+ } catch (Horde_Db_Exception $e) {}
/* Build SQL query. */
$query = 'INSERT INTO ' . $this->_params['table'] .
' VALUES (?, ?, ?, ?)';
$values = array($key, $timestamp, $expiration, $data);
- $result = $this->_write_db->query($query, $values);
- if (is_a($result, 'PEAR_Error')) {
- if ($this->_logger) {
- $this->_logger->log($result, 'ERR');
- }
+ try {
+ $this->_db->query($query, $values);
+ } catch (Horde_Db_Exception $e) {
return false;
}
$values[] = time() - $lifetime;
}
- $result = $this->_db->getRow($query, $values);
- if (is_a($result, 'PEAR_Error')) {
- if ($this->_logger) {
- $this->_logger->log($result, 'ERR');
- }
+ try {
+ $result = $this->_db->selectValue($query, $values);
+ } catch (Horde_Db_Exception $e) {
return false;
}
' WHERE cache_id = ?';
$values = array($key);
- $result = $this->_write_db->query($query, $values);
- if (is_a($result, 'PEAR_Error')) {
- if ($this->_logger) {
- $this->_logger->log($result, 'ERR');
- }
+ try {
+ $this->_db->delete($query, $values);
+ } catch (Horde_Db_Exception $e) {
return false;
}
<min>1.7.0</min>
</pearinstaller>
<package>
+ <name>Exception</name>
+ <channel>pear.horde.org</channel>
+ </package>
+ <package>
<name>Util</name>
<channel>pear.horde.org</channel>
</package>
</required>
<optional>
<package>
- <name>DB</name>
- <channel>pear.php.net</channel>
+ <name>Db</name>
+ <channel>pear.horde.org</channel>
</package>
<package>
<name>Log</name>
{
public function create(Horde_Injector $injector)
{
- if (empty($GLOBALS['conf']['alarms']['driver'])) {
- $driver = null;
- $params = array();
- } else {
- $driver = $GLOBALS['conf']['alarms']['driver'];
- $params = Horde::getDriverConfig('alarms', $driver);
- }
+ $driver = empty($GLOBALS['conf']['alarms']['driver'])
+ ? 'Null'
+ : $GLOBALS['conf']['alarms']['driver'];
+ $params = Horde::getDriverConfig('alarms', $driver);
if (strcasecmp($driver, 'Sql') === 0) {
- $write_db = $injector->getInstance('Horde_Db_Pear')->getOb();
-
- /* Check if we need to set up the read DB connection
- * separately. */
- if (empty($params['splitread'])) {
- $params['db'] = $write_db;
- } else {
- $params['write_db'] = $write_db;
- $params['db'] = $injector->getInstance('Horde_Db_Pear')->getOb('read');
- }
+ $params['db'] = $injector->getInstance('Horde_Db_Adapter_Base');
}
$params['logger'] = $injector->getInstance('Horde_Log_Logger');
* through Horde_Alarms::handlers(). */
/*
$handler_params = array(
- 'notification' => $injector->getInstance('Horde_Notification'));
- $alarm->addHandler('notify', new Horde_Alarm_Handler_Notification($handler_params));
+ 'notification' => $injector->getInstance('Horde_Notification')
+ );
+ $alarm->addHandler('notify', new Horde_Alarm_Handler_Notification($handler_params)
+ );
+
$handler_params = array(
'notification' => $injector->getInstance('Horde_Notification'),
- 'icon' => (string)Horde_Themes::img('alerts/alarm.png'));
+ 'icon' => (string)Horde_Themes::img('alerts/alarm.png')
+ );
$alarm->addHandler('desktop', new Horde_Alarm_Handler_Desktop($handler_params));
*/
+
$handler_params = array(
'identity' => $injector->getInstance('Horde_Prefs_Identity'),
'mail' => $injector->getInstance('Horde_Mail'),
if (strcasecmp($driver, 'Memcache') === 0) {
$params['memcache'] = $injector->getInstance('Horde_Memcache');
} elseif (strcasecmp($driver, 'Sql') === 0) {
- $write_db = $injector->getInstance('Horde_Db_Pear')->getOb();
-
- /* Check if we need to set up the read DB connection
- * separately. */
- if (empty($params['splitread'])) {
- $params['db'] = $write_db;
- } else {
- $params['write_db'] = $write_db;
- $params['db'] = $injector->getInstance('Horde_Db_Pear')->getOb('read');
- }
+ $params['db'] = $injector->getInstance('Horde_Db_Adapter_Base');
if (!empty($params['use_memorycache'])) {
$params['use_memorycache'] = $this->_getCacheInstance($params['use_memorycache'], $injector);
{
public function create(Horde_Injector $injector)
{
- if (empty($GLOBALS['conf']['lock']['driver'])) {
+ $driver = empty($GLOBALS['conf']['lock']['driver'])
+ ? 'Null'
+ : $GLOBALS['conf']['lock']['driver'];
+
+ if (strcasecmp($driver, 'None') === 0) {
$driver = 'Null';
- } else {
- $driver = $GLOBALS['conf']['lock']['driver'];
- if (strcasecmp($driver, 'None') === 0) {
- $driver = 'Null';
- }
}
$params = Horde::getDriverConfig('lock', $driver);
$params['logger'] = $injector->getInstance('Horde_Log_Logger');
if (strcasecmp($driver, 'Sql') === 0) {
- $write_db = $injector->getInstance('Horde_Db_Pear')->getOb();
-
- /* Check if we need to set up the read DB connection
- * separately. */
- if (empty($params['splitread'])) {
- $params['db'] = $write_db;
- } else {
- $params['write_db'] = $write_db;
- $params['db'] = $injector->getInstance('Horde_Db_Pear')->getOb('read');
- }
+ $params['db'] = $injector->getInstance('Horde_Db_Adapter_Base');
}
return Horde_Lock::factory($driver, $params);
{
public function create(Horde_Injector $injector)
{
- $params = isset($GLOBALS['conf']['perms'])
- ? Horde::getDriverConfig('perms', $GLOBALS['conf']['perms']['driver'])
- : array();
-
$driver = empty($GLOBALS['conf']['perms']['driver'])
? (empty($GLOBALS['conf']['datatree']['driver']) ? null : 'Datatree')
: $GLOBALS['conf']['perms']['driver'];
+ $params = isset($GLOBALS['conf']['perms'])
+ ? Horde::getDriverConfig('perms', $driver)
+ : array();
if (strcasecmp($driver, 'Datatree') === 0) {
$dt_driver = $GLOBALS['conf']['datatree']['driver'];
array_merge(Horde::getDriverConfig('datatree', $dt_driver), array('group' => 'horde.perms'))
);
} elseif (strcasecmp($driver, 'Sql') === 0) {
- $write_db = $injector->getInstance('Horde_Db_Pear')->getOb();
-
- /* Check if we need to set up the read DB connection
- * separately. */
- if (empty($params['splitread'])) {
- $params['db'] = $write_db;
- } else {
- $params['write_db'] = $write_db;
- $params['db'] = $injector->getInstance('Horde_Db_Pear')->getOb('read');
- }
+ $params['db'] = $injector->getInstance('Horde_Db_Adapter_Base');
}
- $params = array_merge($params, array(
- 'cache' => $injector->getInstance('Horde_Cache'),
- 'logger' => $injector->getInstance('Horde_Log_Logger')
- ));
+ $params['cache'] = $injector->getInstance('Horde_Cache');
+ $params['logger'] = $injector->getInstance('Horde_Log_Logger');
return Horde_Perms::factory($driver, $params);
}
: array();
if (strcasecmp($driver, 'Sql') === 0) {
- $write_db = $injector->getInstance('Horde_Db_Pear')->getOb();
-
- /* Check if we need to set up the read DB connection
- * separately. */
- if (empty($params['splitread'])) {
- $params['db'] = $write_db;
- } else {
- $params['write_db'] = $write_db;
- $params['db'] = $injector->getInstance('Horde_Db_Pear')->getOb('read');
- }
+ $params['db'] = $injector->getInstance('Horde_Db_Adapter_Base');
} elseif (strcasecmp($driver, 'None') === 0) {
$driver = 'Null';
}
// Create the database-specific (but not adapter specific) schema
// object.
- if (!$this->_schemaClass)
- $this->_schemaClass = get_class($this).'_Schema';
+ if (!$this->_schemaClass) {
+ $this->_schemaClass = __CLASS__ . '_Schema';
+ }
$this->_schema = new $this->_schemaClass($this, array(
'cache' => $this->_cache,
- 'logger' => $this->_logger));
+ 'logger' => $this->_logger
+ ));
$this->_schemaMethods = array_flip(get_class_methods($this->_schema));
$this->connect();
public function componentFactory($component, $args)
{
$class = str_replace('_Schema', '', $this->_schemaClass) . '_' . $component;
- if (class_exists($class)) {
- $class = new ReflectionClass($class);
- } else {
- $class = new ReflectionClass('Horde_Db_Adapter_Base_' . $component);
- }
+ $class = new ReflectionClass(class_exists($class) ? $class : __CLASS__ . '_' . $component);
return $class->newInstanceArgs($args);
}
return call_user_func_array(array($this->_schema, $method), $args);
}
- throw new BadMethodCallException('Call to undeclared method "'.$method.'"');
+ throw new BadMethodCallException('Call to undeclared method "' . $method . '"');
}
}
/**
+ * @return string
+ */
+ public function adapterName()
+ {
+ return 'PDO_Oci';
+ }
+
+ /**
* Get a description of the database table that $model is going to
* reflect.
*/
/**
* Handle for the current database connection.
*
- * @var DB
+ * @var Horde_Db_Adapter_Base
*/
private $_db;
/**
- * Handle for the current database connection, used for writing. Defaults
- * to the same handle as $_db if a separate write database isn't required.
- *
- * @var DB
- */
- private $_write_db;
-
- /**
* Constructor.
*
* @param array $params Parameters:
* <pre>
- * 'db' - (DB) [REQUIRED] The DB instance.
+ * 'db' - (Horde_Db_Adapter_Base) [REQUIRED] The DB instance.
* 'table' - (string) The name of the lock table in 'database'.
* DEFAULT: 'horde_locks'
- * 'write_db' - (DB) The write DB instance.
* </pre>
*
* @throws Horde_Lock_Exception
throw new Horde_Lock_Exception('Missing db parameter.');
}
$this->_db = $params['db'];
-
- $this->_write_db = isset($params['write_db'])
- ? $params['write_db']
- : $this->_db;
-
- unset($params['db'], $params['write_db']);
+ unset($params['db']);
$params = array_merge(array(
'table' => 'horde_locks'
/* Only do garbage collection if asked for, and then only 0.1% of the
* time we create an object. */
if (rand(0, 999) == 0) {
- register_shutdown_function(array($this, '_doGC'));
+ register_shutdown_function(array($this, 'doGC'));
}
}
' WHERE lock_id = ? AND lock_expiry_timestamp >= ?';
$values = array($lockid, $now);
- if ($this->_logger) {
- $this->_logger->log('SQL Query by Horde_Lock_sql::getLockInfo(): ' . $sql, 'DEBUG');
- }
-
- $result = $this->_db->query($sql, $values);
- if ($result instanceof PEAR_Error) {
- throw new Horde_Lock_Exception($result);
- }
-
- $locks = array();
- $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
- if ($row instanceof PEAR_Error) {
- return false;
+ try {
+ return $this->_db->selectOne($sql, $values);
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Lock_Exception($e);
}
-
- $result->free();
- return $row;
}
/**
$values[] = $type;
}
- if ($this->_logger) {
- $this->_logger->log('SQL Query by Horde_Lock_sql::getLocks(): ' . $sql, 'DEBUG');
- }
-
- $result = $this->_db->query($sql, $values);
- if ($result instanceof PEAR_Error) {
- throw new Horde_Lock_Exception($result);
+ try {
+ $result = $this->_db->selectAll($sql, $values);
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Lock_Exception($e);
}
$locks = array();
- $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
- while ($row && !($row instanceof PEAR_Error)) {
+ foreach ($result as $val) {
$locks[$row['lock_id']] = $row;
- /* Advance to the new row in the result set. */
- $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
}
- $result->free();
return $locks;
}
'WHERE lock_id = ?';
$values = array($now, $expiry, $lockid);
- if ($this->_logger) {
- $this->_logger->log('SQL Query by Horde_Lock_sql::resetLock(): ' . $sql, 'DEBUG');
- }
-
- $result = $this->_write_db->query($sql, $values);
- if ($result instanceof PEAR_Error) {
- throw new Horde_Lock_Exception($result);
- }
-
- if ($this->_logger) {
- $this->_logger->log(sprintf('Lock %s reset successfully.', $lockid), 'DEBUG');
+ try {
+ $this->_db->update($sql, $values);
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Lock_Exception($e);
}
return true;
$values = array($lockid, $requestor, $scope, $principal, $now, $now,
$expiration, $type);
- if ($this->_logger) {
- $this->_logger->log('SQL Query by Horde_Lock_sql::setLock(): ' . $sql, 'DEBUG');
- }
-
- $result = $this->_write_db->query($sql, $values);
- if ($result instanceof PEAR_Error) {
- throw new Horde_Lock_Exception($result);
+ try {
+ $this->_db->insert($sql, $values);
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Lock_Exception($e);
}
if ($this->_logger) {
$sql = 'DELETE FROM ' . $this->_params['table'] . ' WHERE lock_id = ?';
$values = array($lockid);
- if ($this->_logger) {
- $this->_logger->log('SQL Query by Horde_Lock_sql::clearLock(): ' . $sql, 'DEBUG');
- }
-
- $result = $this->_write_db->query($sql, $values);
- if ($result instanceof PEAR_Error) {
- throw new Horde_Lock_Exception($result);
+ try {
+ $this->_db->delete($sql, $values);
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Lock_Exception($e);
}
if ($this->_logger) {
/**
* Do garbage collection needed for the driver.
*/
- private function _doGC()
+ public function doGC()
{
$now = time();
$query = 'DELETE FROM ' . $this->_params['table'] . ' WHERE ' .
'lock_expiry_timestamp < ? AND lock_expiry_timestamp != 0';
$values = array($now);
- $result = $this->_write_db->query($query, $values);
- if ($this->_logger) {
- $this->_logger->log('SQL Query by Horde_Lock_sql::_doGC(): ' . $sql, 'DEBUG');
- if ($result instanceof PEAR_Error) {
- $this->_logger->log($result, 'ERR');
- } else {
- $this->_logger->log(sprintf('Lock garbage collection cleared %d locks.', $this->_write_db->affectedRows()), 'DEBUG');
+ try {
+ $result = $this->_db->delete($query, $values);
+ if ($this->_logger) {
+ $this->_logger->log(sprintf('Lock garbage collection cleared %d locks.', $result), 'DEBUG');
}
- }
+ } catch (Horde_Db_Exception $e) {}
}
}
<min>1.7.0</min>
</pearinstaller>
<package>
+ <name>Exception</name>
+ <channel>pear.horde.org</channel>
+ </package>
+ <package>
<name>Support</name>
<channel>pear.horde.org</channel>
</package>
</required>
<optional>
<package>
+ <name>Db</name>
+ <channel>pear.horde.org</channel>
+ </package>
+ <package>
<name>Log</name>
<channel>pear.horde.org</channel>
</package>
}
$query = 'UPDATE horde_perms SET perm_data = ? WHERE perm_id = ?';
$params = array(serialize($this->data), $this->getId());
- $result = $this->_write_db->query($query, $params);
- if ($result instanceof PEAR_Error) {
- throw new Horde_Perms_Exception($result);
+
+ try {
+ $this->_write_db->update($query, $params);
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Perms_Exception($e);
}
$cache = $GLOBALS['injector']->getInstance('Horde_Cache');
/**
* Handle for the current database connection.
*
- * @var DB
+ * @var Horde_Db_Adapter_Base
*/
protected $_db;
/**
- * Handle for the current database connection, used for writing. Defaults
- * to the same handle as $db if a separate write database is not required.
- *
- * @var DB
- */
- protected $_write_db;
-
- /**
* Incrementing version number if cached classes change.
*
* @var integer
* @param array $params Configuration parameters (in addition to base
* Horde_Perms parameters):
* <pre>
- * 'db' - (DB) [REQUIRED] The DB instance.
- * 'table' - (string) The name of the perms table in 'database'.
+ * 'db' - (Horde_Db_Adapter_Base) [REQUIRED] The DB instance.
+ * 'table' - (string) The name of the perms table.
* DEFAULT: 'horde_perms'
- * 'write_db' - (DB) The write DB instance.
* </pre>
*
* @throws Horde_Perms_Exception
throw new Horde_Perms_Exception('Missing db parameter.');
}
$this->_db = $params['db'];
-
- $this->_write_db = isset($params['write_db'])
- ? $params['write_db']
- : $this->_db;
-
- unset($params['db'], $params['write_db']);
+ unset($params['db']);
$this->_params = array_merge(array(
'table' => 'horde_perms'
if (empty($perm)) {
$query = 'SELECT perm_id, perm_data FROM ' .
$this->_params['table'] . ' WHERE perm_name = ?';
- $result = $this->_db->getRow($query, array($name), DB_FETCHMODE_ASSOC);
- if ($result instanceof PEAR_Error) {
- throw new Horde_Perms_Exception($result);
- } elseif (empty($result)) {
+ try {
+ $result = $this->_db->selectOne($query, array($name));
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Perms_Exception($e);
+ }
+
+ if (empty($result)) {
throw new Horde_Perms_Exception('Does not exist');
}
$this->_permsCache[$name] = unserialize($perm);
}
- $this->_permsCache[$name]->setSQLOb($this->_write_db);
+ $this->_permsCache[$name]->setSQLOb($this->_db);
return $this->_permsCache[$name];
}
} else {
$query = 'SELECT perm_name, perm_data FROM ' .
$this->_params['table'] . ' WHERE perm_id = ?';
- $result = $this->_db->getRow($query, array($id), DB_FETCHMODE_ASSOC);
- if ($result instanceof PEAR_Error) {
- throw new Horde_Perms_Exception($result);
- } elseif (empty($result)) {
+ try {
+ $result = $this->_db->selectOne($query, array($id));
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Perms_Exception($e);
+ }
+
+ if (empty($result)) {
throw new Horde_Perms_Exception('Does not exist');
}
$object = new Horde_Perms_Permission_SqlObject($result['perm_name'], $this->_cacheVersion);
$object->setId($id);
$object->setData(unserialize($result['perm_data']));
- $object->setSQLOb($this->_write_db);
+ $object->setSQLOb($this->_db);
}
return $object;
*
* @param Horde_Perms_Permission_SqlObject $perm The perm object.
*
- * @return TODO
+ * @return integer Permission ID in the database.
* @throws Horde_Perms_Exception
*/
public function addPermission(Horde_Perms_Permission_SqlObject $perm)
$this->_cache->expire('perm_sql' . $this->_cacheVersion . $name);
$this->_cache->expire('perm_sql_exists_' . $this->_cacheVersion . $name);
- $id = $this->_write_db->nextId($this->_params['table']);
-
// remove root from the name
$root = Horde_Perms::ROOT . ':';
if (substr($name, 0, strlen($root)) == ($root)) {
}
$query = 'INSERT INTO ' . $this->_params['table'] .
- ' (perm_id, perm_name, perm_parents) VALUES (?, ?, ?)';
- $perm->setId($id);
+ ' (perm_name, perm_parents) VALUES (?, ?)';
- $result = $this->_write_db->query($query, array($id, $name, $parents));
- if ($result instanceof PEAR_Error) {
- throw new Horde_Perms_Exception($result);
+ try {
+ $id = $this->_db->insert($query, array($name, $parents));
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Perms_Exception($e);
}
- $perm->setSQLOb($this->_write_db);
+ $perm->setId($id);
$perm->save();
return $id;
*
* @param Horde_Perms_Permission_SqlObject $perm The permission to
* remove.
- * @param boolean $force Force to remove ever
+ * @param boolean $force Force to remove every
* child.
*
- * @return TODO
+ * @return boolean True if permission was deleted.
* @throws Horde_Perms_Exception
*/
- public function removePermission(Horde_Perms_Permission_SqlObject $perm, $force = false)
+ public function removePermission(Horde_Perms_Permission_SqlObject $perm,
+ $force = false)
{
$name = $perm->getName();
$this->_cache->expire('perm_sql' . $this->_cacheVersion . $name);
$query = 'DELETE FROM ' . $this->_params['table'] .
' WHERE perm_name = ?';
- $result = $this->_write_db->query($query, array($name));
- if ($result instanceof PEAR_Error) {
- throw new Horde_Perms_Exception($result);
- } elseif ($force) {
- return $result;
+
+ try {
+ $result = $this->_db->delete($query, array($name));
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Perms_Exception($e);
+ }
+
+ if ($force) {
+ return (bool)$result;
}
$query = 'DELETE FROM ' . $this->_params['table'] .
' WHERE perm_name LIKE ?';
- return $this->_write_db->query($query, array($name . ':%'));
+
+ try {
+ return (bool)$this->_db->delete($query, array($name . ':%'));
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Perms_Exception($e);
+ }
}
/**
* Returns the unique identifier of this permission.
*
* @param Horde_Perms_Permission_SqlObject $perm The permission object to
- * get the ID of.
+ * get the ID of.
*
* @return integer The unique id.
+ * @throws Horde_Perms_Exception
*/
public function getPermissionId($permission)
{
$query = 'SELECT perm_id FROM ' . $this->_params['table'] .
' WHERE perm_name = ?';
- return $this->_db->getOne($query, array($permission->getName()));
+
+ try {
+ return $this->_db->selectValue($query, array($permission->getName()));
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Perms_Exception($e);
+ }
}
/**
if ($exists === false) {
$query = 'SELECT COUNT(*) FROM ' . $this->_params['table'] .
' WHERE perm_name = ?';
- $exists = $this->_db->getOne($query, array($permission));
- if ($exists instanceof PEAR_Error) {
- throw new Horde_Perms_Exception($exists);
+
+ try {
+ $exists = $this->_db->selectValue($query, array($permission));
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Perms_Exception($e);
}
$this->_cache->set($key, (string)$exists);
{
$query = 'SELECT perm_parents FROM ' . $this->_params['table'] .
' WHERE perm_name = ?';
- $parents = $this->_db->getOne($query, array($child));
- if ($parents instanceof PEAR_Error) {
- throw new Horde_Perms_Exception($parents);
+ try {
+ $parents = $this->_db->selectValue($query, array($child));
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Perms_Exception($e);
}
if (empty($parents)) {
}
$parents = explode(':', $parents);
+
return array_pop($parents);
}
{
$query = 'SELECT perm_parents FROM ' . $this->_params['table'] .
' WHERE perm_name = ?';
- $result = $this->_db->getOne($query, array($child));
- if ($result instanceof PEAR_Error) {
- throw new Horde_Perms_Exception($result);
- } elseif (empty($result)) {
+
+ try {
+ $result = $this->_db->selectValue($query, array($child));
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Perms_Exception($e);
+ }
+
+ if (empty($result)) {
throw new Horde_Perms_Exception('Does not exist');
}
{
$query = 'SELECT perm_id, perm_name FROM ' . $this->_params['table'] .
' ORDER BY perm_name ASC';
- $tree = $this->_db->getAssoc($query);
- if ($tree instanceof PEAR_Error) {
- throw new Horde_Perms_Exception($tree);
+
+ try {
+ $tree = $this->_db->selectAssoc($query);
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Perms_Exception($e);
}
$tree[Horde_Perms::ROOT] = Horde_Perms::ROOT;
+
return $tree;
}
class Horde_Token_Sql extends Horde_Token_Driver
{
/**
- * Handle for the current database connection.
+ * Handle for the database connection.
*
- * @var DB
+ * @var Horde_Db_Adapter_Base
*/
- protected $_db = '';
-
- /**
- * Handle for the current database connection, used for writing. Defaults
- * to the same handle as $_db if a separate write database is not required.
- *
- * @var DB
- */
- protected $_write_db;
+ protected $_db;
/**
* Constructor.
*
* @param array $params Parameters:
* <pre>
- * 'db' - (DB) [REQUIRED] The DB instance.
- * 'table' - (string) The name of the tokens table in 'database'.
+ * 'db' - (Horde_Db_Adapter_Base) [REQUIRED] The DB instance.
+ * 'table' - (string) The name of the tokens table.
* DEFAULT: 'horde_tokens'
* 'timeout' - (integer) The period (in seconds) after which an id is
* purged.
* DEFAULT: 86400 (24 hours)
- * 'write_db' - (DB) The write DB instance.
* </pre>
*
* @throws Horde_Token_Exception
throw new Horde_Token_Exception('Missing db parameter.');
}
$this->_db = $params['db'];
-
- if (isset($params['write_db'])) {
- $this->_write_db = $params['write_db'];
- } else {
- $this->_write_db = $this->_db;
- }
-
- unset($params['db'], $params['write_db']);
+ unset($params['db']);
$params = array_merge(array(
'table' => 'horde_tokens',
$values = array(time() - $this->_params['timeout']);
/* Return an error if the update fails. */
- $result = $this->_write_db->query($query, $values);
- if ($result instanceof PEAR_Error) {
- if ($this->_logger) {
- $this->_logger->log($result, 'ERR');
- }
- throw new Horde_Token_Exception($result);
+ try {
+ $this->_db->delete($query, $values);
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Token_Exception($e);
}
}
$values = array($this->_encodeRemoteAddress(), $tokenID);
- $result = $this->_db->getOne($query, $values);
- if ($result instanceof PEAR_Error) {
- if ($this->_logger) {
- $this->_logger->log($result, 'ERR');
- }
+ try {
+ return $this->_db->selectValue($query, $values);
+ } catch (Horde_Db_Exception $e) {
return false;
}
-
- return !empty($result);
}
/**
$values = array($this->_encodeRemoteAddress(), $tokenID, time());
- $result = $this->_write_db->query($query, $values);
- if ($result instanceof PEAR_Error) {
- if ($this->_logger) {
- $this->_logger->log($result, 'ERR');
- }
- throw new Horde_Token_Exception($result);
+ try {
+ $this->_db->insert($query, $values);
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Token_Exception($e);
}
}
</required>
<optional>
<package>
- <name>DB</name>
- <channel>pear.php.net</channel>
+ <name>Db</name>
+ <channel>pear.horde.org</channel>
</package>
<package>
<name>Log</name>
$params = Horde::getDriverConfig('sentmail', $driver);
if (strcasecmp($driver, 'Sql') === 0) {
- $write_db = $injector->getInstance('Horde_Db_Pear')->getOb();
-
- /* Check if we need to set up the read DB connection
- * separately. */
- if (empty($params['splitread'])) {
- $params['db'] = $write_db;
- } else {
- $params['write_db'] = $write_db;
- $params['db'] = $injector->getInstance('Horde_Db_Pear')->getOb('read');
- }
+ $params['db'] = $injector->getInstance('Horde_Db_Adapter_Base');
} elseif (strcasecmp($driver, 'None') === 0) {
$driver = 'Null';
}
/**
* Handle for the current database connection.
*
- * @var DB
+ * @var Horde_Db_Adapter_Base
*/
- protected $_db = '';
-
- /**
- * Handle for the current database connection, used for writing. Defaults
- * to the same handle as $_db if a separate write database is not required.
- *
- * @var DB
- */
- protected $_write_db;
+ protected $_db;
/**
* Constructor.
*
* @param array $params Parameters:
* <pre>
- * 'db' - (DB) [REQUIRED] The DB instance.
+ * 'db' - (Horde_Db_Adapter_Base) [REQUIRED] The DB instance.
* 'table' - (string) The name of the sentmail table.
* DEFAULT: 'imp_sentmail'
- * 'write_db' - (DB) The write DB instance.
* </pre>
*
* @throws IMP_Exception
throw new IMP_Exception('Missing db parameter.');
}
$this->_db = $params['db'];
-
- $this->_write_db = isset($params['write_db'])
- ? $params['write_db']
- : $this->_db;
-
- unset($params['db'], $params['write_db']);
+ unset($params['db']);
$params = array_merge(array(
'table' => 'imp_sentmail'
protected function _log($action, $message_id, $recipient, $success)
{
/* Build the SQL query. */
- $query = sprintf('INSERT INTO %s (sentmail_id, sentmail_who, sentmail_ts, sentmail_messageid, sentmail_action, sentmail_recipient, sentmail_success) VALUES (?, ?, ?, ?, ?, ?, ?)',
- $this->_params['table']);
- $values = array($this->_db->nextId($this->_params['table']),
- Horde_Auth::getAuth(),
- time(),
- $message_id,
- $action,
- $recipient,
- intval($success));
-
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('IMP_Sentmail_Sql::_log(): %s', $query), 'DEBUG');
+ $query = sprintf('INSERT INTO %s (sentmail_who, sentmail_ts, sentmail_messageid, sentmail_action, sentmail_recipient, sentmail_success) VALUES (?, ?, ?, ?, ?, ?)', $this->_params['table']);
+ $values = array(
+ Horde_Auth::getAuth(),
+ time(),
+ $message_id,
+ $action,
+ $recipient,
+ intval($success)
+ );
/* Execute the query. */
- $result = $this->_write_db->query($query, $values);
-
- /* Log errors. */
- if ($result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- }
+ $this->_db->insert($query, $values);
}
/**
$where = sprintf(' AND sentmail_action in (%s)',
implode(', ', $filter));
}
+
$query = sprintf('SELECT sentmail_recipient, count(*) AS sentmail_count FROM %s WHERE sentmail_who = %s AND sentmail_success = 1%s GROUP BY sentmail_recipient ORDER BY sentmail_count DESC LIMIT %d',
$this->_params['table'],
$this->_db->quote(Horde_Auth::getAuth()),
$where,
$limit);
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('IMP_Sentmail_Sql::favouriteRecipients(): %s', $query), 'DEBUG');
-
/* Execute the query. */
- $recipients = $this->_db->getAll($query);
- if ($recipients instanceof PEAR_Error) {
- Horde::logMessage($recipients, 'ERR');
- throw new IMP_Exception($recipients);
+ try {
+ return $this->_db->selectValues($query);
+ } catch (Horde_Db_Exception $e) {
+ throw new IMP_Exception($e);
}
-
- /* Extract email addresses. */
- $favourites = array();
- foreach ($recipients as $recipient) {
- $favourites[] = reset($recipient);
- }
-
- return $favourites;
}
/**
$query .= sprintf(' AND sentmail_who = %s', $this->_db->quote(Horde_Auth::getAuth()));
}
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('IMP_Sentmail_Sql::numberOfRecipients(): %s', $query), 'DEBUG');
-
/* Execute the query. */
- $recipients = $this->_db->getOne($query, array(time() - $hours * 3600));
- if ($recipients instanceof PEAR_Error) {
- Horde::logMessage($recipients, 'ERR');
- throw new IMP_Exception($recipients);
+ try {
+ return $this->_db->selectValue($query, array(time() - $hours * 3600));
+ } catch (Horde_Db_Exception $e) {
+ throw new IMP_Exception($e);
}
-
- return $recipients;
}
/**
$query = sprintf('DELETE FROM %s WHERE sentmail_ts < ?',
$this->_params['table']);
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('IMP_Sentmail_Sql::_deleteOldEntries(): %s', $query), 'DEBUG');
-
/* Execute the query. */
- $result = $this->_write_db->query($query, array($before));
- if ($result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- }
+ try {
+ $this->_db->delete($query, array($before));
+ } catch (Horde_Db_Exception $e) {}
}
}