Setup for redo contact import
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 13 Jan 2017 15:33:41 +0000 (10:33 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 13 Jan 2017 15:33:41 +0000 (10:33 -0500)
Use current member file and redo the contact to get title county and
correcting the addresses.

models/admin/management/csvimport.php
views/admin/management/csvimport.html

index 6e0cd7b..4c519ad 100644 (file)
@@ -96,7 +96,7 @@ class GlmMembersAdmin_management_csvimport
      */
     public function modelAction ($actionData = false)
     {
-         
+
 
         $resultMessage = '';
         $success       = false;
@@ -133,6 +133,55 @@ class GlmMembersAdmin_management_csvimport
             //$resultMessage .= '<pre>$file_data: ' . print_r( $file_data, true ) . '</pre>';
             break;
 
+        case 'redoContacts':
+            // check for members.csv
+            $upload_dir = wp_upload_dir();
+            $members = $file_headers = $data = array();
+
+            if ( is_file( $upload_dir['basedir'].'/Members.csv' ) && ( $fh = fopen( $upload_dir['basedir'].'/Members.csv', 'r' ) ) !== false ) {
+                $resultMessage .= '<p>Member file found</p>';
+                $row = 0;
+                while( ( $data = fgetcsv( $fh, 1000, ',' ) ) !== false ) {
+                    if ( $row === 0 ) {
+                        // First row grab as headers.
+                        $file_headers = $data;
+                    } else {
+                        // All other rows are data.
+                        $members[] = array_combine( $file_headers, $data );
+                    }
+                    $row++;
+                }
+                fclose( $fh );
+                $resultMessage .= '<pre>$members: ' . print_r( $members, true ) . '</pre>';
+            }
+
+            if ( !empty( $members ) ) {
+                foreach ( $members as $contact ) {
+                    // update contact data for address and county and title
+                    $this->wpdb->update(
+                        GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . 'contacts',
+                        array(
+                            'title'  => $contact['title'],
+                            'county' => $contact['region'],
+                            'addr1'  => $contact['street'],
+                            'city'   => ( isset( $contact['city'] ) ? $this->getCityId( $contact['city'] ) : 0 ),
+                            'zip'    => $zip,
+                        ),
+                        array( 'username' => $contact['username'] ),
+                        array(
+                            '%s',
+                            '%s',
+                            '%s',
+                            '%d',
+                            '%s',
+                        ),
+                        array( '%s' )
+                    );
+                }
+            }
+
+            break;
+
         case 'importBoard':
             // check for members.csv
             $upload_dir = wp_upload_dir();
@@ -150,8 +199,8 @@ class GlmMembersAdmin_management_csvimport
                 fclose( $fh );
                 $resultMessage .= '<pre>$Members: ' . print_r( $Members, true ) . '</pre>';
             }
-            
-               
+
+
             $url = get_site_url() . '/wp-admin/admin.php?page=glm-members-admin-menu-management&glm_action=csvimport&option=importBoard';
             $limit = 110;
 
@@ -191,7 +240,7 @@ class GlmMembersAdmin_management_csvimport
                         'post_name'    => $old_post_id,
                         'post_type'    => 'reply',
                         'post_status'  => 'publish',
-                    );  
+                    );
 
                 }else if( strpos( $post_title, 'Re:') === false ){
                     $args = array(
@@ -207,7 +256,7 @@ class GlmMembersAdmin_management_csvimport
                 }
                 $new_post_id = wp_insert_post($args);
                 add_post_meta($new_post_id, '_bbp_forum_id', 389);
-                add_post_meta($new_post_id, '_bbp_last_active_time', $post_date);    
+                add_post_meta($new_post_id, '_bbp_last_active_time', $post_date);
 
 
                 if($reply === '0'){
@@ -230,7 +279,7 @@ class GlmMembersAdmin_management_csvimport
         $resultMessage =  "<pre>Start: $start</pre>";
         $start += $limit;
         $resultMessage .= "<p><a class='next-import-btn' href=\"". $url . "&limit=$limit&start=$start\">Next</a></p>";
+
             break;
 
         default:
index bca7bed..64af82a 100644 (file)
@@ -7,8 +7,8 @@
     <input type="file" name="file_upload">
     <input type="submit" class="button">
 </form>
-
-<a href="{$thisUrl}?page={$thisPage}&glm_action=csvimport&option=importBoard">Import Message Board</a>
+<p><a href="{$thisUrl}?page={$thisPage}&glm_action=csvimport&option=importBoard">Import Message Board</a></p>
+<p><a href="{$thisUrl}?page={$thisPage}&glm_action=csvimport&option=redoContacts">Redo Contacts</a></p>
 {/if}
 
 {if $resultMessage}
@@ -33,6 +33,6 @@ jQuery(document).ready(function($){
         }
         window.onload = clickNext();
     });
-});   
-    
+});
+
 </script>