From 8a4bca18bca6a35443236994b15ec4e1b55a7f23 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Fri, 23 Jun 2017 15:51:01 -0400 Subject: [PATCH] Removing uneeded member import files. Files that were for brewbakers and trailmaps imports. --- .../management/import/brewbakersBrands.php | 121 -- .../management/import/brewbakersFiles.php | 180 --- .../management/import/brewbakersImages.php | 200 ---- .../management/import/brewbakersImport.php | 1000 ----------------- .../management/import/trailmapsFiles.php | 131 --- .../management/import/trailmapsImport.php | 218 ---- 6 files changed, 1850 deletions(-) delete mode 100644 models/admin/management/import/brewbakersBrands.php delete mode 100644 models/admin/management/import/brewbakersFiles.php delete mode 100644 models/admin/management/import/brewbakersImages.php delete mode 100644 models/admin/management/import/brewbakersImport.php delete mode 100644 models/admin/management/import/trailmapsFiles.php delete mode 100644 models/admin/management/import/trailmapsImport.php diff --git a/models/admin/management/import/brewbakersBrands.php b/models/admin/management/import/brewbakersBrands.php deleted file mode 100644 index 9b764cf6..00000000 --- a/models/admin/management/import/brewbakersBrands.php +++ /dev/null @@ -1,121 +0,0 @@ -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.
'.$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 '
$rvs: ' . print_r( $rvs, 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 - ) - ); -} - - -$templateData['newStart'] = $start + $limit; -$templateData['start'] = $start; -$templateData['total'] = $totalFiles; -$templateData['numbFilesFound'] = $numbFilesFound; - -$requestedView = 'import/brewbakersFiles.html'; diff --git a/models/admin/management/import/brewbakersFiles.php b/models/admin/management/import/brewbakersFiles.php deleted file mode 100644 index 477014c2..00000000 --- a/models/admin/management/import/brewbakersFiles.php +++ /dev/null @@ -1,180 +0,0 @@ -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 deleted file mode 100644 index a0571ae6..00000000 --- a/models/admin/management/import/brewbakersImages.php +++ /dev/null @@ -1,200 +0,0 @@ -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 deleted file mode 100644 index f8945e98..00000000 --- a/models/admin/management/import/brewbakersImport.php +++ /dev/null @@ -1,1000 +0,0 @@ -$_REQUEST: ' . print_r( $_REQUEST, true ) . ''; -$rvLimit = false; // set to false to turn off limit - -// Setup the database connection to postgres -$dbServer = 'ds4'; -$dbName = 'brewbakers'; -$dbUser = 'postgres'; -$resetdb = true; -$rvs = array(); -$homes = array(); -$amenities = array(); -$amenityData = array(); - -// Create connection -$connString = "host=$dbServer dbname=$dbName user=$dbUser"; -$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; -} -// 1. Get the rvs data -if ( !$failure ) { - // Grab the RV data - $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"; - if ( $rvLimit ) { - $sql .= " LIMIT $rvLimit OFFSET 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 ); - $templateData['genError'] = 'While reading base rv data, we did not receive the expected number of rvs! '; - if ( $notice ) { - $templateData['genError'] .= 'Perhaps the following message will help.
'.$notice; - } - $failure = true; - } - //echo '
$rvs: ' . print_r( $rvs, true ) . '
'; - } -} -// 2. Get the homes data -if ( !$failure ) { - // Grab the Homes data - $sql = " - SELECT h.*, - m.name as model_name, - c.name as class_name, - man.name as manufacturer_name - FROM homes h, model m, manufacturer man, class c - WHERE h.model = m.id - AND h.class = c.id - AND h.manufacturer = man.id - ORDER BY h.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 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 ) { - // 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 -$numbAmenityMembers = 0; -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 { - $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 ) { - $templateData['genError'] .= 'Perhaps the following message will help.
'.$notice; - } - $failure = 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 - return $wpdb->get_var( - $wpdb->prepare( - "SELECT id - FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "categories - WHERE name = %s - AND parent = %d", - $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 -function addNewCategory( $wpdb, $name, $parent ) -{ - $catId = getCategoryId( $wpdb, $name, $parent ); - if ( $catId ) { - return $catId; - } else { - // Add the category - $wpdb->insert( - GLM_MEMBERS_PLUGIN_DB_PREFIX . 'categories', - array( - 'name' => $name, - 'descr' => '', - 'short_descr' => '', - 'parent' => $parent - ), - array( - '%s', - '%s', - '%s', - '%d', - ) - ); - return $wpdb->insert_id; - } -} -// Grab the Brands from Brewbakers -if ( !$failure ) { - // Add new main level for Brands - $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 - FROM brands - 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 brands listed in this database!'; - $failure = true; - } else { - $brands = pg_fetch_all( $res ); - if ( count( $brands ) != $rows ) { - $notice = pg_last_notice( $res ); - $templateData['genError'] = 'While reading base brands data, we did not receive the expected number of brands! '; - if ( $notice ) { - $templateData['genError'] .= 'Perhaps the following message will help.
'.$notice; - } - $failure = true; - } - //echo '
$brands: ' . print_r( $brands, true ) . '
'; - foreach ( $brands as $key => $val ) { - //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 - $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 - FROM manufacturer - WHERE section = 1 - 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 Housing Manufacturers listed in this database!'; - $failure = true; - } else { - $houseMan = pg_fetch_all( $res ); - if ( count( $houseMan ) != $rows ) { - $notice = pg_last_notice( $res ); - $templateData['genError'] = 'While reading base Housing Manufacturers data, we did not receive the expected number of row! '; - if ( $notice ) { - $templateData['genError'] .= 'Perhaps the following message will help.
'.$notice; - } - $failure = true; - } - //echo '
$houseMan: ' . print_r( $houseMan, true ) . '
'; - foreach ( $houseMan as $key => $val ) { - //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 - $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 - FROM manufacturer - WHERE section = 2 - 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 RV Manufacturers listed in this database!'; - $failure = true; - } else { - $rvMan = pg_fetch_all( $res ); - if ( count( $rvMan ) != $rows ) { - $notice = pg_last_notice( $res ); - $templateData['genError'] = 'While reading base RV Manufacturers data, we did not receive the expected number of row! '; - if ( $notice ) { - $templateData['genError'] .= 'Perhaps the following message will help.
'.$notice; - } - $failure = true; - } - //echo '
$rvMan: ' . print_r( $rvMan, true ) . '
'; - foreach ( $rvMan as $key => $val ) { - //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 - $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 - FROM class - WHERE section = 1 - 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 Housing Classes listed in this database!'; - $failure = true; - } else { - $houseClass = pg_fetch_all( $res ); - if ( count( $houseClass ) != $rows ) { - $notice = pg_last_notice( $res ); - $templateData['genError'] = 'While reading base Housing Classes data, we did not receive the expected number of row! '; - if ( $notice ) { - $templateData['genError'] .= 'Perhaps the following message will help.
'.$notice; - } - $failure = true; - } - //echo '
$houseClass: ' . print_r( $houseClass, true ) . '
'; - foreach ( $houseClass as $key => $val ) { - //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 - $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 - FROM class - WHERE section = 2 - 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 RV Classes listed in this database!'; - $failure = true; - } else { - $rvClass = pg_fetch_all( $res ); - if ( count( $rvClass ) != $rows ) { - $notice = pg_last_notice( $res ); - $templateData['genError'] = 'While reading base RV Classes data, we did not receive the expected number of row! '; - if ( $notice ) { - $templateData['genError'] .= 'Perhaps the following message will help.
'.$notice; - } - $failure = true; - } - //echo '
$rvClass: ' . print_r( $rvClass, true ) . '
'; - foreach ( $rvClass as $key => $val ) { - //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 - $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 - FROM model - WHERE section = 1 - ORDER BY name"; - $res = pg_query( $db, $sql ); - $rows = pg_num_rows( $res ); - if ( $rows == 0 ) { - $templateData['genError'] = 'There does not appear to be any RV Models listed in this database!'; - $failure = true; - } else { - $homeModel = pg_fetch_all( $res ); - if ( count( $homeModel ) != $rows ) { - $notice = pg_last_notice( $res ); - $templateData['genError'] = 'While reading base RV Models data, we did not receive the expected number of row! '; - if ( $notice ) { - $templateData['genError'] .= 'Perhaps the following message will help.
'.$notice; - } - $failure = true; - } - //echo '
$homeModel: ' . print_r( $homeModel, true ) . '
'; - foreach ( $homeModel as $key => $val ) { - //echo '
Adding category for ' . $val['name'] . ' parent ' . $homeModelId . '
'; - $newCatId = addNewCategory( $this->wpdb, $val['name'], $homeModelId ); - } - } -} -// 6. Get category member relation data -// Read in all amenities -if (!$failure) { - $sql = " - SELECT * - FROM amenities - ORDER BY name - ;"; - $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 { - $tmp = pg_fetch_all($res); - if (count($tmp) != $rows) { - $notice = pg_last_notice($res); - $templateData['genError'] = 'While reading amenity data, we did not receive the expected number of amenities! '; - if ($notice) { - $templateData['genError'] .= 'Perhaps the following message will help.
'.$notice; - } - $failure = true; - } else { - - // Since there was no problem, we'll post-process the cities into an array indexed by city_id - $amenity = array(); - - // Reprocess into array indexed by amenity_id - foreach ($tmp as $x) { - $amenity[$x['id']] = $x; - } - //echo '
$amenity: ' . print_r( $amenity, true ) . '
'; - } - } -} -function getAmenityId( $wpdb, $name ) -{ - return $wpdb->get_var( - $wpdb->prepare( - "SELECT id - FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "amenities - WHERE name = %s", - $name - ) - ); -} -function addNewAmenity( $wpdb, $name ) -{ - $amenityId = getAmenityId( $wpdb, $name ); - if ( $amenityId ) { - return $amenityId; - } else { - // Add the category - $wpdb->insert( - GLM_MEMBERS_PLUGIN_DB_PREFIX . 'amenities', - array( - 'active' => true, - 'name' => $name, - 'descr' => '', - 'short_descr' => '', - 'ref_type' => 20 - ), - array( - '%d', - '%s', - '%s', - '%s', - '%d' - ) - ); - return $wpdb->insert_id; - } -} - -if (!$failure) { - // Import Amenities - while (list ($key, $val) = each ($amenity) ) { - $amenityId = addNewAmenity( $this->wpdb, $val['name'] ); - $amenity[$key]['new_id'] = $amenityId; - } - //echo '
new $amenity: ' . print_r( $amenity, true ) . '
'; -} -function getMemberTypeId( $wpdb, $name ) -{ - return $wpdb->get_var( - $wpdb->prepare( - "SELECT id - FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_type - WHERE name = %s", - $name - ) - ); -} -function addNewMemberType( $wpdb, $name ) -{ - $memberTypeId = getMemberTypeId( $wpdb, $name ); - if ( $memberTypeId ) { - return $memberTypeId; - } else { - // Add the category - $wpdb->insert( - GLM_MEMBERS_PLUGIN_DB_PREFIX . 'member_type', - array( - 'name' => $name, - 'descr' => '' - ), - '%s' - ); - return $wpdb->insert_id; - } -} -// Member Types -if (!$failure) { - // Add member type for RV's - $rvMemberType = addNewMemberType( $this->wpdb, 'RV' ); - // Add member type for Homes - $homeMemberType = addNewMemberType( $this->wpdb, 'Home' ); -} -if (!$failure) { - // Import Members - $numbMembersActive = 0; - $numbMembersInactive = 0; - $namesInserted = array(); - $membImportIssues = ''; - $haveMembImportIssues = false; - $dupeNames = 0; - while (list ($key, $val) = each ($homes) ) { - // 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['make'], - $val['class_name'] - ); - 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' => $homeMemberType, - '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( - '%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; - $rvBrand = $rvClass = $rvManufacturer = 0; - $rvCat = array(); - - // Add Member Categories - // Get category id for the brand_name - $rvBrand = getCategoryId( $this->wpdb, $val['brand_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'] ); - - } - -} -// 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/models/admin/management/import/trailmapsFiles.php b/models/admin/management/import/trailmapsFiles.php deleted file mode 100644 index 428a5bb8..00000000 --- a/models/admin/management/import/trailmapsFiles.php +++ /dev/null @@ -1,131 +0,0 @@ -wpdb, $this->config); -$refType = $this->config['ref_type_numb']['MemberInfo']; -$refTable = $this->config['ref_type_table'][$refType]; -$fileBaseURL = 'http://www.michigantrailmaps.com/uploads/member_files/'; - - -// Read in all member files. -$file = array(); -$numbFilesFound = 0; -if (!$failure && $start === 0) { - // Grab the files for members - $sql = " - SELECT * - FROM members.member_files - ORDER BY member_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['members'][$x['member_id']])) { - $file['members'][$x['member_id']] = array( - 'member_id' => $x['member_id'], - 'files' => array() - ); - } - - $file['members'][$x['member_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']; - $fileName = ( $i['file_name'] ) ? $i['file_name'] : $i['original_name']; - $res = $FileUpload->storeFile ($fileURL, $refType, $refTable, $newMemberId, $fileName ); - } - } - - } - } - -} - -$templateData['newStart'] = $start + $limit; -$templateData['start'] = $start; -$templateData['total'] = $totalFiles; -$templateData['numbFilesFound'] = $numbFilesFound; - -$requestedView = 'import/trailmapsFiles.html'; diff --git a/models/admin/management/import/trailmapsImport.php b/models/admin/management/import/trailmapsImport.php deleted file mode 100644 index 82e3a1c6..00000000 --- a/models/admin/management/import/trailmapsImport.php +++ /dev/null @@ -1,218 +0,0 @@ -'.$err['message']; - $failure = true; -} -// Reset the custom field data table. -$this->wpdb->query("DELETE FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_data"); -$this->wpdb->query("DELETE FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "counties"); - -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 - ) - ); -} -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( - 'reviewed' => getCustomFieldId( $this->wpdb, 'Reviewed' ), - 'distance' => getCustomFieldId( $this->wpdb, 'Distance' ), - 'trailtype' => getCustomFieldId( $this->wpdb, 'Type' ), - 'terrain' => getCustomFieldId( $this->wpdb, 'Terrain' ), - 'difficulty' => getCustomFieldId( $this->wpdb, 'Difficulty' ), - 'nearest_city' => getCustomFieldId( $this->wpdb, 'Nearest City or Town' ), - 'guide' => getCustomFieldId( $this->wpdb, 'Trail Guide' ), - 'facilities' => getCustomFieldId( $this->wpdb, 'Facilities' ), - 'hours' => getCustomFieldId( $this->wpdb, 'Hours & Fees' ), - 'directions' => getCustomFieldId( $this->wpdb, 'Directions' ), - 'information' => getCustomFieldId( $this->wpdb, 'Information' ), -); -//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' ) - ); -} - -// Read in all counties -if (!$failure) { - $sql = " - SELECT * - FROM members.county - ;"; - $res = pg_query($db, $sql); - $rows = pg_num_rows($res); - if ($rows == 0) { - $templateData['genError'] = 'There does not appear to be any counties 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 county data, we did not receive the expected number of counties! '; - if ($notice) { - $templateData['genError'] .= 'Perhaps the following message will help.
    '.$notice; - } - $failure = true; - } else { - - // Since there was no problem, we'll post-process the cities into an array indexed by city_id - $county = array(); - - // Reprocess into array indexed by state_id - foreach ($tmp as $x) { - $county[$x['county_id']] = $x; - } - } - } -} - -if (!$failure) { - // Import Counties - while (list ($key, $val) = each ($county) ) { - - $res = $this->wpdb->insert( - GLM_MEMBERS_PLUGIN_DB_PREFIX.'counties', - array( - 'name' => $val['county_name'], - 'descr' => '', - 'short_descr' => '' - ), - array( - '%s', - '%s', - '%s' - ) - ); - $county[$key]['new_id'] = $this->wpdb->insert_id; - - } -} - -if ( !$failure ) { - $sql = " - SELECT member_id,county,reviewed,distance,trailtype,terrain,difficulty, - nearest_city,guide,facilities,hours,directions,information - FROM members.member - ORDER BY member_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 { - $trails = pg_fetch_all( $res ); - if ( count( $trails ) != $rows ) { - $notice = pg_last_notice( $res ); - $templateData['genError'] = 'While reading base trails data, we did not receive the expected number of trails! '; - if ( $notice ) { - $templateData['genError'] .= 'Perhaps the following message will help.
    '.$notice; - } - $failure = true; - } - } -} -//echo '
    $trails: ' . print_r( $trails, true ) . '
    '; -//echo '
    $customFieldIds: ' . print_r( $customFieldIds, true ) . '
    '; -//exit; -$test = false;//true; -if (!$failure) { - // Import Members - while (list ($key, $val) = each ($trails) ) { - // Grab the new member info id from the old member_id field. - $infoID = getMemberInfoIdFromOldMemberId( $this->wpdb, $val['member_id'] ); - if ( !$infoID ) { - echo '
    $infoID: ' . print_r( $infoID, true ) . '
    '; - echo '
    $val[member_id]: ' . print_r( $val['member_id'], true ) . '
    '; - } - - if ( $infoID && !$test ) { - // Update the county field for the member info record - $res = $this->wpdb->update( - GLM_MEMBERS_PLUGIN_DB_PREFIX . 'member_info', - array( - 'county' => (isset($county[$val['county']]) ? $county[$val['county']]['new_id']: 0) - ), - array('id' => $infoID ), - array( '%d' ), - array( '%d' ) - ); - // Add Custom Fields - addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'reviewed', $val['reviewed'] ); - addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'distance', $val['distance'] ); - addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'trailtype', $val['trailtype'] ); - addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'terrain', $val['terrain'] ); - addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'difficulty', $val['difficulty'] ); - addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'nearest_city', $val['nearest_city'] ); - addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'guide', $val['guide'] ); - addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'facilities', $val['facilities'] ); - addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'hours', $val['hours'] ); - addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'directions', $val['directions'] ); - addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'information', $val['information'] ); - } - - } - //echo '
    $member: ' . print_r( $member, true ) . '
    '; -} - -$haveCatImportIssues = false; -$catImportIssues = ''; -// If everything is OK, make data available to the template -if (!$failure) { - - $templateData['numbMembers'] = count($trails); -} - - -if ($failure) { - $requestedView = 'import.html'; -} else { - $requestedView = 'import/trailmapsImport.html'; -} -- 2.17.1