From: Steve Sutton Date: Fri, 7 Apr 2017 18:11:37 +0000 (-0400) Subject: Updating the brewakers import scripts. X-Git-Tag: v2.9.15^2~51 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=fbab7520650eb0b3c1c8c86d05a404b580f5c7c1;p=WP-Plugins%2Fglm-member-db.git Updating the brewakers import scripts. Wrapping up the import scripts for files and the images. Fix for one of the custom field types. When the boolean field is pulled it's t or f have to translate that to Yes and No. --- diff --git a/models/admin/management/import.php b/models/admin/management/import.php index 473db858..e066a209 100644 --- a/models/admin/management/import.php +++ b/models/admin/management/import.php @@ -146,6 +146,14 @@ class GlmMembersAdmin_management_import require GLM_MEMBERS_PLUGIN_PATH.'/models/admin/management/import/memberImages.php'; break; + case 'brewbakersImages': + require GLM_MEMBERS_PLUGIN_PATH.'/models/admin/management/import/brewbakersImages.php'; + break; + + case 'brewbakersFiles': + require GLM_MEMBERS_PLUGIN_PATH.'/models/admin/management/import/brewbakersFiles.php'; + break; + case 'importOldMemberIds': require GLM_MEMBERS_PLUGIN_PATH.'/models/admin/management/import/oldMemberIds.php'; break; @@ -156,7 +164,6 @@ class GlmMembersAdmin_management_import case 'importBrewbakers': require GLM_MEMBERS_PLUGIN_PATH.'/models/admin/management/import/brewbakersImport.php'; - exit; break; default: diff --git a/models/admin/management/import/brewbakersFiles.php b/models/admin/management/import/brewbakersFiles.php new file mode 100644 index 00000000..a6c28c62 --- /dev/null +++ b/models/admin/management/import/brewbakersFiles.php @@ -0,0 +1,180 @@ +wpdb, $this->config); + +$refType = $this->config['ref_type_numb']['MemberInfo']; +$refTable = $this->config['ref_type_table'][$refType]; + +$fileBaseURL = 'http://www.brewbakers.com/uploads/homes_files/'; + + +// Read in all member files for Homes and RV's +$file = array(); +$numbFilesFound = 0; +if (!$failure && $start === 0) { + // Grab the files for homes + $sql = " + SELECT * + FROM homes_files + ORDER BY homes_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 { + $tmp = pg_fetch_all($res); + if (count($tmp) != $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.
'.$notice; + } + $failure = true; + } else { + + // Reprocess into array grouped by member with the main index the member ID + foreach ($tmp as $x) { + + // If member entry hasn't been created yet, add it now + if (!isset($file['homes'][$x['homes_id']])) { + $file['homes'][$x['homes_id']] = array( + 'homes_id' => $x['homes_id'], + 'files' => array() + ); + } + + $file['homes'][$x['homes_id']]['files'][] = $x; + $numbFilesFound++; + } + //echo '
$file: ' . print_r( $file, true ) . '
'; + } + } +} +if (!$failure) { + // Get total count + $sql = " + SELECT count(*) as total + FROM rvs_files"; + $res = pg_query($db, $sql); + $totalFiles = pg_fetch_result( $res, 0, 'total'); + + // Grab the files for rvs + $sql = " + SELECT * + FROM rvs_files + ORDER BY rvs_id"; + $sql .= " LIMIT $limit OFFSET $start"; + $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 { + $tmp = pg_fetch_all($res); + if (count($tmp) != $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.
'.$notice; + } + $failure = true; + } else { + + // Reprocess into array grouped by member with the main index the member ID + foreach ($tmp as $x) { + + // If member entry hasn't been created yet, add it now + if (!isset($file['rvs'][$x['rvs_id']])) { + $file['rvs'][$x['rvs_id']] = array( + 'rvs_id' => $x['rvs_id'], + 'files' => array() + ); + } + + $file['rvs'][$x['rvs_id']]['files'][] = $x; + $numbFilesFound++; + } + //echo '
$file: ' . print_r( $file, true ) . '
'; + } + } +} +//echo '
$file: ' . print_r( $file, true ) . '
'; +//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 + ) + ); +} +//echo '
$file: ' . print_r( $file, true ) . '
'; +//exit; +// Reset member files data tables if needed +if ( !$failure && $resetdb && $start === 0 ) { + // Reset the data + $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX."files" ); + + // Delete Files + foreach( new RecursiveIteratorIterator( + + new RecursiveDirectoryIterator( GLM_MEMBERS_PLUGIN_FILES_PATH, FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS ), + RecursiveIteratorIterator::CHILD_FIRST ) as $value ) { + if ($value->isFile()) { + unlink( $value ); + } + } +} +// If we have file URLs +if ($file != false) { + + // For each member + foreach ($file as $memType) { + foreach ($memType as $oldMemberId => $m) { + + $newMemberId = getMemberInfoIdFromOldMemberId( $this->wpdb, $oldMemberId); + + // For each file in this member's gallery + if ($m['files']) { + foreach ($m['files'] as $i) { + $fileURL = $fileBaseURL.$i['name_on_disk']; + $res = $FileUpload->storeFile ($fileURL, $refType, $refTable, $newMemberId, $i['original_name']); + } + } + + } + } + +} + +$templateData['newStart'] = $start + $limit; +$templateData['start'] = $start; +$templateData['total'] = $totalFiles; +$templateData['numbFilesFound'] = $numbFilesFound; + +$requestedView = 'import/brewbakersFiles.html'; diff --git a/models/admin/management/import/brewbakersImages.php b/models/admin/management/import/brewbakersImages.php new file mode 100644 index 00000000..d42afa79 --- /dev/null +++ b/models/admin/management/import/brewbakersImages.php @@ -0,0 +1,200 @@ +wpdb, $this->config); + +$refType = $this->config['ref_type_numb']['MemberInfo']; +$refTable = $this->config['ref_type_table'][$refType]; + +// Get image array stored in a WordPress option +$imageBaseURL = 'http://is0.gaslightmedia.com/brewbakers/CKImage/'; + + +// Read in all member photos for Homes and RV's +$image = array(); +$numbImagesFound = 0; +if (!$failure && $start === 0) { + // Grab the photos for homes + $sql = " + SELECT * + FROM homes_photos + ORDER BY homes_id,pos"; + $res = pg_query($db, $sql); + $rows = pg_num_rows($res); + if ($rows == 0) { + $templateData['genError'] = 'There does not appear to be any member photos listed in this database!'; + $failure = true; + } else { + $tmp = pg_fetch_all($res); + if (count($tmp) != $rows) { + $notice = pg_last_notice($res); + $templateData['genError'] = 'While reading member photo data, we did not receive the expected number of member photos! '; + if ($notice) { + $templateData['genError'] .= 'Perhaps the following message will help.
'.$notice; + } + $failure = true; + } else { + + // Reprocess into array grouped by member with the main index the member ID + foreach ($tmp as $x) { + + // If member entry hasn't been created yet, add it now + if (!isset($image['homes'][$x['homes_id']])) { + $image['homes'][$x['homes_id']] = array( + 'homes_id' => $x['homes_id'], + 'images' => array() + ); + } + + $image['homes'][$x['homes_id']]['images'][] = $x; + $numbImagesFound++; + } + //echo '
$image: ' . print_r( $image, true ) . '
'; + } + } +} +if (!$failure) { + // Get total count + $sql = " + SELECT count(*) as total + FROM rvs_photos"; + $res = pg_query($db, $sql); + $totalImages = pg_fetch_result( $res, 0, 'total'); + + // Grab the photos for rvs + $sql = " + SELECT * + FROM rvs_photos + ORDER BY rvs_id,pos"; + $sql .= " LIMIT $limit OFFSET $start"; + $res = pg_query($db, $sql); + $rows = pg_num_rows($res); + if ($rows == 0) { + $templateData['genError'] = 'There does not appear to be any member photos listed in this database!'; + $failure = true; + } else { + $tmp = pg_fetch_all($res); + if (count($tmp) != $rows) { + $notice = pg_last_notice($res); + $templateData['genError'] = 'While reading member photo data, we did not receive the expected number of member photos! '; + if ($notice) { + $templateData['genError'] .= 'Perhaps the following message will help.
'.$notice; + } + $failure = true; + } else { + + // Reprocess into array grouped by member with the main index the member ID + foreach ($tmp as $x) { + + // If member entry hasn't been created yet, add it now + if (!isset($image['rvs'][$x['rvs_id']])) { + $image['rvs'][$x['rvs_id']] = array( + 'rvs_id' => $x['rvs_id'], + 'images' => array() + ); + } + + $image['rvs'][$x['rvs_id']]['images'][] = $x; + $numbImagesFound++; + } + //echo '
$image: ' . print_r( $image, true ) . '
'; + } + } +} +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 + ) + ); +} +//echo '
$image: ' . print_r( $image, true ) . '
'; +//exit; +// Reset member images data tables if needed +if ( !$failure && $resetdb && $start === 0 ) { + // Reset the data + $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX."images" ); + + // Delete Images + foreach( new RecursiveIteratorIterator( + + new RecursiveDirectoryIterator( GLM_MEMBERS_PLUGIN_IMAGES_PATH, FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS ), + RecursiveIteratorIterator::CHILD_FIRST ) as $value ) { + if ($value->isFile()) { + unlink( $value ); + } + } +} +// If we have image URLs +if ($image != false) { + + // For each member + foreach ($image as $memType) { + foreach ($memType as $oldMemberId => $m) { + + $newMemberId = getMemberInfoIdFromOldMemberId( $this->wpdb, $oldMemberId); + + // For each image in this member's gallery + if ($m['images']) { + foreach ($m['images'] as $i) { + // If this is the first image (pos == 1) then add it as the logo + if ( $i['pos'] == 1 ) { + $imageURL = $imageBaseURL.$i['image']; + $res = $ImageUpload->storeImage ($imageURL); + + // If we got a good new filename back, then it should be a good image store + if ($res['newFileName']) { + + // Update the member record with the logo image name + $res = $this->wpdb->update( + GLM_MEMBERS_PLUGIN_DB_PREFIX.'member_info', + array( + 'logo' => $res['newFileName'] + ), + array( 'id' => $newMemberId ), + array( '%s' ), + array( '%d' ) + ); + } + } + + $imageURL = $imageBaseURL.$i['image']; + $res = $ImageUpload->storeImage ($imageURL, $refType, $refTable, $newMemberId, $i['caption']); + } + } + + } + } + +} + +$templateData['newStart'] = $start + $limit; +$templateData['start'] = $start; +$templateData['total'] = $totalImages; +$templateData['numbImagesFound'] = $numbImagesFound; + +$requestedView = 'import/brewbakersImages.html'; diff --git a/models/admin/management/import/brewbakersImport.php b/models/admin/management/import/brewbakersImport.php index cec72b95..4f0439c1 100644 --- a/models/admin/management/import/brewbakersImport.php +++ b/models/admin/management/import/brewbakersImport.php @@ -1,12 +1,14 @@ $_REQUEST: ' . print_r( $_REQUEST, true ) . ''; +// Setup the brewbakers image url +$dbImageURL = 'http://is0.gaslightmedia.com/brewbakers/CKImage/'; +//echo '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; +$rvLimit = false; // set to false to turn off limit // Setup the database connection to postgres -$dbServer = 'ds4'; +$dbServer = 'localhost'; $dbName = 'brewbakers'; $dbUser = 'postgres'; -$resetdb = false; +$resetdb = true; $rvs = array(); $homes = array(); $amenities = array(); @@ -33,6 +35,9 @@ if ( !$failure ) { AND r.class = c.id AND r.manufacturer = man.id ORDER BY r.id"; + if ( $rvLimit ) { + $sql .= " LIMIT $rvLimit OFFSET 0"; + } $res = pg_query( $db, $sql ); $rows = pg_num_rows( $res ); if ( $rows == 0 ) { @@ -79,20 +84,18 @@ if ( !$failure ) { } $failure = true; } - echo '
$homes: ' . print_r( $homes, true ) . '
'; + //echo '
$homes: ' . print_r( $homes, true ) . '
'; } } // Reset member data tables if needed if ( !$failure && $resetdb ) { - // Reset the database - 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( GLM_MEMBERS_PLUGIN_DB_VERSION ) ) { - glmMembersAdmin::addNotice('Unable to create the database tables while resetting the database.
', 'AdminError'); - break; - } + // Reset the data + $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX."members" ); + $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info" ); + $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX."category_member_info" ); + //$this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX."amenities" ); + $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX."amenity_ref" ); + $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX."custom_field_data" ); } // 3. Get amenities data if ( !$failure ) { @@ -120,6 +123,7 @@ if ( !$failure ) { } } // 4. Get amenity member relation data +$numbAmenityMembers = 0; if ( !$failure ) { // Grab the amenity data $sql = " @@ -132,8 +136,8 @@ if ( !$failure ) { $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 ) { + $tmp = pg_fetch_all( $res ); + if ( count( $tmp ) != $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 ) { @@ -141,9 +145,21 @@ if ( !$failure ) { } $failure = true; } - //echo '
$amenityData: ' . print_r( $amenityData, true ) . '
'; + $rvAmen = array(); + foreach ( $tmp as $x ) { + // if rv entry hasn't been created yet, add it now + if ( !isset( $rvAmen[$x['rvs_id']] ) ) { + $rvAmen[$x['rvs_id']] = array(); + } + + $rvAmen[$x['rvs_id']][] = $x; + $numbAmenityMembers++; + } } } +//echo '
$rvAmen: ' . print_r( $rvAmen, true ) . '
'; +//var_dump($rvAmen); +//exit; function getCategoryId( $wpdb, $name, $parent ) { // check to see if the category already exists @@ -158,6 +174,59 @@ function getCategoryId( $wpdb, $name, $parent ) ) ); } +function getCustomFieldId( $wpdb, $name ) +{ + return $wpdb->get_var( + $wpdb->prepare( + "SELECT id + FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_fields + WHERE field_name = %s", + $name + ) + ); +} +$customFieldIds = array( + 'year' => getCustomFieldId( $this->wpdb, 'Year' ), + 'model' => getCustomFieldId( $this->wpdb, 'Model' ), + 'color' => getCustomFieldId( $this->wpdb, 'Color' ), + 'length' => getCustomFieldId( $this->wpdb, 'Length' ), + 'weight' => getCustomFieldId( $this->wpdb, 'UVW lbs' ), + 'sleeping_capacity' => getCustomFieldId( $this->wpdb, 'Sleeping Capacity' ), + 'slide_outs' => getCustomFieldId( $this->wpdb, 'Slide Outs' ), + 'fresh_water_tank_size' => getCustomFieldId( $this->wpdb, 'Fresh Water (gal)' ), + 'black_tank_size' => getCustomFieldId( $this->wpdb, 'Black Water (gal)' ), + 'grey_tank_size' => getCustomFieldId( $this->wpdb, 'Gray Water (gal)' ), + 'stock_numb' => getCustomFieldId( $this->wpdb, 'Stock #' ), + 'msrp' => getCustomFieldId( $this->wpdb, 'MSRP' ), + 'make' => getCustomFieldId( $this->wpdb, 'Make' ), + 'bedrooms' => getCustomFieldId( $this->wpdb, 'Bedrooms' ), + 'bathrooms' => getCustomFieldId( $this->wpdb, 'Bathrooms' ), + 'sqft' => getCustomFieldId( $this->wpdb, 'Square Footage' ), + 'just_arrived' => getCustomFieldId( $this->wpdb, 'Just Arrived' ), + 'red_hot_deal' => getCustomFieldId( $this->wpdb, 'Red Hot Deal' ), + 'used' => getCustomFieldId( $this->wpdb, 'Used' ), +); +//echo '
$customFieldIds: ' . print_r( $customFieldIds, true ) . '
'; +function addCustomFieldData( $wpdb, $customFieldIds, $ref_dest, $fieldName, $fieldValue ) +{ + // check the $fieldValue for t or f + if ( $fieldValue ) { + if ( $fieldValue == 't' ) { + $fieldValue = 'Yes'; + } elseif ( $fieldValue == 'f' ) { + $fieldValue = 'No'; + } + } + $wpdb->insert( + GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . 'custom_field_data', + array( + 'field_id' => $customFieldIds[$fieldName], + 'ref_dest' => $ref_dest, + 'field_data' => ($fieldValue) ? $fieldValue: '', + ), + array( '%d', '%d', '%s' ) + ); +} // 5. Get categories // Setup three main level categories // Brands, Manufactures, and Classes @@ -189,8 +258,8 @@ function addNewCategory( $wpdb, $name, $parent ) // Grab the Brands from Brewbakers if ( !$failure ) { // Add new main level for Brands - $brandId = addNewCategory( $this->wpdb, 'Brands', 0 ); - echo '
$brandId: ' . print_r( $brandId, true ) . '
'; + $rvBrandId = addNewCategory( $this->wpdb, 'Brands', 0 ); + //echo '
$rvBrandId: ' . print_r( $rvBrandId, true ) . '
'; // Get all Brands and add them as sub categories $sql = " SELECT id,name @@ -213,16 +282,16 @@ if ( !$failure ) { } //echo '
$brands: ' . print_r( $brands, true ) . '
'; foreach ( $brands as $key => $val ) { - //echo '
Adding category for ' . $val['name'] . ' parent ' . $brandId . '
'; - $newCatId = addNewCategory( $this->wpdb, $val['name'], $brandId ); + //echo '
Adding category for ' . $val['name'] . ' parent ' . $rvBrandId . '
'; + $newCatId = addNewCategory( $this->wpdb, $val['name'], $rvBrandId ); } } } // Grab the Housing Manufacturers if ( !$failure ) { // Add new main level for Brands - $manufacturerId = addNewCategory( $this->wpdb, 'Housing Manufacturers', 0 ); - echo '
$manufacturerId: ' . print_r( $manufacturerId, true ) . '
'; + $homeManufacturerId = addNewCategory( $this->wpdb, 'Housing Manufacturers', 0 ); + //echo '
$homeManufacturerId: ' . print_r( $homeManufacturerId, true ) . '
'; // Get all Manufactures from housing section and add them as sub categories $sql = " SELECT id,name @@ -246,16 +315,16 @@ if ( !$failure ) { } //echo '
$houseMan: ' . print_r( $houseMan, true ) . '
'; foreach ( $houseMan as $key => $val ) { - //echo '
Adding category for ' . $val['name'] . ' parent ' . $manufacturerId . '
'; - $newCatId = addNewCategory( $this->wpdb, $val['name'], $manufacturerId ); + //echo '
Adding category for ' . $val['name'] . ' parent ' . $homeManufacturerId . '
'; + $newCatId = addNewCategory( $this->wpdb, $val['name'], $homeManufacturerId ); } } } // Grab the RV Manufacturers if ( !$failure ) { // Add new main level for Brands - $manufacturerId = addNewCategory( $this->wpdb, 'RV Manufacturers', 0 ); - echo '
$manufacturerId: ' . print_r( $manufacturerId, true ) . '
'; + $rvManufacturerId = addNewCategory( $this->wpdb, 'RV Manufacturers', 0 ); + //echo '
$rvManufacturerId: ' . print_r( $rvManufacturerId, true ) . '
'; // Get all Manufactures from rvs section and add them as sub categories $sql = " SELECT id,name @@ -279,16 +348,16 @@ if ( !$failure ) { } //echo '
$rvMan: ' . print_r( $rvMan, true ) . '
'; foreach ( $rvMan as $key => $val ) { - //echo '
Adding category for ' . $val['name'] . ' parent ' . $manufacturerId . '
'; - $newCatId = addNewCategory( $this->wpdb, $val['name'], $manufacturerId ); + //echo '
Adding category for ' . $val['name'] . ' parent ' . $rvManufacturerId . '
'; + $newCatId = addNewCategory( $this->wpdb, $val['name'], $rvManufacturerId ); } } } // Grab the Housing Classes if ( !$failure ) { // Add new main level for Brands - $classId = addNewCategory( $this->wpdb, 'Housing Classes', 0 ); - echo '
$classId: ' . print_r( $classId, true ) . '
'; + $homeClassId = addNewCategory( $this->wpdb, 'Housing Classes', 0 ); + //echo '
$homeClassId: ' . print_r( $homeClassId, true ) . '
'; // Get all Manufactures from housing section and add them as sub categories $sql = " SELECT id,name @@ -312,16 +381,16 @@ if ( !$failure ) { } //echo '
$houseClass: ' . print_r( $houseClass, true ) . '
'; foreach ( $houseClass as $key => $val ) { - //echo '
Adding category for ' . $val['name'] . ' parent ' . $classId . '
'; - $newCatId = addNewCategory( $this->wpdb, $val['name'], $classId ); + //echo '
Adding category for ' . $val['name'] . ' parent ' . $homeClassId . '
'; + $newCatId = addNewCategory( $this->wpdb, $val['name'], $homeClassId ); } } } // Grab the RV Classes if ( !$failure ) { // Add new main level for Brands - $classId = addNewCategory( $this->wpdb, 'RV Classes', 0 ); - echo '
$classId: ' . print_r( $classId, true ) . '
'; + $rvClassId = addNewCategory( $this->wpdb, 'RV Classes', 0 ); + //echo '
$rvClassId: ' . print_r( $rvClassId, true ) . '
'; // Get all Manufactures from rvs section and add them as sub categories $sql = " SELECT id,name @@ -345,16 +414,16 @@ if ( !$failure ) { } //echo '
$rvClass: ' . print_r( $rvClass, true ) . '
'; foreach ( $rvClass as $key => $val ) { - //echo '
Adding category for ' . $val['name'] . ' parent ' . $classId . '
'; - $newCatId = addNewCategory( $this->wpdb, $val['name'], $classId ); + //echo '
Adding category for ' . $val['name'] . ' parent ' . $rvClassId . '
'; + $newCatId = addNewCategory( $this->wpdb, $val['name'], $rvClassId ); } } } // Grab the Homes Models if ( !$failure ) { // Add new main level for Models - $modelId = addNewCategory( $this->wpdb, 'Home Models', 0 ); - echo '
$modelId: ' . print_r( $modelId, true ) . '
'; + $homeModelId = addNewCategory( $this->wpdb, 'Home Models', 0 ); + //echo '
$homeModelId: ' . print_r( $homeModelId, true ) . '
'; // Get all Manufactures from rvs section and add them as sub categories $sql = " SELECT id,name @@ -378,8 +447,8 @@ if ( !$failure ) { } //echo '
$homeModel: ' . print_r( $homeModel, true ) . '
'; foreach ( $homeModel as $key => $val ) { - //echo '
Adding category for ' . $val['name'] . ' parent ' . $modelId . '
'; - $newCatId = addNewCategory( $this->wpdb, $val['name'], $modelId ); + //echo '
Adding category for ' . $val['name'] . ' parent ' . $homeModelId . '
'; + $newCatId = addNewCategory( $this->wpdb, $val['name'], $homeModelId ); } } } @@ -438,8 +507,20 @@ function addNewAmenity( $wpdb, $name ) // Add the category $wpdb->insert( GLM_MEMBERS_PLUGIN_DB_PREFIX . 'amenities', - array( 'name' => $name ), - '%s' + array( + 'active' => true, + 'name' => $name, + 'descr' => '', + 'short_descr' => '', + 'ref_type' => 20 + ), + array( + '%d', + '%s', + '%s', + '%s', + '%d' + ) ); return $wpdb->insert_id; } @@ -449,9 +530,9 @@ if (!$failure) { // Import Amenities while (list ($key, $val) = each ($amenity) ) { $amenityId = addNewAmenity( $this->wpdb, $val['name'] ); - $amenity[$key]['new_id'] = $this->wpdb->insert_id; + $amenity[$key]['new_id'] = $amenityId; } - //echo '
$amenity: ' . print_r( $amenity, true ) . '
'; + //echo '
new $amenity: ' . print_r( $amenity, true ) . '
'; } function getMemberTypeId( $wpdb, $name ) { @@ -489,48 +570,6 @@ if (!$failure) { // Add member type for Homes $homeMemberType = addNewMemberType( $this->wpdb, 'Home' ); } -// Read in all member photos for Homes and RV's -$image = array(); -$numbImagesFound = 0; -if (!$failure) { - $sql = " - SELECT * - FROM homes_photos - ORDER BY homes_id,pos"; - $res = pg_query($db, $sql); - $rows = pg_num_rows($res); - if ($rows == 0) { - $templateData['genError'] = 'There does not appear to be any member photos listed in this database!'; - $failure = true; - } else { - $tmp = pg_fetch_all($res); - if (count($tmp) != $rows) { - $notice = pg_last_notice($res); - $templateData['genError'] = 'While reading member photo data, we did not receive the expected number of member photos! '; - if ($notice) { - $templateData['genError'] .= 'Perhaps the following message will help.
'.$notice; - } - $failure = true; - } else { - - // Reprocess into array grouped by member with the main index the member ID - foreach ($tmp as $x) { - - // If member entry hasn't been created yet, add it now - if (!isset($image[$x['homes_id']])) { - $image[$x['homes_id']] = array( - 'homes_id' => $x['homes_id'], - 'images' => array() - ); - } - - $image[$x['homes_id']]['images'][] = $x; - $numbImagesFound++; - } - //echo '
$image: ' . print_r( $image, true ) . '
'; - } - } -} if (!$failure) { // Import Members $numbMembersActive = 0; @@ -547,10 +586,9 @@ if (!$failure) { // Check for duplicate name // Build out the Home name from year make model class $membName = sprintf( - "%s %s %s %s", + "%s %s %s", $val['year'], $val['make'], - $val['model_name'], $val['class_name'] ); if (isset($namesInserted[$membName])) { @@ -572,6 +610,189 @@ if (!$failure) { 'created' => date('Y-m-d'), 'name' => $membName, 'member_slug' => sanitize_title($membName), + 'featured' => ($val['featured'] == 't') ? 1: 0, + 'old_member_id' => $val['id'] + ), + array( + '%d', + '%d', + '%s', + '%s', + '%s', + '%d', + '%d' + ) + ); + $membID = $this->wpdb->insert_id; + $member[$key]['new_id'] = $membID; + + // Add this member to the names inserted so we can check for duplicates + $namesInserted[$membName] = true; + + // Insert Member Information Record + $res = $this->wpdb->insert( + GLM_MEMBERS_PLUGIN_DB_PREFIX.'member_info', + array( + 'member' => $membID, + 'member_name' => $membName, + 'status' => $this->config['status_numb']['Active'], + 'reference_name' => 'Imported Member Information', + 'descr' => preg_replace('%[\n\r]%', '', $val['description']), + 'short_descr' => '', + 'addr1' => '', + 'addr2' => '', + 'city' => 0, + 'state' => 0, + 'country' => '', + 'zip' => '', + 'lat' => 0, + 'lon' => 0, + 'region' => 0, + 'phone' => '', + 'toll_free' => '', + 'url' => '', + 'email' => '', + 'logo' => '', + 'cc_type' => 0, + 'notes' => '', + 'create_time' => $val['created'], + 'modify_time' => '' + ), + array( + '%d', + '%s', + '%d', + '%s', + '%s', + '%s', + '%s', + '%s', + '%d', + '%s', + '%s', + '%s', + '%f', + '%f', + '%d', + '%s', + '%s', + '%s', + '%s', + '%s', + '%d', + '%s', + '%s', + '%s' + ) + ); + $infoID = $this->wpdb->insert_id; + $member[$key]['new_info_id'] = $infoID; + $homeModel = $homeClass = $homeManufacturer = 0; + $homeCat = array(); + + // Add Member Categories + // Get category id for the model_name + $homeModel = getCategoryId( $this->wpdb, $val['model_name'], $homeModelId ); + if ( $homeModel ) { + $homeCat[] = array( + 'category' => $homeModel, + 'member_info' => $infoID + ); + } + // Get category id for the class_name + $homeClass = getCategoryId( $this->wpdb, $val['class_name'], $homeClassId ); + if ( $homeClass ) { + $homeCat[] = array( + 'category' => $homeClass, + 'member_info' => $infoID + ); + } + // Get category id for the manufacturer_name + $homeManufacturer = getCategoryId( $this->wpdb, $val['manufacturer_name'], $homeManufacturerId ); + if ( $homeManufacturer ) { + $homeCat[] = array( + 'category' => $homeManufacturer, + 'member_info' => $infoID + ); + } + // Add Member Categories + if (isset($homeCat)) { + foreach ($homeCat as $catMemData) { + + $res = $this->wpdb->insert( + GLM_MEMBERS_PLUGIN_DB_PREFIX.'category_member_info', + $catMemData, + array( + '%d', + '%d' + ) + ); + + } + } + + // Add Member Amenities (only for rvs) + + // Add Custom Fields + // year + addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'year', $val['year'] ); + // make + addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'make', $val['make'] ); + // color + addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'color', $val['color'] ); + // Stock Number + addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'stock_numb', $val['stock_numb'] ); + // MSRP + addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'msrp', $val['msrp'] ); + // Bedrooms + addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'bedrooms', $val['bedrooms'] ); + // Bathrooms + addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'bathrooms', $val['bathrooms'] ); + // Square Footage + addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'sqft', $val['sqft'] ); + // Used + addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'used', $val['used'] ); + + } + //echo '
$member: ' . print_r( $member, true ) . '
'; +} + +$haveCatImportIssues = false; +$catImportIssues = ''; +if (!$failure) { + while (list ($key, $val) = each ($rvs) ) { + // Member is active, so set to active-moderated + $access = $this->config['access_numb']['Moderated']; + $numbMembersActive++; + + // Check for duplicate name + // Build out the Home name from year make model class + $membName = sprintf( + "%s %s %s", + $val['year'], + $val['model_name'], + $val['stock_numb'] + ); + if (isset($namesInserted[$membName])) { + + // Bump dupe count and add to name to make this one unique + $dupeNames++; + $membName .= ' DUPE-'.$dupeNames; + + $membImportIssues .= '
  • Member Duplicate '.$membName.'
  • '; + $haveMembImportIssues = true; + + } + // Add main member record + $res = $this->wpdb->insert( + GLM_MEMBERS_PLUGIN_DB_PREFIX.'members', + array( + 'access' => $access, + 'member_type' => $rvMemberType, + 'created' => date('Y-m-d'), + 'name' => $membName, + 'member_slug' => sanitize_title($membName), + 'featured' => ($val['featured'] == 't') ? 1: 0, 'old_member_id' => $val['id'] ), array( @@ -580,11 +801,200 @@ if (!$failure) { '%s', '%s', '%s', + '%d', '%d' ) ); $membID = $this->wpdb->insert_id; $member[$key]['new_id'] = $membID; + + // Add this member to the names inserted so we can check for duplicates + $namesInserted[$membName] = true; + + // Insert Member Information Record + $res = $this->wpdb->insert( + GLM_MEMBERS_PLUGIN_DB_PREFIX.'member_info', + array( + 'member' => $membID, + 'member_name' => $membName, + 'status' => $this->config['status_numb']['Active'], + 'reference_name' => 'Imported Member Information', + 'descr' => preg_replace('%[\n\r]%', '', $val['description']), + 'short_descr' => '', + 'addr1' => '', + 'addr2' => '', + 'city' => 0, + 'state' => 0, + 'country' => '', + 'zip' => '', + 'lat' => 0, + 'lon' => 0, + 'region' => 0, + 'phone' => '', + 'toll_free' => '', + 'url' => '', + 'email' => '', + 'logo' => '', + 'cc_type' => 0, + 'notes' => '', + 'create_time' => $val['created'], + 'modify_time' => '' + ), + array( + '%d', + '%s', + '%d', + '%s', + '%s', + '%s', + '%s', + '%s', + '%d', + '%s', + '%s', + '%s', + '%f', + '%f', + '%d', + '%s', + '%s', + '%s', + '%s', + '%s', + '%d', + '%s', + '%s', + '%s' + ) + ); + $infoID = $this->wpdb->insert_id; + $member[$key]['new_info_id'] = $infoID; + $rvBrand = $rvClass = $rvManufacturer = 0; + $rvCat = array(); + + // Add Member Categories + // Get category id for the model_name + $rvBrand = getCategoryId( $this->wpdb, $val['model_name'], $rvBrandId ); + if ( $rvBrand ) { + $rvCat[] = array( + 'category' => $rvBrand, + 'member_info' => $infoID + ); + } + // Get category id for the class_name + $rvClass = getCategoryId( $this->wpdb, $val['class_name'], $rvClassId ); + if ( $rvClass ) { + $rvCat[] = array( + 'category' => $rvClass, + 'member_info' => $infoID + ); + } + // Get category id for the manufacturer_name + $rvManufacturer = getCategoryId( $this->wpdb, $val['manufacturer_name'], $rvManufacturerId ); + if ( $rvManufacturer ) { + $rvCat[] = array( + 'category' => $rvManufacturer, + 'member_info' => $infoID + ); + } + // Add Member Categories + if (isset($rvCat)) { + foreach ($rvCat as $catMemData) { + + $res = $this->wpdb->insert( + GLM_MEMBERS_PLUGIN_DB_PREFIX.'category_member_info', + $catMemData, + array( + '%d', + '%d' + ) + ); + + } + } + + // Add Member Amenities (only for rvs) + if (isset($rvAmen[$val['id']])) { + foreach ($rvAmen[$val['id']] as $a) { + // Check first if the amenity still exists + // Brewbakers may have extra rvs_amenity records for amenities + // that don't exists anymore. + if ( isset( $amenity[$a['amenity_id']] ) ) { + $res = $this->wpdb->insert( + GLM_MEMBERS_PLUGIN_DB_PREFIX.'amenity_ref', + array( + 'amenity' => $amenity[$a['amenity_id']]['new_id'], + 'ref_type' => $this->config['ref_type_numb']['MemberInfo'], + 'ref_dest' => $infoID + ), + array( + '%d', + '%d', + '%d' + ) + ); + } + } + } + + // Add Custom Fields + // year + addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'year', $val['year'] ); + // Model + addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'model', $val['model_name'] ); + // length + addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'length', $val['length'] ); + // Weight + addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'weight', $val['weight'] ); + // color + addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'color', $val['color'] ); + // Stock Number + addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'stock_numb', $val['stock_numb'] ); + // MSRP + addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'msrp', $val['msrp'] ); + // Sleeping Capacity + addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'sleeping_capacity', $val['sleeping_capacity'] ); + // Slide Outs + addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'slide_outs', $val['slide_outs'] ); + // Fresh Water + addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'fresh_water_tank_size', $val['fresh_water_tank_size'] ); + // Black Tank + addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'black_tank_size', $val['black_tank_size'] ); + // Grey Tank + addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'grey_tank_size', $val['grey_tank_size'] ); + // Just Arrived + addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'just_arrived', $val['just_arrived'] ); + // Red Hot Heal + addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'red_hot_deal', $val['red_hot_deal'] ); + // Used + addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'used', $val['used'] ); + } - echo '
    $member: ' . print_r( $member, true ) . '
    '; + +} +// If everything is OK, make data available to the template +if (!$failure) { + + $templateData['numbMembers'] = count($member); + $templateData['numbMembersActive'] = $numbMembersActive; + $templateData['numbMembersInactive'] = $numbMembersInactive; + $templateData['haveMembImportIssues'] = $haveMembImportIssues; + $templateData['membImportIssues'] = $membImportIssues; + $templateData['numbCategories'] = count($rvCat) + count($homeCat); + $templateData['haveCatImportIssues'] = $haveCatImportIssues; + $templateData['catImportIssues'] = $catImportIssues; + $templateData['numbAmenities'] = count($amenity); + $templateData['numbAmenityMembers'] = $numbAmenityMembers; + + // For testing only + $templateData['member'] = $member; + $templateData['amenity'] = $amenity; + $templateData['rvAmen'] = $rvAmen; +} + + +if ($failure) { + $requestedView = 'import.html'; +} else { + $requestedView = 'import/brewbakers.html'; } diff --git a/views/admin/management/import.html b/views/admin/management/import.html index 56eba1e5..d47c4bfe 100644 --- a/views/admin/management/import.html +++ b/views/admin/management/import.html @@ -23,6 +23,12 @@ Import Brewbakers + + +

    Import Images

    +

    Import Files

    + +

    @@ -135,6 +141,10 @@ $('.for-member-import').addClass('glm-hidden'); } else if (selected == 'importMailingAddresses') { $('.for-member-import').addClass('glm-hidden'); + } else if (selected == 'importBrewbakers') { + $('.for-member-import').addClass('glm-hidden'); + $('.all-import-fields').addClass('glm-hidden'); + $('.for-brewbakers').removeClass('glm-hidden'); } else { $('.for-member-import').addClass('glm-hidden'); $('.all-import-fields').addClass('glm-hidden'); diff --git a/views/admin/management/import/brewbakers.html b/views/admin/management/import/brewbakers.html new file mode 100644 index 00000000..44276752 --- /dev/null +++ b/views/admin/management/import/brewbakers.html @@ -0,0 +1,45 @@ +{include file='admin/management/header.html'} + +

    Data Import - Test Database

    +
      +
    1. Provide legacy database information and import member data.
    2. +
    3. Import any images.
    4. +
    5. Review results
    6. +
    + +

    Data Import Results

    + + + + + + + + + + + + + + +
    Members: + {$numbMembers} + {if $haveMembImportIssues} +
      {$membImportIssues}
    + {/if} +
    Members Active:{$numbMembersActive}
    Members Inactive:{$numbMembersInactive}
    Categories:{$numbCategories}
    Member Category Entries: + {if $haveCatImportIssues} +
      {$catImportIssues}
    + {/if} +
    Amenities:{$numbAmenities}
    Member Amenity Entries:{$numbAmenityMembers}
    + +

    Data Import Step 2: Import images.

    +{if isset($genError)} +

    +

    Oops!

    +

    {$genError}

    +

    +{/if} + + +{include file='admin/footer.html'} diff --git a/views/admin/management/import/brewbakersFiles.html b/views/admin/management/import/brewbakersFiles.html new file mode 100644 index 00000000..46b5c272 --- /dev/null +++ b/views/admin/management/import/brewbakersFiles.html @@ -0,0 +1,37 @@ +{include file='admin/management/header.html'} + +

    Data Import - Test Database

    +
      +
    1. Provide legacy database information and import member data.
    2. +
    3. Import any images.
    4. +
    5. Review results
    6. +
    + + +

    Data Import Step 3: Review Results.

    +{if isset($genError)} +

    +

    Oops!

    +

    {$genError}

    +

    +{/if} + +
    +Found: {$numbFilesFound} files
    +Start: {$start}
    +End: {$newStart}
    +Total: {$total}
    +
    + Next Set of Files + + {if $newStart > $total } +

    Process Complete

    +

    + The data and image import process is complete. You should now have all member data and images imported. +

    +

    + You should now go to the "Member List" and make sure the data and images have been imported properly. +

    + {/if} + +{include file='admin/footer.html'} diff --git a/views/admin/management/import/brewbakersImages.html b/views/admin/management/import/brewbakersImages.html new file mode 100644 index 00000000..2f4ccbfb --- /dev/null +++ b/views/admin/management/import/brewbakersImages.html @@ -0,0 +1,37 @@ +{include file='admin/management/header.html'} + +

    Data Import - Test Database

    +
      +
    1. Provide legacy database information and import member data.
    2. +
    3. Import any images.
    4. +
    5. Review results
    6. +
    + + +

    Data Import Step 3: Review Results.

    +{if isset($genError)} +

    +

    Oops!

    +

    {$genError}

    +

    +{/if} + +
    +Found: {$numbImagesFound} images
    +Start: {$start}
    +End: {$newStart}
    +Total: {$total}
    +
    + Next Set of Images + + {if $newStart > $total } +

    Process Complete

    +

    + The data and image import process is complete. You should now have all member data and images imported. +

    +

    + You should now go to the "Member List" and make sure the data and images have been imported properly. +

    + {/if} + +{include file='admin/footer.html'} diff --git a/views/admin/member/memberInfo.html b/views/admin/member/memberInfo.html index ef202e68..85cad94b 100644 --- a/views/admin/member/memberInfo.html +++ b/views/admin/member/memberInfo.html @@ -105,9 +105,7 @@ Contact Info Categories & Amenities Images - Video Live Cam