*
* @access private
*
- * @return boolean True on success; exits (Horde::fatal()) on error.
+ * @return boolean True on success.
*/
function _connect()
{
return true;
}
- try {
- $result = Horde::assertDriverConfig($this->_params, 'pdnsqsql', array('phptype'), 'PowerDNS Generic SQL');
- } catch (Exception $e) {
- Horde::logMessage($e, 'ERR');
- throw $e;
- }
-
- /* Connect to the SQL server using the supplied parameters. */
- require_once 'DB.php';
- $this->_write_db = &DB::connect($this->_params,
- array('persistent' => !empty($this->_params['persistent'])));
- if (is_a($this->_write_db, 'PEAR_Error')) {
- Horde::fatal($this->_write_db, __FILE__, __LINE__);
- }
-
- // Set DB portability options.
- switch ($this->_write_db->phptype) {
- case 'mssql':
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
- /* Check if we need to set up the read DB connection seperately. */
- if (!empty($this->_params['splitread'])) {
- $params = array_merge($this->_params, $this->_params['read']);
- $this->_db = &DB::connect($params,
- array('persistent' => !empty($params['persistent'])));
- if (is_a($this->_db, 'PEAR_Error')) {
- Horde::fatal($this->_db, __FILE__, __LINE__);
- }
-
- // Set DB portability options.
- switch ($this->_db->phptype) {
- case 'mssql':
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
- } else {
- /* Default to the same DB handle for the writer too. */
- $this->_db =& $this->_write_db;
- }
-
- $this->_connected = true;
+ $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'beatnik', 'storage');
+ $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'beatnik', 'storage');
return true;
}
*
* @access private
*
- * @return boolean True on success; exits (Horde::fatal()) on error.
+ * @return boolean True on success.
*/
function _connect()
{
return true;
}
- Horde::assertDriverConfig($this->_params, 'storage',
- array('phptype', 'charset'));
-
- if (!isset($this->_params['database'])) {
- $this->_params['database'] = '';
- }
- if (!isset($this->_params['username'])) {
- $this->_params['username'] = '';
- }
- if (!isset($this->_params['hostspec'])) {
- $this->_params['hostspec'] = '';
- }
-
- /* Connect to the SQL server using the supplied parameters. */
- require_once 'DB.php';
- $this->_write_db = &DB::connect($this->_params,
- array('persistent' => !empty($this->_params['persistent'])));
- if (is_a($this->_write_db, 'PEAR_Error')) {
- Horde::fatal($this->_write_db, __FILE__, __LINE__);
- }
-
- // Set DB portability options.
- switch ($this->_write_db->phptype) {
- case 'mssql':
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
- /* Check if we need to set up the read DB connection seperately. */
- if (!empty($this->_params['splitread'])) {
- $params = array_merge($this->_params, $this->_params['read']);
- $this->_db = &DB::connect($params,
- array('persistent' => !empty($params['persistent'])));
- if (is_a($this->_db, 'PEAR_Error')) {
- Horde::fatal($this->_db, __FILE__, __LINE__);
- }
-
- // Set DB portability options.
- switch ($this->_db->phptype) {
- case 'mssql':
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
- } else {
- /* Default to the same DB handle for the writer too. */
- $this->_db =& $this->_write_db;
- }
-
- $this->_connected = true;
+ $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'beatnik', 'storage');
+ $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'beatnik', 'storage');
return true;
}
return true;
}
- Horde::assertDriverConfig($this->_params, 'storage',
- array('phptype', 'charset', 'table'));
-
- if (!isset($this->_params['database'])) {
- $this->_params['database'] = '';
- }
- if (!isset($this->_params['username'])) {
- $this->_params['username'] = '';
- }
- if (!isset($this->_params['hostspec'])) {
- $this->_params['hostspec'] = '';
- }
-
- /* Connect to the SQL server using the supplied parameters. */
- require_once 'DB.php';
- $this->_write_db = &DB::connect($this->_params,
- array('persistent' => !empty($this->_params['persistent'])));
- if (is_a($this->_write_db, 'PEAR_Error')) {
- throw new Horde_Exception_Prior($this->_write_db);
- }
-
- // Set DB portability options.
- switch ($this->_write_db->phptype) {
- case 'mssql':
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
- /* Check if we need to set up the read DB connection seperately. */
- if (!empty($this->_params['splitread'])) {
- $params = array_merge($this->_params, $this->_params['read']);
- $this->_db = &DB::connect($params,
- array('persistent' => !empty($params['persistent'])));
- if (is_a($this->_db, 'PEAR_Error')) {
- throw new Horde_Exception_Prior($this->_write_db);
- }
-
- // Set DB portability options.
- switch ($this->_db->phptype) {
- case 'mssql':
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
- } else {
- /* Default to the same DB handle for the writer too. */
- $this->_db =& $this->_write_db;
- }
-
- $this->_connected = true;
+ $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'crumb', 'storage');
+ $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'crumb', 'storage');
return true;
}
*/
function initialize()
{
- Horde::assertDriverConfig($this->_params, 'storage',
- array('phptype', 'charset'));
-
- if (!isset($this->_params['database'])) {
- $this->_params['database'] = '';
- }
- if (!isset($this->_params['username'])) {
- $this->_params['username'] = '';
- }
- if (!isset($this->_params['hostspec'])) {
- $this->_params['hostspec'] = '';
- }
-
- /* Connect to the SQL server using the supplied parameters. */
- require_once 'DB.php';
- $this->_db = &DB::connect($this->_params,
- array('persistent' => !empty($this->_params['persistent'])));
- if (is_a($this->_db, 'PEAR_Error')) {
- return $this->_db;
- }
-
- /* Set DB portability options. */
- switch ($this->_db->phptype) {
- case 'mssql':
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
+ try {
+ $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'fima', 'storage');
+ } catch (Horde_Exception $e) {
+ return PEAR::raiseError($e->getMessage());
}
- $this->_connected = true;
-
return true;
}
* Attempts to open a persistent connection to the SQL server.
*
* @return boolean True on success.
+ * @throws Horde_Exception
*/
private function _connect()
{
- Horde::assertDriverConfig($this->_params, 'storage',
- array('phptype', 'charset', 'table'));
-
- if (!isset($this->_params['database'])) {
- $this->_params['database'] = '';
- }
- if (!isset($this->_params['username'])) {
- $this->_params['username'] = '';
- }
- if (!isset($this->_params['hostspec'])) {
- $this->_params['hostspec'] = '';
- }
-
- /* Connect to the SQL server using the supplied parameters. */
- require_once 'DB.php';
- $this->_write_db = DB::connect($this->_params,
- array('persistent' => !empty($this->_params['persistent'])));
- if ($this->_write_db instanceof PEAR_Error) {
- throw new Horde_Exception_Prior($this->_write_db);
- }
-
- // Set DB portability options.
- switch ($this->_write_db->phptype) {
- case 'mssql':
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
- /* Check if we need to set up the read DB connection seperately. */
- if (!empty($this->_params['splitread'])) {
- $params = array_merge($this->_params, $this->_params['read']);
- $this->_db = DB::connect($params,
- array('persistent' => !empty($params['persistent'])));
- if ($this->_db instanceof PEAR_Error) {
- throw new Horde_Exception_Prior($this->_db);
- }
-
- // Set DB portability options.
- switch ($this->_db->phptype) {
- case 'mssql':
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
- } else {
- /* Default to the same DB handle for the writer too. */
- $this->_db =& $this->_write_db;
- }
+ $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'folks', 'storage');
+ $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'folks', 'storage');
return true;
}
* Attempts to open a persistent connection to the SQL server.
*
* @return boolean True on success.
+ * @throws Horde_Exception
*/
protected function _connect()
{
- $this->_params = Horde::getDriverConfig('storage', 'sql');
+ $this->_params = array_merge(array(
+ 'blacklist' => 'folks_blacklist',
+ 'friends' => 'folks_friends'
+ ), $this->_params);
- if (!isset($this->_params['database'])) {
- $this->_params['database'] = '';
- }
- if (!isset($this->_params['username'])) {
- $this->_params['username'] = '';
- }
- if (!isset($this->_params['hostspec'])) {
- $this->_params['hostspec'] = '';
- }
- if (!isset($this->_params['friends'])) {
- $this->_params['friends'] = 'folks_friends';
- }
- if (!isset($this->_params['blacklist'])) {
- $this->_params['blacklist'] = 'folks_blacklist';
- }
-
- /* Connect to the SQL server using the supplied parameters. */
- require_once 'DB.php';
- $this->_write_db = DB::connect($this->_params,
- array('persistent' => !empty($this->_params['persistent'])));
- if ($this->_write_db instanceof PEAR_Error) {
- throw new Horde_Exception_Prior($this->_write_db);
- }
-
- // Set DB portability options.
- switch ($this->_write_db->phptype) {
- case 'mssql':
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
- /* Check if we need to set up the read DB connection seperately. */
- if (!empty($this->_params['splitread'])) {
- $params = array_merge($this->_params, $this->_params['read']);
- $this->_db = DB::connect($params,
- array('persistent' => !empty($params['persistent'])));
- if ($this->_db instanceof PEAR_Error) {
- throw new Horde_Exception_Prior($this->_db);
- }
-
- // Set DB portability options.
- switch ($this->_db->phptype) {
- case 'mssql':
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
- } else {
- /* Default to the same DB handle for the writer too. */
- $this->_db =& $this->_write_db;
- }
+ $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'folks', 'storage');
+ $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'folks', 'storage');
return true;
}
* Return the DB instance.
*
* @param string $type Either 'read' or 'rw'.
+ * @param string $app The application.
+ * @param mixed $type The type. If this is an array, this is used as
+ * the configuration array.
*
* @return DB The singleton DB instance.
* @throws Horde_Exception
*/
- public function getDb($type = 'rw')
+ public function getDb($type = 'rw', $app = 'horde', $type = null)
{
- if (isset($this->_instances[$type])) {
- return $this->_instances[$type];
+ global $registry;
+
+ $sig = hash('md5', serialize($type . '|' . $app . '|' . $type));
+
+ if (isset($this->_instances[$sig])) {
+ return $this->_instances[$sig];
+ }
+
+ $pushed = ($app == 'horde')
+ ? false
+ : $registry->pushApp($app);
+
+ $config = is_array($type)
+ ? $type
+ : $this->getConfig($type);
+
+ /* Determine if we we are not using splitread or if we are using the
+ * base SQL config. */
+ if ((($type == 'read') && empty($config['splitread'])) ||
+ (isset($config['driverconfig']) &&
+ ($config['driverconfig'] == 'horde'))) {
+ $this->_instances[$sig] = $this->getDb($type);
+ return $this->_instances[$sig];
}
- $params = array_merge(array(
- 'database' => '',
- 'hostspec' => '',
- 'password' => '',
- 'username' => ''
- ), $GLOBALS['conf']['sql']);
if ($type == 'read') {
- $params = array_merge($params, $params['read']);
+ $config = array_merge($config, $config['read']);
}
- Horde::assertDriverConfig($params, 'sql', array('charset', 'phptype'), 'SQL');
+ Horde::assertDriverConfig($config, 'sql', array('charset', 'phptype'));
/* Connect to the SQL server using the supplied parameters. */
- $db = DB::connect($params, array(
- 'persistent' => !empty($params['persistent']),
- 'ssl' => !empty($params['ssl'])
+ $db = DB::connect($config, array(
+ 'persistent' => !empty($config['persistent']),
+ 'ssl' => !empty($config['ssl'])
));
if ($db instanceof PEAR_Error) {
+ if ($pushed) {
+ $registry->popApp();
+ }
throw new Horde_Exception($db);
}
break;
}
- $this->_instances[$type] = $db;
+ if ($pushed) {
+ $registry->popApp();
+ }
+
+ $this->_instances[$sig] = $db;
return $db;
}
+ /**
+ */
+ public function getConfig($type)
+ {
+ return Horde::getDriverConfig($type, 'sql');
+ }
+
}
? $conf['vfs']
: $conf[$name];
- if ($vfs['type'] == 'sql') {
- $vfs['params'] = Horde::getDriverConfig($name, 'sql');
+ switch ($vfs['type']) {
+ case 'sql':
+ $db_pear = $this->_injector->getInstance('Horde_Db_Pear');
+ $vfs['db'] = $db_pear->getDb('read', 'horde', 'vfs');
+ $vfs['writedb'] = $db_pear->getDb('rw', 'horde', 'vfs');
+ $vfs['params'] = $db_pear->getConfig('vfs');
+ break;
+
+ case 'sql_file':
+ $db_pear = $this->_injector->getInstance('Horde_Db_Pear');
+ $vfs['db'] = $db_pear->getDb('rw', 'horde', 'vfs');
+ $vfs['params'] = $db_pear->getConfig('vfs');
+ break;
}
return $vfs;
/**
* Attempts to open a connection to the SQL server.
*
- * @return boolean True.
+ * @return mixed True or PEAR_Error.
*/
function _init()
{
- Horde::assertDriverConfig($this->_params, 'sql',
- array('phptype', 'charset'),
- 'DataTree SQL');
-
- $default = array(
- 'database' => '',
- 'username' => '',
- 'password' => '',
- 'hostspec' => '',
+ try {
+ $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'datatree');
+ $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'datatree');
+ } catch (Horde_Exception $e) {
+ return PEAR::raiseError($e->getMessage());
+ }
+
+ $this->_params = array_merge(array(
'table' => 'horde_datatree',
'table_attributes' => 'horde_datatree_attributes',
- );
- $this->_params = array_merge($default, $this->_params);
-
- /* Connect to the SQL server using the supplied parameters. */
- require_once 'DB.php';
- $this->_write_db = DB::connect($this->_params,
- array('persistent' => !empty($this->_params['persistent']),
- 'ssl' => !empty($this->_params['ssl'])));
- if (is_a($this->_write_db, 'PEAR_Error')) {
- return $this->_write_db;
- }
-
- // Set DB portability options.
- $portability = DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS;
- if ($this->_write_db->phptype == 'mssql') {
- $portability |= DB_PORTABILITY_RTRIM;
- }
- $this->_write_db->setOption('portability', $portability);
-
- /* Check if we need to set up the read DB connection
- * seperately. */
- if (!empty($this->_params['splitread'])) {
- $params = array_merge($this->_params, $this->_params['read']);
- $this->_db = DB::connect($params,
- array('persistent' => !empty($params['persistent']),
- 'ssl' => !empty($params['ssl'])));
- if (is_a($this->_db, 'PEAR_Error')) {
- return $this->_db;
- }
-
- // Set DB portability options
- $portability = DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS;
- if ($this->_db->phptype == 'mssql') {
- $portability |= DB_PORTABILITY_RTRIM;
- }
- $this->_db->setOption('portability', $portability);
- } else {
- /* Default to the same DB handle for reads. */
- $this->_db = $this->_write_db;
- }
+ ), $this->_params);
return true;
}
function init($dsn, $sql, $prompt = null)
{
- require_once 'DB.php';
$values = array();
$db = DB::connect($dsn);
- if (!is_a($db, 'PEAR_Error')) {
+ if (!($db instanceof PEAR_Error)) {
// Set DB portability options.
switch ($db->phptype) {
case 'mssql':
$db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
break;
+
default:
$db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
}
$col = $db->getCol($sql);
- if (!is_a($col, 'PEAR_Error')) {
+ if (!($col instanceof PEAR_Error)) {
$values = array_combine($col, $col);
}
}
{
$values = array();
$db = DB::connect($dsn);
- if (!is_a($db, 'PEAR_Error')) {
+ if (!($db instanceof PEAR_Error)) {
// Set DB portability options.
switch ($db->phptype) {
case 'mssql':
$db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
break;
+
default:
$db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
+ break;
}
$col = $db->getCol($sql);
- if (!is_a($col, 'PEAR_Error')) {
+ if (!($col instanceof PEAR_Error)) {
$values = array_combine($col, $col);
}
}
* VFS implementation for PHP's PEAR database abstraction layer.
*
* Required values for $params:<pre>
- * phptype - (string) The database type (ie. 'pgsql', 'mysql', etc.).</pre>
+ * db - (DB) A DB object.
+ * </pre>
*
* Optional values:<pre>
* table - (string) The name of the vfs table in 'database'. Defaults to
- * 'horde_vfs'.</pre>
- *
- * Required by some database implementations:<pre>
- * hostspec - (string) The hostname of the database server.
- * protocol - (string) The communication protocol ('tcp', 'unix', etc.).
- * database - (string) The name of the database.
- * username - (string) The username with which to connect to the database.
- * password - (string) The password associated with 'username'.
- * options - (array) Additional options to pass to the database.
- * tty - (string) The TTY on which to connect to the database.
- * port - (integer) The port on which to connect to the database.</pre>
+ * 'horde_vfs'.
+ * </pre>
*
* Optional values when using separate reading and writing servers, for example
* in replication settings:<pre>
- * splitread - (boolean) Whether to implement the separation or not.
- * read - (array) Parameters which are different for the read database
- * connection, currently supported only 'hostspec' and 'port'
- * parameters.</pre>
+ * writedb - (DB) A writable DB object
+ * </pre>
*
* The table structure for the VFS can be found in data/vfs.sql.
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
- * @author Chuck Hagenbuch <chuck@horde.org>
- * @package VFS
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @category Horde
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @package VFS
*/
class VFS_sql extends VFS
{
protected function _connect()
{
if ($this->_connected) {
- return true;
+ return;
}
- if (!is_array($this->_params)) {
- throw new VFS_Exception('No configuration information specified for SQL VFS.');
- }
-
- $required = array('phptype');
- foreach ($required as $val) {
- if (!isset($this->_params[$val])) {
- throw new VFS_Exception(sprintf('Required "%s" not specified in VFS configuration.', $val));
- }
+ if (!isset($this->_params['db'])) {
+ throw new VFS_Exception('Required "db" not specified in VFS configuration.');
}
$this->_params = array_merge(array(
- 'database' => '',
- 'hostspec' => '',
- 'table' => 'horde_vfs',
- 'username' => ''
+ 'table' => 'horde_vfs'
), $this->_params);
- /* Connect to the SQL server using the supplied parameters. */
- require_once 'DB.php';
- $this->_write_db = DB::connect(
- $this->_params,
- array(
- 'persistent' => !empty($this->_params['persistent']),
- 'ssl' => !empty($this->_params['ssl']
- )
- ));
-
- if ($this->_write_db instanceof PEAR_Error) {
- $this->log($this->_write_db, PEAR_LOG_ERR);
- $error = new VFS_Exception($this->_write_db->getMessage());
- $this->_write_db = false;
- throw $error;
- }
-
- // Set DB portability options.
- switch ($this->_write_db->phptype) {
- case 'mssql':
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
- /* Check if we need to set up the read DB connection
- * seperately. */
- if (!empty($this->_params['splitread'])) {
- $params = array_merge($this->_params, $this->_params['read']);
- $this->_db = DB::connect(
- $params,
- array(
- 'persistent' => !empty($params['persistent']),
- 'ssl' => !empty($params['ssl']
- )
- ));
-
- if ($this->_db instanceof PEAR_Error) {
- throw new VFS_Exception($this->_db->getMessage());
- }
-
- // Set DB portability options.
- switch ($this->_db->phptype) {
- case 'mssql':
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
- } else {
- /* Default to the same DB handle for reads. */
- $this->_db =& $this->_write_db;
- }
+ $this->_db = $this->_params['db'];
+ $this->_write_db = isset($this->_params['writedb'])
+ ? $this->_params['writedb']
+ : $this->_params['db'];
$this->_connected = true;
}
* layer and local file system for file storage.
*
* Required values for $params:<pre>
- * phptype - (string) The database type (ie. 'pgsql', 'mysql', etc.).
+ * db - (DB) The DB object.
* vfsroot - (string) The root directory of where the files should be
* actually stored.</pre>
*
* table - (string) The name of the vfs table in 'database'. Defaults to
* 'horde_vfs'.</pre>
*
- * Required by some database implementations:<pre>
- * hostspec - (string) The hostname of the database server.
- * protocol - (string) The communication protocol ('tcp', 'unix', etc.).
- * database - (string) The name of the database.
- * username - (string) The username with which to connect to the database.
- * password - (string) The password associated with 'username'.
- * options - (array) Additional options to pass to the database.
- * tty - (string) The TTY on which to connect to the database.
- * port - (integer) The port on which to connect to the database.</pre>
+ * The table structure for the VFS can be found in data/vfs.sql.
*
- * The table structure for the VFS can be found in
- * data/vfs.sql.
- *
- * @author Michael Varghese <mike.varghese@ascellatech.com>
- * @package VFS
+ * @author Michael Varghese <mike.varghese@ascellatech.com>
+ * @category Horde
+ * @package VFS
*/
class VFS_sql_file extends VFS_file
{
return;
}
- if (!is_array($this->_params)) {
- throw new VFS_Exception('No configuration information specified for SQL-File VFS.');
- }
-
- $required = array('phptype', 'vfsroot');
+ $required = array('db', 'vfsroot');
foreach ($required as $val) {
if (!isset($this->_params[$val])) {
throw new VFS_Exception(sprintf('Required "%s" not specified in VFS configuration.', $val));
}
$this->_params = array_merge(array(
- 'database' => '',
- 'hostspec' => '',
'table' => 'horde_vfs',
- 'username' => ''
), $this->_params);
- /* Connect to the SQL server using the supplied parameters. */
- require_once 'DB.php';
- $this->_db = DB::connect(
- $this->_params,
- array(
- 'persistent' => !empty($this->_params['persistent']),
- 'ssl' => !empty($this->_params['ssl']
- )
- ));
- if ($this->_db instanceof PEAR_Error) {
- $error = new VFS_Exception($this->_db->getMessage());
- $this->_db = false;
- throw $error;
- }
-
- // Set DB portability options.
- switch ($this->_db->phptype) {
- case 'mssql':
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
-
- default:
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
+ $this->_db = $this->_params['db'];
}
/**
/**
* Attempts to open a persistent connection to the SQL server.
*
- * @return boolean True on success; exits (Horde::fatal()) on error.
+ * @return boolean True on success.
+ * @throws Horde_Exception
*/
function _connect()
{
- if (!$this->_connected) {
- Horde::assertDriverConfig($this->_params, 'storage',
- array('phptype'));
-
- if (!isset($this->_params['database'])) {
- $this->_params['database'] = '';
- }
- if (!isset($this->_params['username'])) {
- $this->_params['username'] = '';
- }
- if (!isset($this->_params['hostspec'])) {
- $this->_params['hostspec'] = '';
- }
-
- /* Connect to the SQL server using the supplied parameters. */
- include_once 'DB.php';
- $this->_db = &DB::connect($this->_params,
- array('persistent' => !empty($this->_params['persistent'])));
- if (is_a($this->_db, 'PEAR_Error')) {
- Horde::fatal($this->_db, __FILE__, __LINE__);
- }
-
- // Set DB portability options.
- switch ($this->_db->phptype) {
- case 'mssql':
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
- $this->_connected = true;
+ if ($this->_connected) {
+ return true;
}
+ $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'hermes', 'storage');
+
return true;
}
function initialise()
{
- global $registry;
-
- Horde::assertDriverConfig($this->_params, 'sql',
- array('phptype'));
-
- if (!isset($this->_params['database'])) {
- $this->_params['database'] = '';
- }
- if (!isset($this->_params['username'])) {
- $this->_params['username'] = '';
- }
- if (!isset($this->_params['hostspec'])) {
- $this->_params['hostspec'] = '';
- }
-
- /* Connect to the SQL server using the supplied parameters. */
- require_once 'DB.php';
- $this->_db = &DB::connect($this->_params,
- array('persistent' => !empty($this->_params['persistent'])));
- if (is_a($this->_db, 'PEAR_Error')) {
- Horde::fatal($this->_db, __FILE__, __LINE__);
- }
-
- // Set DB portability options
- switch ($this->_db->phptype) {
- case 'mssql':
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
+ $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'hylax', 'sql');
return true;
}
* Ingo_Storage_Sql implements the Ingo_Storage API to save Ingo data via
* PHP's PEAR database abstraction layer.
*
- * Required values for $params:<pre>
- * 'phptype' - The database type (e.g. 'pgsql', 'mysql', etc.).
- * 'charset' - The database's internal charset.</pre>
- *
- * Required by some database implementations:<pre>
- * 'database' - The name of the database.
- * 'hostspec' - The hostname of the database server.
- * 'protocol' - The communication protocol ('tcp', 'unix', etc.).
- * 'username' - The username with which to connect to the database.
- * 'password' - The password associated with 'username'.
- * 'options' - Additional options to pass to the database.
- * 'tty' - The TTY on which to connect to the database.
- * 'port' - The port on which to connect to the database.</pre>
- *
* The table structure can be created by the scripts/drivers/sql/ingo.sql
* script.
*
*/
public function __construct($params = array())
{
- $this->_params = $params;
-
- Horde::assertDriverConfig($this->_params, 'storage',
- array('phptype', 'charset'));
-
- if (!isset($this->_params['database'])) {
- $this->_params['database'] = '';
- }
- if (!isset($this->_params['username'])) {
- $this->_params['username'] = '';
- }
- if (!isset($this->_params['hostspec'])) {
- $this->_params['hostspec'] = '';
- }
- $this->_params['table_rules'] = 'ingo_rules';
- $this->_params['table_lists'] = 'ingo_lists';
- $this->_params['table_vacations'] = 'ingo_vacations';
- $this->_params['table_forwards'] = 'ingo_forwards';
- $this->_params['table_spam'] = 'ingo_spam';
-
- /* Connect to the SQL server using the supplied parameters. */
- $this->_write_db = &DB::connect($this->_params,
- array('persistent' => !empty($this->_params['persistent']),
- 'ssl' => !empty($this->_params['ssl'])));
- if (is_a($this->_write_db, 'PEAR_Error')) {
- throw new Horde_Exception_Prior($this->_write_db);
- }
- /* Set DB portability options. */
- switch ($this->_write_db->phptype) {
- case 'mssql':
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
-
- /* Check if we need to set up the read DB connection seperately. */
- if (!empty($this->_params['splitread'])) {
- $params = array_merge($this->_params, $this->_params['read']);
- $this->_db = &DB::connect($params,
- array('persistent' => !empty($params['persistent']),
- 'ssl' => !empty($params['ssl'])));
- if (is_a($this->_db, 'PEAR_Error')) {
- throw new Horde_Exception_Prior($this->_db);
- }
-
- switch ($this->_db->phptype) {
- case 'mssql':
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
- } else {
- /* Default to the same DB handle for the writer too. */
- $this->_db =& $this->_write_db;
- }
+ $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'ingo', 'storage');
+ $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'ingo', 'storage');
+
+ $this->_params = array_merge($params, array(
+ 'table_rules' => 'ingo_rules',
+ 'table_lists' => 'ingo_lists',
+ 'table_vacations' => 'ingo_vacations',
+ 'table_forwards' => 'ingo_forwards',
+ 'table_spam' => 'ingo_spam'
+ ));
parent::__construct();
}
/**
* Jonah storage implementation for PHP's PEAR database abstraction layer.
*
- * Required values for $params:<pre>
- * 'phptype' The database type (e.g. 'pgsql', 'mysql', etc.).
- * 'charset' The database's internal charset.</pre>
- *
- * Required by some database implementations:<pre>
- * 'hostspec' The hostname of the database server.
- * 'protocol' The communication protocol ('tcp', 'unix', etc.).
- * 'database' The name of the database.
- * 'username' The username with which to connect to the database.
- * 'password' The password associated with 'username'.
- * 'options' Additional options to pass to the database.
- * 'tty' The TTY on which to connect to the database.
- * 'port' The port on which to connect to the database.</pre>
- *
* The table structure can be created by the scripts/db/jonah_news.sql
* script. The needed tables are jonah_channels and jonah_stories.
*
/**
* Attempts to open a persistent connection to the SQL server.
*
- * @return boolean True on success; PEAR_Error on failure.
+ * @return boolean True on success; PEAR_Error on failure.
*/
protected function _connect()
{
return true;
}
- Horde::assertDriverConfig($this->_params, 'news',
- array('phptype', 'charset'),
- 'jonah news SQL');
-
- if (!isset($this->_params['database'])) {
- $this->_params['database'] = '';
- }
- if (!isset($this->_params['username'])) {
- $this->_params['username'] = '';
- }
- if (!isset($this->_params['hostspec'])) {
- $this->_params['hostspec'] = '';
- }
-
- /* Connect to the SQL server using the supplied parameters. */
- $this->_db = &DB::connect($this->_params,
- array('persistent' => !empty($this->_params['persistent'])));
- if (is_a($this->_db, 'PEAR_Error')) {
- return $this->_db;
- }
-
- // Set DB portability options.
- switch ($this->_db->phptype) {
- case 'mssql':
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
+ try {
+ $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'jonah', 'news');
+ } catch (Horde_Exception $e) {
+ return PEAR::raiseError($e->getMessage());
}
$this->_connected = true;
+
return true;
}
/**
* Jonah storage implementation for PHP's PEAR database abstraction layer.
*
- * Required values for $params:<pre>
- * 'phptype' The database type (e.g. 'pgsql', 'mysql', etc.).
- * 'charset' The database's internal charset.</pre>
- *
- * Required by some database implementations:<pre>
- * 'hostspec' The hostname of the database server.
- * 'protocol' The communication protocol ('tcp', 'unix', etc.).
- * 'database' The name of the database.
- * 'username' The username with which to connect to the database.
- * 'password' The password associated with 'username'.
- * 'options' Additional options to pass to the database.
- * 'tty' The TTY on which to connect to the database.
- * 'port' The port on which to connect to the database.</pre>
- *
* The table structure can be created by the scripts/db/jonah_news.sql
* script. The needed tables are jonah_channels and jonah_stories.
*
/**
* Attempts to open a persistent connection to the SQL server.
*
- * @return boolean True on success; PEAR_Error on failure.
+ * @return boolean True on success; PEAR_Error on failure.
*/
function _connect()
{
return true;
}
- Horde::assertDriverConfig($this->_params, 'news',
- array('phptype', 'charset'),
- 'jonah news SQL');
-
- if (!isset($this->_params['database'])) {
- $this->_params['database'] = '';
- }
- if (!isset($this->_params['username'])) {
- $this->_params['username'] = '';
- }
- if (!isset($this->_params['hostspec'])) {
- $this->_params['hostspec'] = '';
- }
-
- /* Connect to the SQL server using the supplied parameters. */
- $this->_db = &DB::connect($this->_params,
- array('persistent' => !empty($this->_params['persistent'])));
- if (is_a($this->_db, 'PEAR_Error')) {
- return $this->_db;
- }
-
- // Set DB portability options.
- switch ($this->_db->phptype) {
- case 'mssql':
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
+ try {
+ $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'jonah', 'news');
+ } catch (Horde_Exception $e) {
+ return PEAR::raiseError($e->getMessage());
}
$this->_connected = true;
+
return true;
}
*/
public function initialize()
{
- Horde::assertDriverConfig($this->_params, 'calendar',
- array('phptype'));
-
- if (!isset($this->_params['database'])) {
- $this->_params['database'] = '';
- }
- if (!isset($this->_params['username'])) {
- $this->_params['username'] = '';
- }
- if (!isset($this->_params['hostspec'])) {
- $this->_params['hostspec'] = '';
- }
- if (!isset($this->_params['table'])) {
- $this->_params['table'] = 'kronolith_events';
- }
-
- /* Connect to the SQL server using the supplied parameters. */
- $this->_write_db = DB::connect($this->_params,
- array('persistent' => !empty($this->_params['persistent']),
- 'ssl' => !empty($this->_params['ssl'])));
- $this->handleError($this->_write_db);
- $this->_initConn($this->_write_db);
-
- /* Check if we need to set up the read DB connection
- * seperately. */
- if (!empty($this->_params['splitread'])) {
- $params = array_merge($this->_params, $this->_params['read']);
- $this->_db = DB::connect($params,
- array('persistent' => !empty($params['persistent']),
- 'ssl' => !empty($params['ssl'])));
- $this->handleError($this->_db);
- $this->_initConn($this->_db);
- } else {
- /* Default to the same DB handle for the writer too. */
- $this->_db = $this->_write_db;
- }
- }
-
- /**
- */
- private function _initConn(&$db)
- {
- // Set DB portability options.
- switch ($db->phptype) {
- case 'mssql':
- $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
+ try {
+ $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'kronolith', 'calendar');
+ $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'kronolith', 'calendar');
+ } catch (Horde_Exception $e) {
+ throw new Kronolith_Exception($e);
}
- /* Handle any database specific initialization code to run. */
- switch ($db->dbsyntax) {
- case 'oci8':
- $query = "ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'";
+ foreach (array($this->_db, $this->_write_db) as $db) {
+ /* Handle any database specific initialization code to run. */
+ switch ($db->dbsyntax) {
+ case 'oci8':
+ $query = "ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'";
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('Kronolith_Driver_Sql::_initConn(): user = "%s"; query = "%s"',
- $GLOBALS['registry']->getAuth(), $query), 'DEBUG');
+ /* Log the query at a DEBUG log level. */
+ Horde::logMessage(sprintf('Kronolith_Driver_Sql::_initConn(): user = "%s"; query = "%s"', $GLOBALS['registry']->getAuth(), $query), 'DEBUG');
- $db->query($query);
- break;
+ $db->query($query);
+ break;
- case 'pgsql':
- $query = "SET datestyle TO 'iso'";
+ case 'pgsql':
+ $query = "SET datestyle TO 'iso'";
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('Kronolith_Driver_Sql::_initConn(): user = "%s"; query = "%s"',
- $GLOBALS['registry']->getAuth(), $query), 'DEBUG');
+ /* Log the query at a DEBUG log level. */
+ Horde::logMessage(sprintf('Kronolith_Driver_Sql::_initConn(): user = "%s"; query = "%s"', $GLOBALS['registry']->getAuth(), $query), 'DEBUG');
- $db->query($query);
- break;
+ $db->query($query);
+ break;
+ }
}
+
+ $this->_params = array_merge(array(
+ 'table' => 'kronolith_events'
+ ), $this->_params);
}
/**
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
*
- * @author Michael J. Rubinsky <mrubinsk@horde.org>
- *
- * @package Kronolith
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @category Horde
+ * @package Kronolith
*/
class Kronolith_Geo_Sql extends Kronolith_Geo
{
*/
public function initialize()
{
- Horde::assertDriverConfig($this->_params, 'calendar', array('phptype'));
-
- if (!isset($this->_params['database'])) {
- $this->_params['database'] = '';
- }
- if (!isset($this->_params['username'])) {
- $this->_params['username'] = '';
- }
- if (!isset($this->_params['hostspec'])) {
- $this->_params['hostspec'] = '';
- }
- if (!isset($this->_params['table'])) {
- $this->_params['table'] = 'kronolith_events_geo';
- }
-
- /* Connect to the SQL server using the supplied parameters. */
- $this->_write_db = DB::connect($this->_params,
- array('persistent' => !empty($this->_params['persistent']),
- 'ssl' => !empty($this->_params['ssl'])));
- if ($this->_write_db instanceof PEAR_Error) {
- throw new Kronolith_Exception($this->_write_db);
- }
- $this->_initConn($this->_write_db);
-
- /* Check if we need to set up the read DB connection
- * seperately. */
- if (!empty($this->_params['splitread'])) {
- $params = array_merge($this->_params, $this->_params['read']);
- $this->_db = DB::connect($params,
- array('persistent' => !empty($params['persistent']),
- 'ssl' => !empty($params['ssl'])));
- if ($this->_db instanceof PEAR_Error) {
- throw new Kronolith_Exception($this->_db);
- }
- $this->_initConn($this->_db);
- } else {
- /* Default to the same DB handle for the writer too. */
- $this->_db = $this->_write_db;
+ try {
+ $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'kronolith', 'calendar');
+ $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'kronolith', 'calendar');
+ } catch (Horde_Exception $e) {
+ throw new Kronolith_Exception($e);
}
return true;
}
- protected function _initConn(&$db)
- {
- // Set DB portability options.
- switch ($db->phptype) {
- case 'mssql':
- $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
- }
-
/**
* Set the location of the specified event _id
*
*/
public function initialize()
{
- Horde::assertDriverConfig($this->_params, 'storage',
- array('phptype'),
- 'kronolith storage SQL');
-
- if (!isset($this->_params['database'])) {
- $this->_params['database'] = '';
- }
- if (!isset($this->_params['username'])) {
- $this->_params['username'] = '';
- }
- if (!isset($this->_params['hostspec'])) {
- $this->_params['hostspec'] = '';
- }
-
- /* Connect to the SQL server using the supplied parameters. */
- include_once 'DB.php';
- $this->_write_db = &DB::connect($this->_params,
- array('persistent' => !empty($this->_params['persistent']),
- 'ssl' => !empty($this->_params['ssl'])));
- $this->handleError($this->_write_db);
- $this->_initConn($this->_write_db);
-
- /* Check if we need to set up the read DB connection seperately. */
- if (!empty($this->_params['splitread'])) {
- $params = array_merge($this->_params, $this->_params['read']);
- $this->_db = &DB::connect($params,
- array('persistent' => !empty($params['persistent']),
- 'ssl' => !empty($params['ssl'])));
- $this->handleError($this->_db);
- $this->_initConn($this->_db);
- } else {
- /* Default to the same DB handle for the writer too. */
- $this->_db =& $this->_write_db;
- }
- }
-
- /**
- */
- private function _initConn(&$db)
- {
- // Set DB portability options.
- switch ($db->phptype) {
- case 'mssql':
- $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
+ try {
+ $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'kronolith', 'storage');
+ $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'kronolith', 'storage');
+ } catch (Horde_Exception $e) {
+ throw new Kronolith_Exception($e);
}
}
/**
* Luxor storage implementation for PHP's PEAR database abstraction layer.
*
- * Required values for $params:<pre>
- * 'phptype' The database type (e.g. 'pgsql', 'mysql', etc.).
- * 'charset' The database's internal charset.</pre>
- *
- * Required by some database implementations:<pre>
- * 'hostspec' The hostname of the database server.
- * 'protocol' The communication protocol ('tcp', 'unix', etc.).
- * 'username' The username with which to connect to the database.
- * 'password' The password associated with 'username'.
- * 'database' The name of the database.
- * 'options' Additional options to pass to the database.
- * 'tty' The TTY on which to connect to the database.
- * 'port' The port on which to connect to the database.</pre>
- *
* The table structure can be created by the scripts/drivers/luxor.sql
* script.
*
/**
* Attempts to open a persistent connection to the SQL server.
*
- * @return boolean True on success; exits (Horde::fatal()) on error.
+ * @return boolean True on success.
*/
function _connect()
{
if (!$this->_connected) {
- Horde::assertDriverConfig($this->_params, 'storage',
- array('phptype', 'charset'));
-
- if (!isset($this->_params['database'])) {
- $this->_params['database'] = '';
- }
- if (!isset($this->_params['username'])) {
- $this->_params['username'] = '';
- }
- if (!isset($this->_params['hostspec'])) {
- $this->_params['hostspec'] = '';
- }
-
- /* Connect to the SQL server using the supplied parameters. */
- $this->_db = &DB::connect($this->_params,
- array('persistent' => !empty($this->_params['persistent'])));
- if (is_a($this->_db, 'PEAR_Error')) {
- Horde::fatal($this->_db, __FILE__, __LINE__);
- }
-
- // Set DB portability options.
- switch ($this->_db->phptype) {
- case 'mssql':
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
+ $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'luxor', 'storage');
$this->_connected = true;
}
* Mnemo storage implementation for PHP's PEAR database abstraction
* layer.
*
- * Required parameters:<pre>
- * 'phptype' The database type (e.g. 'pgsql', 'mysql', etc.).
- * 'charset' The database's internal charset.</pre>
- *
- * Optional values:<pre>
- * 'table' The name of the memos table in 'database'. Defaults
- * to 'mnemo_memos'</pre>
- *
- * Required by some database implementations:<pre>
- * 'hostspec' The hostname of the database server.
- * 'protocol' The communication protocol ('tcp', 'unix', etc.).
- * 'database' The name of the database.
- * 'username' The username with which to connect to the database.
- * 'password' The password associated with 'username'.
- * 'options' Additional options to pass to the database.
- * 'tty' The TTY on which to connect to the database.
- * 'port' The port on which to connect to the database.</pre>
- *
* The table structure is defined in scripts/drivers/mnemo_memos.sql.
*
* $Horde: mnemo/lib/Driver/sql.php,v 1.53 2009/07/09 08:18:32 slusarz Exp $
/**
* Attempts to open a connection to the SQL server.
*
- * @return boolean True on success, PEAR_Error on failure.
+ * @return boolean True on success.
*/
function initialize()
{
- Horde::assertDriverConfig($this->_params, 'storage',
- array('phptype', 'charset'));
-
- if (!isset($this->_params['database'])) {
- $this->_params['database'] = '';
- }
- if (!isset($this->_params['username'])) {
- $this->_params['username'] = '';
- }
- if (!isset($this->_params['hostspec'])) {
- $this->_params['hostspec'] = '';
- }
-
- if (!isset($this->_params['table'])) {
- $this->_params['table'] = 'mnemo_memos';
- }
+ $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'mnemo', 'storage');
+ $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'mnemo', 'storage');
- /* Connect to the SQL server using the supplied parameters. */
- require_once 'DB.php';
- $this->_write_db = &DB::connect($this->_params,
- array('persistent' => !empty($this->_params['persistent']),
- 'ssl' => !empty($this->_params['ssl'])));
- if (is_a($this->_write_db, 'PEAR_Error')) {
- Horde::fatal($this->_write_db, __FILE__, __LINE__);
- }
-
- // Set DB portability options.
- switch ($this->_write_db->phptype) {
- case 'mssql':
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
- /* Check if we need to set up the read DB connection
- * seperately. */
- if (!empty($this->_params['splitread'])) {
- $params = array_merge($this->_params, $this->_params['read']);
- $this->_db = &DB::connect($params,
- array('persistent' => !empty($params['persistent']),
- 'ssl' => !empty($params['ssl'])));
- if (is_a($this->_db, 'PEAR_Error')) {
- Horde::fatal($this->_db, __FILE__, __LINE__);
- }
-
- // Set DB portability options.
- switch ($this->_db->phptype) {
- case 'mssql':
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
- } else {
- /* Default to the same DB handle for reads. */
- $this->_db =& $this->_write_db;
- }
+ $this->_params = array_merge(array(
+ 'table' => 'mnemo_memos'
+ ), $this->_params);
return true;
}
*/
private function _connect()
{
- Horde::assertDriverConfig($this->_params, 'storage',
- array('phptype', 'charset'));
+ $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'news', 'storage');
+ $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'news', 'storage');
- if (!isset($this->_params['database'])) {
- $this->_params['database'] = '';
- }
- if (!isset($this->_params['username'])) {
- $this->_params['username'] = '';
- }
- if (!isset($this->_params['hostspec'])) {
- $this->_params['hostspec'] = '';
- }
if (isset($this->_params['prefix'])) {
$this->prefix = $this->_params['prefix'];
}
- /* Connect to the SQL server using the supplied parameters. */
- require_once 'DB.php';
- $this->write_db = &DB::connect($this->_params,
- array('persistent' => !empty($this->_params['persistent'])));
- if ($this->write_db instanceof PEAR_Error) {
- throw new Horde_Exception_Prior($this->write_db);
- }
-
- // Set DB portability options.
- switch ($this->write_db->phptype) {
- case 'mssql':
- $this->write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
- /* Check if we need to set up the read DB connection seperately. */
- if (!empty($this->_params['splitread'])) {
- $params = array_merge($this->_params, $this->_params['read']);
- $this->db = &DB::connect($params,
- array('persistent' => !empty($params['persistent'])));
- if ($this->db instanceof PEAR_Error) {
- throw new Horde_Exception_Prior($this->db);
- }
-
- // Set DB portability options.
- switch ($this->db->phptype) {
- case 'mssql':
- $this->db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
- } else {
- /* Default to the same DB handle for the writer too. */
- $this->db =& $this->write_db;
- }
-
return true;
}
/**
* Operator storage implementation for PHP's PEAR database abstraction layer.
*
- * Required values for $params:<pre>
- * 'phptype' The database type (e.g. 'pgsql', 'mysql', etc.).
- * 'table' The name of the foo table in 'database'.
- * 'charset' The database's internal charset.</pre>
- *
- * Required by some database implementations:<pre>
- * 'database' The name of the database.
- * 'hostspec' The hostname of the database server.
- * 'protocol' The communication protocol ('tcp', 'unix', etc.).
- * 'username' The username with which to connect to the database.
- * 'password' The password associated with 'username'.
- * 'options' Additional options to pass to the database.
- * 'tty' The TTY on which to connect to the database.
- * 'port' The port on which to connect to the database.</pre>
- *
* The table structure can be created by the scripts/sql/operator_foo.sql
* script.
*
/**
* Attempts to open a connection to the SQL server.
*
- * @return boolean True on success; exits (Horde::fatal()) on error.
+ * @return boolean True on success.
+ * @throws Horde_Exception
*/
protected function _connect()
{
return true;
}
- Horde::assertDriverConfig($this->_params, 'storage',
- array('phptype', 'charset', 'table'));
-
- if (!isset($this->_params['database'])) {
- $this->_params['database'] = '';
- }
- if (!isset($this->_params['username'])) {
- $this->_params['username'] = '';
- }
- if (!isset($this->_params['hostspec'])) {
- $this->_params['hostspec'] = '';
- }
-
- /* Connect to the SQL server using the supplied parameters. */
- require_once 'DB.php';
- $this->_write_db = &DB::connect($this->_params,
- array('persistent' => !empty($this->_params['persistent'])));
- if (is_a($this->_write_db, 'PEAR_Error')) {
- Horde::fatal($this->_write_db, __FILE__, __LINE__);
- }
-
- // Set DB portability options.
- switch ($this->_write_db->phptype) {
- case 'mssql':
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
- /* Check if we need to set up the read DB connection seperately. */
- if (!empty($this->_params['splitread'])) {
- $params = array_merge($this->_params, $this->_params['read']);
- $this->_db = &DB::connect($params,
- array('persistent' => !empty($params['persistent'])));
- if (is_a($this->_db, 'PEAR_Error')) {
- Horde::fatal($this->_db, __FILE__, __LINE__);
- }
-
- // Set DB portability options.
- switch ($this->_db->phptype) {
- case 'mssql':
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
- } else {
- /* Default to the same DB handle for the writer too. */
- $this->_db =& $this->_write_db;
- }
-
- $this->_connected = true;
+ $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'operator', 'storage');
+ $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'operator', 'storage');
return true;
}
*/
protected function _connect()
{
- if ($this->_connected) {
- return;
- }
-
- Horde::assertDriverConfig($this->_params, 'storage',
- array('phptype', 'charset'));
-
- if (!isset($this->_params['database'])) {
- $this->_params['database'] = '';
- }
- if (!isset($this->_params['username'])) {
- $this->_params['username'] = '';
- }
- if (!isset($this->_params['hostspec'])) {
- $this->_params['hostspec'] = '';
- }
-
- /* Connect to the SQL server using the supplied parameters. */
- $this->_write_db = DB::connect($this->_params,
- array('persistent' => !empty($this->_params['persistent'])));
- if ($this->_write_db instanceof PEAR_Error) {
- throw new Horde_Exception_Prior($this->_write_db);
- }
-
- // Set DB portability options.
- switch ($this->_write_db->phptype) {
- case 'mssql':
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
-
- default:
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
- /* Check if we need to set up the read DB connection seperately. */
- if (!empty($this->_params['splitread'])) {
- $params = array_merge($this->_params, $this->_params['read']);
- $this->_db = DB::connect($params,
- array('persistent' => !empty($params['persistent'])));
- if ($this->_db instanceof PEAR_Error) {
- throw new Horde_Exception_Prior($this->_db);
- }
-
- // Set DB portability options.
- switch ($this->_db->phptype) {
- case 'mssql':
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
-
- default:
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
- } else {
- /* Default to the same DB handle for the writer too. */
- $this->_db = $this->_write_db;
+ if (!$this->_connected) {
+ $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'pastie', 'storage');
+ $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'pastie', 'storage');
+ $this->_connected = true;
}
-
- $this->_connected = true;
}
/**
*/
protected function _connect()
{
- if ($this->_connected) {
- return;
- }
-
- Horde::assertDriverConfig($this->_params, $this->_params['class'],
- array('phptype', 'charset'));
-
- if (!isset($this->_params['database'])) {
- $this->_params['database'] = '';
- }
- if (!isset($this->_params['username'])) {
- $this->_params['username'] = '';
- }
- if (!isset($this->_params['hostspec'])) {
- $this->_params['hostspec'] = '';
- }
-
- /* Connect to the SQL server using the supplied parameters. */
- $this->_write_db = DB::connect($this->_params,
- array('persistent' => !empty($this->_params['persistent'])));
- if ($this->_write_db instanceof PEAR_Error) {
- throw new Shout_Exception($this->_write_db);
- }
-
- // Set DB portability options.
- switch ($this->_write_db->phptype) {
- case 'mssql':
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
-
- default:
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
- /* Check if we need to set up the read DB connection seperately. */
- if (!empty($this->_params['splitread'])) {
- $params = array_merge($this->_params, $this->_params['read']);
- $this->_db = DB::connect($params,
- array('persistent' => !empty($params['persistent'])));
- if ($this->_db instanceof PEAR_Error) {
- throw Shout_Exception($this->_db);
+ if (!$this->_connected) {
+ try {
+ $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'shout', $this->_params['class']);
+ $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'shout', $this->_params['class']);
+ } catch (Horde_Exception $e) {
+ throw new Shout_Exception($e);
}
- // Set DB portability options.
- switch ($this->_db->phptype) {
- case 'mssql':
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
-
- default:
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
- } else {
- /* Default to the same DB handle for the writer too. */
- $this->_db = $this->_write_db;
+ $this->_connected = true;
}
-
- $this->_connected = true;
}
/**
/**
* Skoli storage implementation for PHP's PEAR database abstraction layer.
*
- * Required parameters:<pre>
- * 'phptype' The database type (e.g. 'pgsql', 'mysql', etc.).
- * 'charset' The database's internal charset.</pre>
- *
- * Required by some database implementations:<pre>
- * 'hostspec' The hostname of the database server.
- * 'protocol' The communication protocol ('tcp', 'unix', etc.).
- * 'database' The name of the database.
- * 'username' The username with which to connect to the database.
- * 'password' The password associated with 'username'.
- * 'options' Additional options to pass to the database.
- * 'tty' The TTY on which to connect to the database.
- * 'port' The port on which to connect to the database.</pre>
- *
- * Optional values when using separate reading and writing servers, for example
- * in replication settings:<pre>
- * 'splitread' Boolean, whether to implement the separation or not.
- * 'read' Array containing the parameters which are different for
- * the read database connection, currently supported
- * only 'hostspec' and 'port' parameters.</pre>
- *
* Optional parameters:<pre>
* 'objects_table' The name of the objects table in 'database'.
* Default is 'skoli_objects'.
*/
function initialize()
{
- Horde::assertDriverConfig($this->_params, 'storage',
- array('phptype', 'charset'));
-
- if (!isset($this->_params['database'])) {
- $this->_params['database'] = '';
- }
- if (!isset($this->_params['username'])) {
- $this->_params['username'] = '';
- }
- if (!isset($this->_params['hostspec'])) {
- $this->_params['hostspec'] = '';
- }
- if (!isset($this->_params['objects_table'])) {
- $this->_params['objects_table'] = 'skoli_objects';
- }
- if (!isset($this->_params['object_attributes_table'])) {
- $this->_params['object_attributes_table'] = 'skoli_object_attributes';
- }
- if (!isset($this->_params['students_table'])) {
- $this->_params['students_table'] = 'skoli_classes_students';
- }
-
- /* Connect to the SQL server using the supplied parameters. */
- $this->_write_db = &DB::connect($this->_params,
- array('persistent' => !empty($this->_params['persistent'])));
- if (is_a($this->_write_db, 'PEAR_Error')) {
- return $this->_write_db;
- }
-
- /* Set DB portability options. */
- switch ($this->_write_db->phptype) {
- case 'mssql':
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
- /* Check if we need to set up the read DB connection
- * seperately. */
- if (!empty($this->_params['splitread'])) {
- $params = array_merge($this->_params, $this->_params['read']);
- $this->_db = &DB::connect($params,
- array('persistent' => !empty($params['persistent'])));
- if (is_a($this->_db, 'PEAR_Error')) {
- return $this->_db;
- }
-
- /* Set DB portability options. */
- switch ($this->_db->phptype) {
- case 'mssql':
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
- } else {
- /* Default to the same DB handle for the writer too. */
- $this->_db =& $this->_write_db;
- }
+ try {
+ $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'skoli', 'storage');
+ $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'skoli', 'storage');
+ } catch (Horde_Exception $e) {
+ return PEAR::raiseError($e->getMessage());
+ }
+
+ $this->_params = array_merge(array(
+ 'objects_table' => 'skoli_objects',
+ 'object_attributes_table' => 'skoli_object_attributes',
+ 'students_table' => 'skoli_classes_students'
+ ), $this->_params);
return true;
}
// Connect to database.
$db = DB::connect($dsn);
-if (is_a($db, 'PEAR_Error')) {
+if ($db instanceof PEAR_Error) {
$cli->fatal($db->toString());
}
require_once dirname(__FILE__) . '/../../lib/Application.php';
Horde_Registry::appInit('turba', array('authentication' => 'none', 'cli' => true));
-/* Grab what we need to steal the DB config */
-require_once HORDE_BASE . '/config/conf.php';
require_once 'Horde/Form.php';
-$config = $GLOBALS['conf']['sql'];
-if (!is_null($db_user)) {
- $config['username'] = $db_user;
-}
-if (!is_null($db_pass)) {
- $config['password'] = $db_pass;
-}
-unset($config['charset']);
-$db = DB::connect($config);
-if (is_a($db, 'PEAR_Error')) {
- throw new Horde_Exception($db);
-}
+$db = $injector->getInstance('Horde_Db_Pear')->getDb();
+
if (!$for_real) {
$cli->message('No changes will done to the existing data. Please read the comments in the code, then set the $for_real flag to true before running.', 'cli.message');
}
'CREATE INDEX turba_firstname_idx ON ' . $db_table . ' (object_firstname)',
'CREATE INDEX turba_lastname_idx ON ' . $db_table . ' (object_lastname)',
);
+
switch ($config['phptype']) {
case 'mssql':
$queries[] = 'ALTER TABLE ' . $db_table . ' ADD COLUMN object_photo VARBINARY(MAX)';
$queries[] = 'ALTER TABLE ' . $db_table . ' ADD COLUMN object_logo VARBINARY(MAX)';
break;
+
case 'pgsql':
$queries[] = 'ALTER TABLE ' . $db_table . ' ADD COLUMN object_photo TEXT';
$queries[] = 'ALTER TABLE ' . $db_table . ' ADD COLUMN object_logo TEXT';
break;
+
default:
$queries[] = 'ALTER TABLE ' . $db_table . ' ADD COLUMN object_photo BLOB';
$queries[] = 'ALTER TABLE ' . $db_table . ' ADD COLUMN object_logo BLOB';
{
global $registry;
- Horde::assertDriverConfig($this->_sqlparams, 'storage',
- array('phptype'));
-
- if (!isset($this->_sqlparams['database'])) {
- $this->_sqlparams['database'] = '';
- }
- if (!isset($this->_sqlparams['username'])) {
- $this->_sqlparams['username'] = '';
- }
- if (!isset($this->_sqlparams['hostspec'])) {
- $this->_sqlparams['hostspec'] = '';
- }
-
- /* Connect to the SQL server using the supplied parameters. */
- require_once 'DB.php';
- $this->_db = &DB::connect($this->_sqlparams,
- array('persistent' => !empty($this->_sqlparams['persistent'])));
- if (is_a($this->_db, 'PEAR_Error')) {
- return $this->_db;
- }
-
- // Set DB portability options.
- switch ($this->_db->phptype) {
- case 'mssql':
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
-
- default:
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
+ try {
+ $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'vilma', 'storage');
+ } catch (Horde_Exception $e) {
+ return PEAR::raiseError($e->getMessage());
}
}
}
*/
function initialise()
{
- global $registry;
-
- Horde::assertDriverConfig($this->_params, 'storage',
- array('phptype'));
-
- if (!isset($this->_params['database'])) {
- $this->_params['database'] = '';
- }
- if (!isset($this->_params['username'])) {
- $this->_params['username'] = '';
- }
- if (!isset($this->_params['hostspec'])) {
- $this->_params['hostspec'] = '';
+ try {
+ $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'vilma', 'storage');
+ } catch (Horde_Exception $e) {
+ return PEAR::raiseError($e->getMessage());
}
/* Use default table names if these are not set. */
$this->_params['tables']['virtuals'] = 'vilma_virtuals';
}
- /* Connect to the SQL server using the supplied parameters. */
- require_once 'DB.php';
- $this->_db = &DB::connect($this->_params,
- array('persistent' => !empty($this->_params['persistent'])));
- if (is_a($this->_db, 'PEAR_Error')) {
- return $this->_db;
- }
-
- // Set DB portability options.
- switch ($this->_db->phptype) {
- case 'mssql':
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
-
- default:
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
return true;
}
*/
function initialise()
{
- Horde::assertDriverConfig($this->_params, 'tickets',
- array('phptype'));
-
- if (!isset($this->_params['database'])) {
- $this->_params['database'] = '';
- }
- if (!isset($this->_params['username'])) {
- $this->_params['username'] = '';
- }
- if (!isset($this->_params['hostspec'])) {
- $this->_params['hostspec'] = '';
- }
-
- /* Connect to the SQL server using the supplied parameters. */
- require_once 'DB.php';
- $this->_write_db = &DB::connect($this->_params,
- array('persistent' => !empty($this->_params['persistent'])));
- if (is_a($this->_write_db, 'PEAR_Error')) {
- Horde::fatal($this->_write_db, __FILE__, __LINE__);
- }
-
- // Set DB portability options.
- switch ($this->_write_db->phptype) {
- case 'mssql':
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
- /* Check if we need to set up the read DB connection
- * seperately. */
- if (!empty($this->_params['splitread'])) {
- $params = array_merge($this->_params, $this->_params['read']);
- $this->_db = &DB::connect($params,
- array('persistent' => !empty($params['persistent'])));
- if (is_a($this->_db, 'PEAR_Error')) {
- Horde::fatal($this->_db, __FILE__, __LINE__);
- }
-
- // Set DB portability options.
- switch ($this->_db->phptype) {
- case 'mssql':
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
- } else {
- /* Default to the same DB handle for reads. */
- $this->_db =& $this->_write_db;
- }
+ $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'whups', 'tickets');
+ $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'whups', 'tickets');
return true;
}
/* Connect to the Bugzilla database. */
$bugzilla = DB::connect($BUGZILLA_DSN);
-if (is_a($bugzilla, 'PEAR_Error')) {
+if ($bugzilla instanceof PEAR_Error) {
error('Failed to connect to Bugzilla database', $bugzilla);
exit;
}
* Wicked storage implementation for PHP's PEAR database abstraction
* layer.
*
- * Required values for $params:<pre>
- * 'phptype' The database type (e.g. 'pgsql', 'mysql', etc.).
- * 'hostspec' The hostname of the database server.
- * 'protocol' The communication protocol ('tcp', 'unix', etc.).
- * 'username' The username with which to connect to the database.
- * 'password' The password associated with 'username'.
- * 'database' The name of the database.
- * 'table' The name of the tasks table in 'database'.
- * 'charset' The database's internal charset.</pre>
- *
- * Required by some database implementations:<pre>
- * 'options' Additional options to pass to the database.
- * 'tty' The TTY on which to connect to the database.
- * 'port' The port on which to connect to the database.</pre>
- *
* The table structure can be created by the scripts/drivers/wicked_foo.sql
* script.
*
*/
function connect()
{
- Horde::assertDriverConfig($this->_params, 'storage',
- array('phptype', 'charset'));
-
- if (!isset($this->_params['database'])) {
- $this->_params['database'] = '';
- }
- if (!isset($this->_params['username'])) {
- $this->_params['username'] = '';
- }
- if (!isset($this->_params['hostspec'])) {
- $this->_params['hostspec'] = '';
- }
- if (!isset($this->_params['table'])) {
- $this->_params['table'] = 'wicked_pages';
- }
- if (!isset($this->_params['historytable'])) {
- $this->_params['historytable'] = 'wicked_history';
+ try {
+ $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'wicked', 'storage');
+ } catch (Horde_Exception $e) {
+ return PEAR::raiseError($e->getMessage());
}
- if (!isset($this->_params['attachmenttable'])) {
- $this->_params['attachmenttable'] = 'wicked_attachments';
- }
- if (!isset($this->_params['attachmenthistorytable'])) {
- $this->_params['attachmenthistorytable'] = 'wicked_attachment_history';
- }
-
- /* Connect to the SQL server using the supplied parameters. */
- $this->_db = &DB::connect($this->_params,
- array('persistent' => !empty($this->_params['persistent'])));
- if (is_a($this->_db, 'PEAR_Error')) {
- return $this->_db;
- }
-
- // Set DB portability options.
- switch ($this->_db->phptype) {
- case 'mssql':
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
+ $this->_params = array_merge(array(
+ 'table' => 'wicked_pages',
+ 'historytable' => 'wicked_history',
+ 'attachmenttable' => 'wicked_attachments',
+ 'attachmenthistorytable' => 'wicked_attachment_history'
+ ), $this->_params);
return true;
}