From eab20f7379d44efdc396a84d89d88fbfbcc60029 Mon Sep 17 00:00:00 2001 From: eriknyk Date: Thu, 28 Aug 2014 12:37:12 -0400 Subject: [PATCH] Adding a new propel function: Propel::getDbConnection('workflow_ro'),.. to enable use, of a replicated read only or read and write db source connections, commonly used on balanced environments. --- gulliver/thirdparty/propel/Propel.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/gulliver/thirdparty/propel/Propel.php b/gulliver/thirdparty/propel/Propel.php index 501dca3fe..62d87167d 100755 --- a/gulliver/thirdparty/propel/Propel.php +++ b/gulliver/thirdparty/propel/Propel.php @@ -31,7 +31,7 @@ include_once 'adapter/DBAdapter.php'; * * @author Hans Lellelid (Propel) * @author Daniel Rall (Torque) - * @author Magnús Þór Torfason (Torque) + * @author Magn�s ��r Torfason (Torque) * @author Jason van Zyl (Torque) * @author Rafal Krzewski (Torque) * @author Martin Poeschl (Torque) @@ -603,4 +603,27 @@ class Propel { } } + /** + * @param $name string The connection name + * @return Connection A database connection + * @throws PropelException + */ + public static function getDbConnection($name) + { + if (! empty(self::$configuration['datasources'][$name]['connection'])) { + return self::getConnection($name); + } + + // the connection names always should be have a underscore like: workflow_ro, rbac_rw + // on fallback, we will try found a connection named: "workflow" if "workflow_ro" does not exist. + // the name without the "_ro" part. + + $defaultDbName = substr($name, 0, strrpos($name, '_')); + + if (! empty(self::$configuration['datasources'][$defaultDbName]['connection'])) { + return self::getConnection($defaultDbName); + } + + throw new PropelException('Error, database connection named "'.$name.'" is not defined for Propel.'); + } }