cvs: pear /LiveUser/sql install.php

From: Date: Sun, 20 Feb 2005 17:46:27 +0000
Subject: cvs: pear /LiveUser/sql install.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-29546@lists.php.net to get a copy of this message
lsmith Sun Feb 20 12:46:27 2005 EDT Modified files: /pear/LiveUser/sql install.php Log: - several minor fixes - added debug output - added sample useage http://cvs.php.net/diff.php/pear/LiveUser/sql/install.php?r1=1.1&r2=1.2&ty=u Index: pear/LiveUser/sql/install.php diff -u pear/LiveUser/sql/install.php:1.1 pear/LiveUser/sql/install.php:1.2 --- pear/LiveUser/sql/install.php:1.1 Wed Feb 16 15:55:12 2005 +++ pear/LiveUser/sql/install.php Sun Feb 20 12:46:27 2005 @@ -3,44 +3,93 @@ // $file is the name of the schema to be inserted into the database // $config -class LiveUser_Misc_SQL_Install +require_once 'LiveUser.php'; +require_once 'MDB2.php'; +MDB2::loadFile('Tools/Manager'); + +/* +$dsn = 'mysql://root:@localhost/liveuser_test_installer'; + +$conf = array( + 'authContainers' => array( + array( + 'type' => 'DB', + 'dsn' => $dsn, + 'authTable' => 'liveuser_users', + 'authTableCols' => array( + 'required' => array( + 'auth_user_id' => array('name' => 'authUserId', 'type' => 'text'), + 'handle' => array('name' => 'handle', 'type' => 'text'), + 'passwd' => array('name' => 'passwd', 'type' => 'text'), + ), + 'optional' => array( + 'lastlogin' => array('name' => 'lastLogin', 'type' => 'timestamp'), + 'is_active' => array('name' => 'isActive', 'type' => 'boolean') + ), + ), + ), + ), + 'permContainer' => array( + 'type' => 'Complex', + 'storage' => array('DB' => array('dsn' => $dsn, 'prefix' => 'liveuser_')), + ) +); + +$installer =& new LiveUser_Misc_Schema_Install(); +#$result = $installer->installAuthSchema($conf['authContainers'][0], 'auth_mdb_schema.xml', true); +#var_dump($result); +$result = $installer->installPermSchema($conf['permContainer']['storage']['DB'], 'perm_mdb_schema.xml', false); +var_dump($result); +*/ + +class LiveUser_Misc_Schema_Install { - function installAuthSchema($config, $file) + function installAuthSchema($config, $file, $create = true) { if (isset($config['connection'])) { $dsn = $config['connection']->dsn; + if (!isset($dsn['database'])) { + $dsn['database'] = $config['connection']->database_name; + } } else { - $dsn = $config['dsn']; + $dsn = MDB2::parseDSN($config['dsn']); } - - $variables = array('user_table_name' => $config['authTable']); - $variables['auth_user_id_name'] = isset($config['required']['auth_user_id']['name']) - ? $config['required']['auth_user_id']['name'] : 'auth_user_id'; - $variables['handle_name'] = isset($config['required']['handle']['name']) - ? $config['required']['handle']['name'] : 'handle'; - $variables['passwd_name'] = isset($config['required']['passwd']['name']) - ? $config['required']['passwd']['name'] : 'passwd'; - $variables['lastlogin_name'] = isset($config['required']['lastlogin']['name']) - ? $config['required']['lastlogin']['name'] : 'lastlogin'; - $variables['owner_user_id_name'] = isset($config['required']['owner_user_id']['name']) - ? $config['required']['owner_user_id']['name'] : 'owner_user_id'; - $variables['owner_group_id_name'] = isset($config['required']['owner_group_id']['name']) - ? $config['required']['owner_group_id']['name'] : 'owner_group_id'; - $variables['is_active_name'] = isset($config['required']['is_active']['name']) - ? $config['required']['is_active']['name'] : 'is_active'; - - return $this->installSchema($dsn, $file, $variables); + + $variables = array('database' => $dsn['database']); + + $variables['user_table_name'] = isset($config['authTable']) + ? $config['authTable'] : 'liveuser_users'; + $variables['auth_user_id_name'] = isset($config['authTableCols']['required']['auth_user_id']['name']) + ? $config['authTableCols']['required']['auth_user_id']['name'] : 'auth_user_id'; + $variables['handle_name'] = isset($config['authTableCols']['required']['handle']['name']) + ? $config['authTableCols']['required']['handle']['name'] : 'handle'; + $variables['passwd_name'] = isset($config['authTableCols']['required']['passwd']['name']) + ? $config['authTableCols']['required']['passwd']['name'] : 'passwd'; + $variables['lastlogin_name'] = isset($config['authTableCols']['optional']['lastlogin']['name']) + ? $config['authTableCols']['optional']['lastlogin']['name'] : 'lastlogin'; + $variables['is_active_name'] = isset($config['authTableCols']['optional']['is_active']['name']) + ? $config['authTableCols']['optional']['is_active']['name'] : 'is_active'; + $variables['owner_user_id_name'] = isset($config['authTableCols']['custom']['owner_user_id']['name']) + ? $config['authTableCols']['custom']['owner_user_id']['name'] : 'owner_user_id'; + $variables['owner_group_id_name'] = isset($config['authTableCols']['custom']['owner_group_id']['name']) + ? $config['authTableCols']['custom']['owner_group_id']['name'] : 'owner_group_id'; + + return $this->installSchema($dsn, $file, $variables, $create); } - function installPermSchema($config, $file) + function installPermSchema($config, $file, $create = true) { if (isset($config['connection'])) { $dsn = $config['connection']->dsn; + if (!isset($dsn['database'])) { + $dsn['database'] = $config['connection']->database_name; + } } else { - $dsn = $config['dsn']; + $dsn = MDB2::parseDSN($config['dsn']); } $variables = array( + 'database' => $dsn['database'], 'table_prefix' => $config['prefix'], 'right_max_level' => LIVEUSER_MAX_LEVEL, ); @@ -48,18 +97,28 @@ return $this->installSchema($dsn, $file, $variables); } - function installSchema($dsn, $file, $variables) + function installSchema($dsn, $file, $variables, $create = true) { - require_once 'MDB2.php'; - MDB2::loadFile('Tools/Manager'); - $manager =& new MDB2_Tools_Manager; - $err = $manager->connect($dsn); + + unset($dsn['database']); + + $options = array( + 'debug' => true, + 'log_line_break' => '<br>', + 'portability' => (MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL), + ); + + $err = $manager->connect($dsn, $options); if (MDB2::isError($err)) { - return $err->getMessage(); + return $err->getMessage().' - '.$err->getUserinfo(); } + $variables['create'] = (int)$create; $result = $manager->updateDatabase($file, 'old_'.$file, $variables); + echo('Debug messages<br>'); + echo($manager->db->debugOutput().'<br>'); + $manager->disconnect(); return $result; }

« previous php.pear.cvs (#29546) next »