Updating member import scripts
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 21 Jun 2017 16:35:38 +0000 (12:35 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 21 Jun 2017 16:35:38 +0000 (12:35 -0400)
Adding in mailing address city state zip.

models/admin/management/import/members.php
setup/databaseScripts/drop_database_V1.1.31.sql [deleted file]
setup/databaseScripts/drop_database_V1.1.32.sql [new file with mode: 0644]
views/admin/management/import.html

index ab7db7d..34c6fd0 100644 (file)
@@ -418,9 +418,10 @@ if (!$failure) {
             // Since there was no problem, we'll post-process the cities into an array indexed by city_id
             $city = array();
 
-            // Reprocess into array indexed by city_id
+            // Reprocess into array indexed by city_id and by city_name
             foreach ($tmp as $x) {
                 $city[$x['city_id']] = $x;
+                $cityNames[$x['city_name']] = $x['city_id'];
             }
         }
     }
@@ -550,11 +551,11 @@ if (!$failure && isset($_REQUEST['dbReset']) && $_REQUEST['dbReset'] == 'on') {
     // Reset the database
     if (!$this->deleteDataTables($dbVersion)) {
         glmMembersAdmin::addNotice('<b>Unable to delete the database tables while resetting the database.</b><br>', 'AdminError');
-        break;
+        //break;
     }
     if (!$this->createDataTables($dbVersion)) {
         glmMembersAdmin::addNotice('<b>Unable to create the database tables while resetting the database.</b><br>', 'AdminError');
-        break;
+        //break;
     }
 
     glmMembersAdmin::addNotice('<b>Database tables have been reset in preparation importing members.</b><br>', 'AdminNotice');
@@ -812,6 +813,12 @@ if (!$failure) {
             }
         }
         $this->wpdb->show_errors();
+
+        // Find the city id if mailing city is given
+        // Need the new city id inserted.
+        $mailingOldCityId = ( ( isset( $cityNames[$val['mailing_city']] ) && $val['mailing_city'] ) ? $cityNames[$val['mailing_city']] : 0 );
+        $mailingCityId = ( (isset($city[$mailingOldCityId]['new_id'] ) && $city[$mailingOldCityId]['new_id'] ) ?  $city[$mailingOldCityId]['new_id']: 0 );
+
         // Insert Member Information Record
         $res = $this->wpdb->insert(
                 GLM_MEMBERS_PLUGIN_DB_PREFIX.'member_info',
@@ -828,6 +835,12 @@ if (!$failure) {
                     'state'          => $state[$val['state_id']]['state_abb'],
                     'country'        => 'US',
                     'zip'            => $val['zip'],
+
+                    'mailing_addr1'  => $val['mailing_address'],
+                    'mailing_city'   => $mailingCityId,
+                    'mailing_state'  => ( (isset($state[$val['mailing_state_id']]['state_abb']) && $val['mailing_state_id']) ? $state[$val['mailing_state_id']]['state_abb']: ''),
+                    'mailing_zip'    => $val['mailing_zip'],
+
                     'lat'            => $val['lat'],
                     'lon'            => $val['lon'],
                     'region'         => (isset($region[$val['region']]) ? $region[$val['region']]['new_id'] : 0),
@@ -842,30 +855,36 @@ if (!$failure) {
                     'modify_time'    => $val['last_update']
                 ),
                 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'
+                    '%d', // member id
+                    '%s', // name
+                    '%d', // status
+                    '%s', // ref name
+                    '%s', // descr
+                    '%s', // short_descr
+                    '%s', // addr1
+                    '%s', // addr2
+                    '%d', // city
+                    '%s', // state
+                    '%s', // country
+                    '%s', // zip
+
+                    '%s', // mailing addr1
+                    '%d', // mailing city
+                    '%s', // mailing state
+                    '%s', // mailing zip
+
+                    '%f', // lat
+                    '%f', // lon
+                    '%d', // region
+                    '%s', // phone
+                    '%s', // toll_free
+                    '%s', // url
+                    '%s', // email
+                    '%s', // logo
+                    '%d', // email
+                    '%s', // notes
+                    '%s', // create_time
+                    '%s' // modify_time
                 )
         );
         $infoID = $this->wpdb->insert_id;
diff --git a/setup/databaseScripts/drop_database_V1.1.31.sql b/setup/databaseScripts/drop_database_V1.1.31.sql
deleted file mode 100644 (file)
index ef327d8..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
--- Gaslight Media Members Database
--- File Created: 12/09/14 15:27:15
--- Database Version: 1.1.23
--- Database Deletion Script
--- Note: Tables with DELETE CASCADE must appear before referenced table
-
-DROP TABLE IF EXISTS
-    {prefix}amenities,
-    {prefix}amenity_ref,
-    {prefix}category_member_info,
-    {prefix}cities,
-    {prefix}clickthrough_stats,
-    {prefix}images,
-    {prefix}files,
-    {prefix}members,
-    {prefix}member_detail_stats,
-    {prefix}member_info,
-    {prefix}member_type,
-    {prefix}regions,
-    {prefix}counties,
-    {prefix}settings_general,
-    {prefix}settings_terms,
-    {prefix}settings_theme,
-    {prefix}categories,
-    {prefix}amenity_groups,
-    {prefix}grouped_amenities,
-    {prefix}cache
-;
-
diff --git a/setup/databaseScripts/drop_database_V1.1.32.sql b/setup/databaseScripts/drop_database_V1.1.32.sql
new file mode 100644 (file)
index 0000000..ef327d8
--- /dev/null
@@ -0,0 +1,29 @@
+-- Gaslight Media Members Database
+-- File Created: 12/09/14 15:27:15
+-- Database Version: 1.1.23
+-- Database Deletion Script
+-- Note: Tables with DELETE CASCADE must appear before referenced table
+
+DROP TABLE IF EXISTS
+    {prefix}amenities,
+    {prefix}amenity_ref,
+    {prefix}category_member_info,
+    {prefix}cities,
+    {prefix}clickthrough_stats,
+    {prefix}images,
+    {prefix}files,
+    {prefix}members,
+    {prefix}member_detail_stats,
+    {prefix}member_info,
+    {prefix}member_type,
+    {prefix}regions,
+    {prefix}counties,
+    {prefix}settings_general,
+    {prefix}settings_terms,
+    {prefix}settings_theme,
+    {prefix}categories,
+    {prefix}amenity_groups,
+    {prefix}grouped_amenities,
+    {prefix}cache
+;
+
index 5cdffad..115d1f6 100644 (file)
@@ -20,7 +20,6 @@
                     <input type="radio" name="option" value="importClicksViews" class="import-type"> Import member Clicks and Views<br>
                     <input type="radio" name="option" value="importMailingAddresses" class="import-type"> Import member Mailing Addresses<br>
                     <input type="radio" name="option" value="displayOldNewMemberIds" class="import-type"> List old/new member IDs<br>
-                    <input type="radio" name="option" value="importTrailMaps" class="import-type"> Import Trail Maps
                 </td>
             </tr>
             <tr class="for-trailmaps glm-hidden">