Thread: [CS-Project-svn_notify] SF.net SVN: cs-project: [898] trunk/1.2 (Page 2)
Brought to you by:
crazedsanity
From: <cra...@us...> - 2008-05-20 19:03:54
|
Revision: 898 http://cs-project.svn.sourceforge.net/cs-project/?rev=898&view=rev Author: crazedsanity Date: 2008-05-20 12:03:51 -0700 (Tue, 20 May 2008) Log Message: ----------- More consolidation. Things still are pointing to global functions instead of the class... more work to do! Modified Paths: -------------- trunk/1.2/includes/setup/1.inc trunk/1.2/includes/setup/2.inc trunk/1.2/includes/setup/3.inc trunk/1.2/includes/setup.inc trunk/1.2/lib/setup.class.php Modified: trunk/1.2/includes/setup/1.inc =================================================================== --- trunk/1.2/includes/setup/1.inc 2008-05-20 18:48:23 UTC (rev 897) +++ trunk/1.2/includes/setup/1.inc 2008-05-20 19:03:51 UTC (rev 898) @@ -10,14 +10,14 @@ if($_POST) { reset_all_steps(FALSE); - store_setup_data(1, $_POST['fields']); - $dbTestRes = test_db_stuff(); + $setupObj->store_setup_data(1, $_POST['fields']); + $dbTestRes = $setupObj->test_db_stuff(); if($dbTestRes === TRUE) { - store_setup_data(1, 1, 'result'); - store_setup_data(1, 'Values stored successfully', 'text'); + $setupObj->store_setup_data(1, 1, 'result'); + $setupObj->store_setup_data(1, 'Values stored successfully', 'text'); //set the next step as accessible. - store_setup_data(2, 1, 'accessible'); + $setupObj->store_setup_data(2, 1, 'accessible'); //TODO: consider moving the database connectivity tests into this step (and alter the status message below accordingly). $page->set_message_wrapper(array( @@ -29,8 +29,8 @@ } else { //oops... - store_setup_data(1, 0, 'result'); - store_setup_data(1, $dbTestRes, 'text'); + $setupObj->store_setup_data(1, 0, 'result'); + $setupObj->store_setup_data(1, $dbTestRes, 'text'); $page->set_message_wrapper(array( 'title' => "Failure", @@ -52,7 +52,7 @@ )); } - $setupData = get_setup_data(1,'data'); + $setupData = $setupObj->get_setup_data(1,'data'); if(!is_array($setupData) || !count($setupData)) { //provide some defaults. $setupData = array( Modified: trunk/1.2/includes/setup/2.inc =================================================================== --- trunk/1.2/includes/setup/2.inc 2008-05-20 18:48:23 UTC (rev 897) +++ trunk/1.2/includes/setup/2.inc 2008-05-20 19:03:51 UTC (rev 898) @@ -7,15 +7,15 @@ if($_POST) { //check that step 1 was successful. - reset_all_steps(FALSE, 2); - $stepOneData = get_setup_data(1, 'data'); - if(get_setup_data(1, 'result')) { + $setupObj->reset_all_steps(FALSE, 2); + $stepOneData = $setupObj->get_setup_data(1, 'data'); + if($setupObj->get_setup_data(1, 'result')) { //first, check to see if we can connect to the host's "template1" database. $db = new cs_phpDB; - store_setup_data(2, 0, 'result'); - $result = test_db_stuff($db); + $setupObj->store_setup_data(2, 0, 'result'); + $result = $setupObj->test_db_stuff($db); if($result === TRUE) { //Good to go: load the schema! @@ -34,7 +34,7 @@ } else { //not so good. Go back to step 1, so they can make changes. - $params = get_setup_data(1, 'data'); + $params = $setupObj->get_setup_data(1, 'data'); $page->set_message_wrapper( array( 'title' => "Test Failed", Modified: trunk/1.2/includes/setup/3.inc =================================================================== --- trunk/1.2/includes/setup/3.inc 2008-05-20 18:48:23 UTC (rev 897) +++ trunk/1.2/includes/setup/3.inc 2008-05-20 19:03:51 UTC (rev 898) @@ -8,8 +8,7 @@ if($_POST) { $validSubmission = test_submitted_data($page, $_POST['users']); if($validSubmission === TRUE) { - $obj = new setup($page); - store_setup_data(3, $obj->handle_step(3), 'text'); + $setupObj->store_setup_data(3, $setupObj->handle_step(3), 'text'); } else { store_setup_data(3, $_POST['users'], 'post_info'); @@ -26,7 +25,7 @@ $page->conditional_header("/setup/3", TRUE); } else { - $myData = get_setup_data(3, 'post_info'); + $myData = $setupObj->get_setup_data(3, 'post_info'); if(is_array($myData)) { foreach($myData as $num=>$userArr) { foreach($userArr as $userField => $userValue) { Modified: trunk/1.2/includes/setup.inc =================================================================== --- trunk/1.2/includes/setup.inc 2008-05-20 18:48:23 UTC (rev 897) +++ trunk/1.2/includes/setup.inc 2008-05-20 19:03:51 UTC (rev 898) @@ -18,10 +18,13 @@ //create the setup object. require_once(dirname(__FILE__) .'/../lib/simpletest/unit_tester.php'); require_once(dirname(__FILE__) .'/../lib/simpletest/reporter.php'); +require_once(dirname(__FILE__) .'/../lib/setup.class.php'); $configObj = new config(NULL, FALSE); $configData = $configObj->read_config_file(FALSE); +$setupObj = new setup($page); + if(strlen($configData['DATABASE__DBNAME'])) { //setup already complete. Stop 'em. $page->set_message_wrapper(array( @@ -58,7 +61,7 @@ $page->conditional_header("/setup/". $_SESSION['setup']['lastStep'], TRUE); } elseif(count($sectionArr) == 2 && is_numeric($sectionArr[1]) && $sectionArr[1] != 1) { - if(!is_numeric(get_setup_data($sectionArr[1], 'accessible'))) { + if(!is_numeric($setupObj->get_setup_data($sectionArr[1], 'accessible'))) { $page->set_message_wrapper( array( 'title' => "Incomplete Step", @@ -71,7 +74,7 @@ } - $page->add_template_var("VERSION_STRING", read_version_file()); + $page->add_template_var("VERSION_STRING", $setupObj->read_version_file()); $page->rip_all_block_rows('stepData'); $page->clear_content('infobar'); @@ -82,12 +85,12 @@ $tmplStepTitle = "Main Setup Screen"; foreach($stepNames as $num=>$name) { - $stepResult = get_setup_data($num, 'result'); + $stepResult = $setupObj->get_setup_data($num, 'result'); if(!is_numeric($stepResult)) { $passFail = "Incomplete"; $bgColor = "yellow"; - if(strlen(get_setup_data($num, 'text'))) { - $stepText = get_setup_data($num, 'text'); + if(strlen($setupObj->get_setup_data($num, 'text'))) { + $stepText = $setupObj->get_setup_data($num, 'text'); } else { $stepText = "Step incomplete..."; @@ -97,14 +100,14 @@ $passFail = interpret_bool($stepResult, array('FAIL', 'Pass')); $bgColor = interpret_bool($stepResult, array('red', 'green')); - if(strlen(get_setup_data($num, 'text'))) { - $stepText = get_setup_data($num, 'text'); + if(strlen($setupObj->get_setup_data($num, 'text'))) { + $stepText = $setupObj->get_setup_data($num, 'text'); } else { $stepText = " "; } - store_setup_data($num, 1, 'accessible'); + $setupObj->store_setup_data($num, 1, 'accessible'); if($passFail == 'Pass') { $_SESSION['setup']['lastStep'] = $num; } @@ -131,144 +134,4 @@ $page->add_template_var('step_data_row', $myRows); } -//============================================================================= -function store_setup_data($step, $data, $type='data') { - $_SESSION['setup'][$type][$step] = $data; -}//end store_setup_data() -//============================================================================= - - - -//============================================================================= -function get_setup_data($step, $type='data') { - return($_SESSION['setup'][$type][$step]); -}//end get_setup_data() -//============================================================================= - - - -//============================================================================= -function read_version_file() { - $retval = NULL; - $fsObj = new cs_fileSystemClass(dirname(__FILE__) .'/..'); - - //okay, all files present: check the version in the VERSION file. - $lines = $fsObj->read('VERSION', TRUE); - $versionLine = $lines[2]; - if(preg_match('/^VERSION: /', $versionLine)) { - - $retval = trim(preg_replace('/VERSION: /', '', $versionLine)); - } - else { - throw new exception(__METHOD__ .": could not find VERSION data"); - } - - return($retval); -}//end read_version_file() -//============================================================================= - - - -//============================================================================= -function get_db_params() { - - $stepOneData = get_setup_data(1, 'data'); - if(is_array($stepOneData)) { - $params = array(); - foreach($stepOneData as $name=>$value) { - $index = preg_replace('/^database__/', '', $name); - $params[$index] = $value; - } - } - else { - throw new exception(__FUNCTION__ .": unable to retrieve step one data..."); - } - - return($params); -}//end get_db_params() -//============================================================================= - - - -//============================================================================= -function reset_all_steps($leaveText=TRUE, $afterStep=NULL) { - $retval=0; - if(is_array($_SESSION['setup'])) { - if(is_numeric($afterStep)) { - $_SESSION['setup']['lastStep'] = $afterStep; - } - else { - $_SESSION['setup']['lastStep'] = 1; - } - $unsetThis = array('data', 'result', 'accessible'); - - if($leaveText !== TRUE) { - $unsetThis[] = 'text'; - } - foreach($unsetThis as $indexName) { - if(isset($_SESSION['setup'][$indexName])) { - if(is_numeric($afterStep)) { - foreach($_SESSION['setup'][$indexName] as $stepNum=>$stepData) { - if(is_numeric($stepNum) && $stepNum > $afterStep) { - unset($_SESSION['setup'][$indexName][$stepNum]); - $retval++; - } - } - } - else { - unset($_SESSION['setup'][$indexName]); - $retval++; - } - } - } - } - else { - throw new exception(__FUNCTION__ .": no step data found in session"); - } - - return($retval); -}//end reset_all_steps() -//============================================================================= - - - -//============================================================================= -function test_db_stuff(cs_phpDB &$db=NULL) { - if(is_null($db) || !is_object($db)) { - $db = new cs_phpDB; - } - $stepOneData = get_setup_data(1); - $params = get_db_params(); - $originalParams = $params; - - - - $params['dbname'] = 'template1'; - $retval = "Failed to connect to ". $params['host'] .":". $params['dbname'] ." (host connection failed)"; - - $gf = new cs_globalFunctions; - - try { - $db->connect($params); - $result = "Connected successfully to ". $params['host'] .":". $params['dbname'] ." (host connection good)"; - try { - $newParams = $originalParams; - $db2 = new cs_phpDB; - $db2->connect($originalParams ); - $retval = "Connected successfully to ". $newParams['host'] .":". $newParams['dbname'] ." (host connection good, DATABASE EXISTS)"; - } - catch(exception $e) { - //no database! - //TODO: do a preg_match() on $e->getMessage() to see if it says something about the database not existing - $retval = TRUE; - } - } - catch(exception $e) { - $retval = $e->getMessage(); - } - - return($retval); -}//end test_db_stuff() -//============================================================================= - ?> \ No newline at end of file Modified: trunk/1.2/lib/setup.class.php =================================================================== --- trunk/1.2/lib/setup.class.php 2008-05-20 18:48:23 UTC (rev 897) +++ trunk/1.2/lib/setup.class.php 2008-05-20 19:03:51 UTC (rev 898) @@ -22,7 +22,17 @@ //============================================================================= function __construct(cs_genericPage $page, cs_phpDB $db=NULL) { $this->pageObj = $page; - $this->dbObj = $db; + + //TODO: determine what step we're on (if > 1, can connect db) + try { + $connectionParams = $this->get_db_params(); + + //TODO: make this a setup parameter (so we can integrate with mysql). + $this->dbObj = new cs_phpDB('pgsql'); + $this->dbObj->connect($connectionParams); + } + catch(exception $e) { + } }//end __construct() //============================================================================= @@ -134,8 +144,8 @@ if(is_null($db) || !is_object($db)) { $db = new cs_phpDB; } - $stepOneData = get_setup_data(1); - $params = get_db_params(); + $stepOneData = $this->get_setup_data(1); + $params = $this->get_db_params(); $originalParams = $params; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |