[Cs-webapplibs-commits] SF.net SVN: cs-webapplibs:[150] trunk/0.3
Status: Beta
Brought to you by:
crazedsanity
From: <cra...@us...> - 2009-09-21 04:40:44
|
Revision: 150 http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=150&view=rev Author: crazedsanity Date: 2009-09-21 04:40:36 +0000 (Mon, 21 Sep 2009) Log Message: ----------- Default db type instead of exception, dbparameters for cs-webapplibs. /cs_phpDB.class.php: * __construct(): -- set type as 'pgsql' if it isn't set. -- dont' throw an exception anymore since type is always set. /cs_webdbupgrade.class.php: * MAIN::: -- new (private) var $dbType=null * __construct(): -- ARG CHANGE: ARG SHIFTED ($lockFile from #3 to #4) -- ARG CHANGE: NEW ARG: #3 (array $dbparams=null) -- allow an array of database parameters to be set -- use array of paramenters vs. constants by default. -- for constant definitions, use (modified) project name as prefix. -- only set internal dbType if the appropriate constant is set -- set default rwDir (don't throw an exception on missing constant) -- user internal dbType as first argument to cs_phpDB. /tests/testOfCSWebAppLibs.php: * create_db(): -- use proper constants for connection parameters * remove_tables(): -- don't force an error if dropping the tables fails. Modified Paths: -------------- trunk/0.3/cs_phpDB.class.php trunk/0.3/cs_webdbupgrade.class.php trunk/0.3/tests/testOfCSWebAppLibs.php Modified: trunk/0.3/cs_phpDB.class.php =================================================================== --- trunk/0.3/cs_phpDB.class.php 2009-09-10 17:39:07 UTC (rev 149) +++ trunk/0.3/cs_phpDB.class.php 2009-09-21 04:40:36 UTC (rev 150) @@ -33,21 +33,18 @@ //========================================================================= public function __construct($type='pgsql') { - - if(strlen($type)) { - - require_once(dirname(__FILE__) .'/db_types/'. __CLASS__ .'__'. $type .'.class.php'); - $className = __CLASS__ .'__'. $type; - $this->dbLayerObj = new $className; - $this->dbType = $type; - - parent::__construct(true); - - $this->isInitialized = TRUE; + if(is_null($type) || !strlen($type)) { + $type = 'pgsql'; } - else { - throw new exception(__METHOD__ .": failed to give a type (". $type .")"); - } + + require_once(dirname(__FILE__) .'/db_types/'. __CLASS__ .'__'. $type .'.class.php'); + $className = __CLASS__ .'__'. $type; + $this->dbLayerObj = new $className; + $this->dbType = $type; + + parent::__construct(true); + + $this->isInitialized = TRUE; }//end __construct() //========================================================================= Modified: trunk/0.3/cs_webdbupgrade.class.php =================================================================== --- trunk/0.3/cs_webdbupgrade.class.php 2009-09-10 17:39:07 UTC (rev 149) +++ trunk/0.3/cs_webdbupgrade.class.php 2009-09-21 04:40:36 UTC (rev 150) @@ -55,6 +55,8 @@ private $storedLogs = array(); private $debugLogs=array(); + private $dbType=null; + /** List of acceptable suffixes; example "1.0.0-BETA3" -- NOTE: these MUST be in * an order that reflects newest -> oldest; "ALPHA happens before BETA, etc. */ private $suffixList = array( @@ -64,16 +66,19 @@ ); //========================================================================= - public function __construct($versionFileLocation, $upgradeConfigFile, $lockFile='upgrade.lock') { + public function __construct($versionFileLocation, $upgradeConfigFile, array $dbParams=null, $lockFile='upgrade.lock') { //setup configuration parameters for database connectivity. - $dbParams = array( - 'host' => constant(__CLASS__ .'-DB_CONNECT_HOST'), - 'port' => constant(__CLASS__ .'-DB_CONNECT_PORT'), - 'dbname' => constant(__CLASS__ .'-DB_CONNECT_DBNAME'), - 'user' => constant(__CLASS__ .'-DB_CONNECT_USER'), - 'password' => constant(__CLASS__ .'-DB_CONNECT_PASSWORD') - ); + if(!is_array($dbParams) || !count($dbParams)) { + $prefix = preg_replace('/-/', '_', $this->get_project()); + $dbParams = array( + 'host' => constant($prefix .'-DB_CONNECT_HOST'), + 'port' => constant($prefix .'-DB_CONNECT_PORT'), + 'dbname' => constant($prefix .'-DB_CONNECT_DBNAME'), + 'user' => constant($prefix .'-DB_CONNECT_USER'), + 'password' => constant($prefix .'-DB_CONNECT_PASSWORD') + ); + } $this->config['DBPARAMS'] = $dbParams; //Check for some required constants. $requisiteConstants = array('LIBDIR'); @@ -95,8 +100,8 @@ $this->config['DB_PRIMARYKEY'] = 'version_id'; $this->sequenceName = $this->config['DB_TABLE'] .'_'. $this->config['DB_PRIMARYKEY'] .'_seq'; - if(!defined('DBTYPE')) { - throw new exception(__METHOD__ .": required constant 'DBTYPE' not set"); + if(defined('DBTYPE')) { + $this->dbType = constant('DBTYPE'); } if(!file_exists($upgradeConfigFile) || !is_readable($upgradeConfigFile)) { @@ -110,18 +115,17 @@ } $this->set_version_file_location($versionFileLocation); - if(!defined(__CLASS__ .'-RWDIR') || !is_dir(constant(__CLASS__ .'-RWDIR')) || !is_readable(constant(__CLASS__ .'-RWDIR')) || !is_writable(constant(__CLASS__ .'-RWDIR'))) { - throw new exception(__METHOD__ .": missing RWDIR (". constant(__CLASS__ .'-RWDIR') .") or isn't readable/writable"); + $rwDir = dirname(__FILE__) .'/../rw'; + if(defined(__CLASS__ .'-RWDIR')) { + $rwDir = constant(__CLASS__ .'-RWDIR'); } - else { - $this->config['RWDIR'] = constant(__CLASS__ .'-RWDIR'); - } + $this->config['RWDIR'] = $rwDir; if(is_null($lockFile) || !strlen($lockFile)) { $lockFile = 'upgrade.lock'; } $this->lockfile = $this->config['RWDIR'] .'/'. $lockFile; - $this->db = new cs_phpDB(constant('DBTYPE')); + $this->db = new cs_phpDB($this->dbType); try { $this->db->connect($this->config['DBPARAMS']); } @@ -137,7 +141,7 @@ $this->check_internal_upgrades(); try { - $loggerDb = new cs_phpDB(constant('DBTYPE')); + $loggerDb = new cs_phpDB($this->dbType); $loggerDb->connect($this->config['DBPARAMS'], true); $this->logsObj = new cs_webdblogger($loggerDb, "Upgrade ". $this->projectName, false); } Modified: trunk/0.3/tests/testOfCSWebAppLibs.php =================================================================== --- trunk/0.3/tests/testOfCSWebAppLibs.php 2009-09-10 17:39:07 UTC (rev 149) +++ trunk/0.3/tests/testOfCSWebAppLibs.php 2009-09-21 04:40:36 UTC (rev 150) @@ -26,11 +26,11 @@ //-------------------------------------------------------------------------- private function create_dbconn() { $dbParams = array( - 'host' => constant('DB_PG_HOST'), - 'dbname' => constant('DB_PG_DBNAME'), - 'user' => constant('DB_PG_DBUSER'), - 'password' => constant('DB_PG_DBPASS'), - 'port' => constant('DB_PG_PORT') + 'host' => constant('cs_webapplibs-DB_CONNECT_HOST'), + 'dbname' => constant('cs_webapplibs-DB_CONNECT_DBNAME'), + 'user' => constant('cs_webapplibs-DB_CONNECT_USER'), + 'password' => constant('cs_webapplibs-DB_CONNECT_PASSWORD'), + 'port' => constant('cs_webapplibs-DB_CONNECT_PORT') ); $db = new cs_phpDB(constant('DBTYPE')); $db->connect($dbParams); @@ -55,7 +55,7 @@ } catch(exception $e) { //force an error. - $this->assertTrue(false, "Error while dropping (". $name .")::: ". $e->getMessage()); + //$this->assertTrue(false, "Error while dropping (". $name .")::: ". $e->getMessage()); } } }//end remove_tables() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |