--- /dev/null
+<?php
+/**
+ * Import Brewbakers Files
+ * Will have to do these 10 to 20 at a time.
+ */
+
+$failure = false;
+// Setup the database connection to postgres
+$dbServer = 'ds4';
+$dbName = 'brewbakers';
+$dbUser = 'postgres';
+$resetdb = true;
+$start = ( isset( $_REQUEST['start'] ) ) ? filter_var( $_REQUEST['start'], FILTER_VALIDATE_INT ): 0;
+$limit = ( $start === 0 ) ? 20 : 100;
+$totalFiles = 0;
+
+$connString = "host=$dbServer dbname=$dbName user=$dbUser";
+$db = @pg_connect( $connString );
+
+$refType = $this->config['ref_type_numb']['MemberInfo'];
+$refTable = $this->config['ref_type_table'][$refType];
+function getCategoryId( $wpdb, $name, $parent )
+{
+ // check to see if the category already exists
+ return $wpdb->get_var(
+ $wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "categories
+ WHERE name = %s
+ AND parent = %d",
+ $name,
+ $parent
+ )
+ );
+}
+$rvBrandId = getCategoryId( $this->wpdb, 'Brands', 0 );
+// Read in all rvs
+$file = array();
+$numbFilesFound = 0;
+if (!$failure && $start === 0) {
+ $sql = "
+ SELECT r.*,
+ b.name as brand_name,
+ c.name as class_name,
+ man.name as manufacturer_name
+ FROM rvs r, brands b, manufacturer man, class c
+ WHERE r.brand = b.id
+ AND r.class = c.id
+ AND r.manufacturer = man.id
+ ORDER BY r.id";
+ $res = pg_query($db, $sql);
+ $rows = pg_num_rows($res);
+ if ($rows == 0) {
+ $templateData['genError'] = 'There does not appear to be any member files listed in this database!';
+ $failure = true;
+ } else {
+ $rvs = pg_fetch_all($res);
+ if (count($rvs) != $rows) {
+ $notice = pg_last_notice($res);
+ $templateData['genError'] = 'While reading member photo data, we did not receive the expected number of member files! ';
+ if ($notice) {
+ $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
+ }
+ $failure = true;
+ } else {
+ foreach ( $rvs as $rv ) {
+ $rvCat = array();
+ // Set up the brands
+ // Get the new member info id
+ $infoID = getMemberInfoIdFromOldMemberId( $this->wpdb, $rv['id'] );
+ // get the new brand id
+ $rvBrand = getCategoryId( $this->wpdb, $rv['brand_name'], $rvBrandId );
+ if ( $infoID && $rvBrandId ) {
+ $rvCat[] = array(
+ 'category' => $rvBrand,
+ 'member_info' => $infoID
+ );
+ }
+ // Add Member Categories
+ if (isset($rvCat) && count($rvCat) > 0) {
+ foreach ($rvCat as $catMemData) {
+ $res = $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'category_member_info',
+ $catMemData,
+ array(
+ '%d',
+ '%d'
+ )
+ );
+
+ }
+ }
+ }
+ }
+ }
+}
+echo '<pre>$rvs: ' . print_r( $rvs, true ) . '</pre>';
+exit;
+
+function getMemberInfoIdFromOldMemberId( $wpdb, $oldMemberId )
+{
+ return $wpdb->get_var(
+ $wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info
+ WHERE member IN (
+ SELECT id
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+ WHERE old_member_id = %d)",
+ $oldMemberId
+ )
+ );
+}
+
+
+$templateData['newStart'] = $start + $limit;
+$templateData['start'] = $start;
+$templateData['total'] = $totalFiles;
+$templateData['numbFilesFound'] = $numbFilesFound;
+
+$requestedView = 'import/brewbakersFiles.html';