Get member data from homes rvs amenities
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 4 Apr 2017 17:09:52 +0000 (13:09 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 4 Apr 2017 17:09:52 +0000 (13:09 -0400)
Getting member data for import.

models/admin/management/import/brewbakersImport.php

index effa709..0f6b6eb 100644 (file)
@@ -6,50 +6,130 @@ echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
 $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...<br>'.$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.<br>'.$notice;
             }
             $failure = true;
         }
-        echo '<pre>$rvs: ' . print_r( $rvs, true ) . '</pre>';
+        //echo '<pre>$rvs: ' . print_r( $rvs, true ) . '</pre>';
     }
 }
-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.<br>'.$notice;
+            }
+            $failure = true;
+        }
+        //echo '<pre>$homes: ' . print_r( $homes, true ) . '</pre>';
+    }
+}
+// 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('<b>Unable to delete the database tables while resetting the database.</b><br>', 'AdminError');
         break;
     }
-    if (!$this->createDataTables($dbVersion)) {
+    if ( !$this->createDataTables( GLM_MEMBERS_PLUGIN_DB_VERSION ) ) {
         glmMembersAdmin::addNotice('<b>Unable to create the database tables while resetting the database.</b><br>', '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.<br>'.$notice;
+            }
+            $failure = true;
+        }
+        echo '<pre>$amenities: ' . print_r( $amenities, true ) . '</pre>';
+    }
+}
+// 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.<br>'.$notice;
+            }
+            $failure = true;
+        }
+        echo '<pre>$amenityData: ' . print_r( $amenityData, true ) . '</pre>';
+    }
+}
+// 5. Get categories
+// 6. Get category member relation data
+