Skip to content

Commit

Permalink
- solved issues with dsn and option detection by making the user pass…
Browse files Browse the repository at this point in the history
… the container instances

git-svn-id: http://svn.php.net/repository/pear/packages/LiveUser/trunk@185558 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
Lukas Smith committed May 1, 2005
1 parent f104c97 commit 23dfefd
Showing 1 changed file with 23 additions and 41 deletions.
64 changes: 23 additions & 41 deletions sql/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,31 +81,27 @@
'portability' => (MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL),
);
$result = LiveUser_Misc_Schema_Install::generateAuthSchema(
$conf['authContainers'][0],
'auth_schema.xml'
);
$auth =& LiveUser::authFactory($conf['authContainers'][0], 'foo');
$result = LiveUser_Misc_Schema_Install::generateAuthSchema($auth, 'auth_schema.xml');
var_dump($result);
$variables = array();
$result = LiveUser_Misc_Schema_Install::installSchema(
$conf['authContainers'][0]['dsn'],
$auth,
'auth_schema.xml',
$variables,
true,
$options
);
var_dump($result);
$result = LiveUser_Misc_Schema_Install::generatePermSchema(
$conf['permContainer']['storage'],
'perm_schema.xml'
);
$perm =& LiveUser::storageFactory($conf['permContainer']['storage']);
$result = LiveUser_Misc_Schema_Install::generatePermSchema($perm, 'perm_schema.xml');
var_dump($result);
$variables = array();
$result = LiveUser_Misc_Schema_Install::installSchema(
$conf['permContainer']['storage']['MDB2']['dsn'],
$perm,
'perm_schema.xml',
$variables,
false,
Expand All @@ -116,24 +112,14 @@

class LiveUser_Misc_Schema_Install
{
function generateAuthSchema($config, $file)
function generateAuthSchema($auth, $file)
{
$auth =& LiveUser::authFactory($config, 'foo');
if (!$auth) {
if (!is_a($auth, 'LiveUser_Auth_Common')) {
return false;
}

$dsn = $auth->dbc->dsn;
$options = array();
if (is_a($auth->dbc, 'DB_Common')) {
$options['seqcol_name'] = 'id';
} else {
$dsn['database'] = $auth->dbc->database_name;
}

// generate xml schema
$fields = array();

if (isset($auth->authTableCols['required']) &&
is_array($auth->authTableCols['required'])
) {
Expand Down Expand Up @@ -199,24 +185,15 @@ function generateAuthSchema($config, $file)
if (!LiveUser_Misc_Schema_Install::writeSchema($definition, $file)) {
return false;
}
return array($dsn, $options);
return true;
}

function generatePermSchema($config, $file)
function generatePermSchema($perm, $file)
{
$perm =& LiveUser::storageFactory($config);
if (!$perm) {
if (!is_a($perm, 'LiveUser_Perm_Storage')) {
return false;
}

$dsn = $perm->dbc->dsn;
$options = array();
if (is_a($perm->dbc, 'DB_Common')) {
$options['seqcol_name'] = 'id';
} else {
$dsn['database'] = $perm->dbc->database_name;
}

// generate xml schema
$tables = array();
$sequences = array();
Expand Down Expand Up @@ -271,7 +248,7 @@ function generatePermSchema($config, $file)
if (!LiveUser_Misc_Schema_Install::writeSchema($definition, $file)) {
return false;
}
return array($dsn, $options);
return true;
}

function writeSchema($definition, $file)
Expand All @@ -285,18 +262,23 @@ function writeSchema($definition, $file)
return $writer->dumpDatabase($definition, $arguments);
}

function installSchema($dsn, $file, $variables = array(), $create = true, $options = array())
function installSchema($obj, $file, $variables = array(), $create = true, $options = array())
{
$dsn = MDB2::parseDSN($dsn);
$dsn = $obj->dbc->dsn;
if (is_a($obj->dbc, 'DB_Common')) {
$options['seqcol_name'] = 'id';
} else {
$dsn['database'] = $obj->dbc->database_name;
}

$file_old = $file.'.'.$dsn['hostspec'].'.'.$dsn['database'].'.old';
$variables['create'] = (int)$create;
$variables['database'] = $dsn['database'];
unset($dsn['database']);

$manager =& new MDB2_Schema;
$err = $manager->connect($dsn, $options);
if (MDB2::isError($err)) {
return $err;
$manager =& MDB2_Schema::factory($dsn, $options);
if (PEAR::isError($manager)) {
return $manager;
}

$result = $manager->updateDatabase($file, $file_old, $variables);
Expand Down

0 comments on commit 23dfefd

Please sign in to comment.