allow schema to work on more than one connection (namely, the Status_network DB)

This commit is contained in:
James Walker 2010-07-29 21:04:28 -04:00
parent c2a26ba653
commit 47f19988d1

View File

@ -47,40 +47,47 @@ if (!defined('STATUSNET')) {
class Schema class Schema
{ {
static $_single = null; static $_static = null;
protected $conn = null; protected $conn = null;
/** /**
* Constructor. Only run once for singleton object. * Constructor. Only run once for singleton object.
*/ */
protected function __construct() protected function __construct($conn = null)
{ {
// XXX: there should be an easier way to do this. if (is_null($conn)) {
$user = new User(); // XXX: there should be an easier way to do this.
$user = new User();
$conn = $user->getDatabaseConnection();
$user->free();
unset($user);
}
$this->conn = $user->getDatabaseConnection(); $this->conn = $conn;
$user->free();
unset($user);
} }
/** /**
* Main public entry point. Use this to get * Main public entry point. Use this to get
* the singleton object. * the schema object.
* *
* @return Schema the (single) Schema object * @return Schema the Schema object for the connection
*/ */
static function get() static function get($conn = null)
{ {
$type = common_config('db', 'type'); if (is_null($conn)) {
if (empty(self::$_single)) { $key = 'default';
$schemaClass = ucfirst($type).'Schema'; } else {
self::$_single = new $schemaClass(); $key = md5(serialize($conn->dsn));
} }
return self::$_single;
$type = common_config('db', 'type');
if (empty(self::$_static[$key])) {
$schemaClass = ucfirst($type).'Schema';
self::$_static[$key] = new $schemaClass($conn);
}
return self::$_static[$key];
} }
/** /**