From caaf5527f8f832e7ffc451ac3c41030e91892a72 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 4 Apr 2017 13:09:52 -0400 Subject: [PATCH] Get member data from homes rvs amenities Getting member data for import. --- .../management/import/brewbakersImport.php | 114 +++++++++++++++--- 1 file changed, 97 insertions(+), 17 deletions(-) diff --git a/models/admin/management/import/brewbakersImport.php b/models/admin/management/import/brewbakersImport.php index effa709c..0f6b6eb7 100644 --- a/models/admin/management/import/brewbakersImport.php +++ b/models/admin/management/import/brewbakersImport.php @@ -6,50 +6,130 @@ echo '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; $dbServer = 'ds4'; $dbName = 'brewbakers'; $dbUser = 'postgres'; +$resetdb = false; +$rvs = array(); +$homes = array(); // Create connection $connString = "host=$dbServer dbname=$dbName user=$dbUser"; -$db = @pg_connect($connString); -if (!$db) { +$db = @pg_connect( $connString ); +if ( !$db ) { $err = error_get_last(); $templateData['genError'] = 'There was a problem connecting to the database. The error message was...
'.$err['message']; $failure = true; } -if (!$failure) { +// 1. Get the rvs data +if ( !$failure ) { // Grab the RV data $sql = " SELECT * FROM rvs ORDER BY id"; - $res = pg_query($db, $sql); - $rows = pg_num_rows($res); - if ($rows == 0) { + $res = pg_query( $db, $sql ); + $rows = pg_num_rows( $res ); + if ( $rows == 0 ) { $templateData['genError'] = 'There does not appear to be any rvs listed in this database!'; $failure = true; } else { - $rvs = pg_fetch_all($res); - if (count($rvs) != $rows) { - $notice = pg_last_notice($res); + $rvs = pg_fetch_all( $res ); + if ( count( $rvs ) != $rows ) { + $notice = pg_last_notice( $res ); $templateData['genError'] = 'While reading base rv data, we did not receive the expected number of rvs! '; - if ($notice) { + if ( $notice ) { $templateData['genError'] .= 'Perhaps the following message will help.
'.$notice; } $failure = true; } - echo '
$rvs: ' . print_r( $rvs, true ) . '
'; + //echo '
$rvs: ' . print_r( $rvs, true ) . '
'; } } -if (!$failure) { - // Get current db version - $dbVersion = GLM_MEMBERS_PLUGIN_DB_VERSION; - +// 2. Get the homes data +if ( !$failure ) { + // Grab the Homes data + $sql = " + SELECT * + FROM homes + ORDER BY id"; + $res = pg_query( $db, $sql ); + $rows = pg_num_rows( $res ); + if ( $rows == 0 ) { + $templateData['genError'] = 'There does not appear to be any homes listed in this database!'; + $failure = true; + } else { + $homes = pg_fetch_all( $res ); + if ( count( $homes ) != $rows ) { + $notice = pg_last_notice( $res ); + $templateData['genError'] = 'While reading base homes data, we did not receive the expected number of homes! '; + if ( $notice ) { + $templateData['genError'] .= 'Perhaps the following message will help.
'.$notice; + } + $failure = true; + } + //echo '
$homes: ' . print_r( $homes, true ) . '
'; + } +} +// Reset member data tables if needed +if ( !$failure && $resetdb ) { // Reset the database - if (!$this->deleteDataTables($dbVersion)) { + if ( !$this->deleteDataTables( GLM_MEMBERS_PLUGIN_DB_VERSION ) ) { glmMembersAdmin::addNotice('Unable to delete the database tables while resetting the database.
', 'AdminError'); break; } - if (!$this->createDataTables($dbVersion)) { + if ( !$this->createDataTables( GLM_MEMBERS_PLUGIN_DB_VERSION ) ) { glmMembersAdmin::addNotice('Unable to create the database tables while resetting the database.
', 'AdminError'); break; } } +// 3. Get amenities data +if ( !$failure ) { + // Grab the amenity data + $sql = " + SELECT * + FROM amenities + ORDER BY id"; + $res = pg_query( $db, $sql ); + $rows = pg_num_rows( $res ); + if ( $rows == 0 ) { + $templateData['genError'] = 'There does not appear to be any amenities listed in this database!'; + $failure = true; + } else { + $amenities = pg_fetch_all( $res ); + if ( count( $amenities ) != $rows ) { + $notice = pg_last_notice( $res ); + $templateData['genError'] = 'While reading base amenity data, we did not receive the expected number of amenities! '; + if ( $notice ) { + $templateData['genError'] .= 'Perhaps the following message will help.
'.$notice; + } + $failure = true; + } + echo '
$amenities: ' . print_r( $amenities, true ) . '
'; + } +} +// 4. Get amenity member relation data +if ( !$failure ) { + // Grab the amenity data + $sql = " + SELECT * + FROM rvs_amenities + ORDER BY id"; + $res = pg_query( $db, $sql ); + $rows = pg_num_rows( $res ); + if ( $rows == 0 ) { + $templateData['genError'] = 'There does not appear to be any amenity relation listed in this database!'; + $failure = true; + } else { + $amenityData = pg_fetch_all( $res ); + if ( count( $amenityData ) != $rows ) { + $notice = pg_last_notice( $res ); + $templateData['genError'] = 'While reading base amenity relation data, we did not receive the expected number of amenityData! '; + if ( $notice ) { + $templateData['genError'] .= 'Perhaps the following message will help.
'.$notice; + } + $failure = true; + } + echo '
$amenityData: ' . print_r( $amenityData, true ) . '
'; + } +} +// 5. Get categories +// 6. Get category member relation data + -- 2.17.1