From: Steve Sutton Date: Thu, 9 Aug 2018 15:35:03 +0000 (-0400) Subject: Script for migrating the migcsa data from contact info to organization. X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=010d7e95a31df829c3b9368ce0a06c8ceed33bf4;p=WP-Plugins%2Fglm-member-db-contacts.git Script for migrating the migcsa data from contact info to organization. Moving the data from Contact Info records into the contact business fields. Also moving the custom field data for the email and phone into the business email and phone. --- diff --git a/models/admin/management/contacts.php b/models/admin/management/contacts.php index f66c714..1656e90 100644 --- a/models/admin/management/contacts.php +++ b/models/admin/management/contacts.php @@ -108,25 +108,22 @@ class GlmMembersAdmin_management_contacts extends GlmDataContacts public function modelAction($actionData = false) { - $option = 'importSetup'; - $importResult = array( - 'status' => false, - 'exceptionTable' => false - ); - $errorMsg = false; - $db_host = false; - $db_name = false; - $db_user = false; - $db_password = false; - $db_schema = false; - $content = ''; - $thisOption = ''; - $requestedView = 'contacts.html'; - $result = ''; - $resultData = array(); + $option = 'importSetup'; + $errorMsg = false; + $db_host = false; + $db_name = false; + $db_user = false; + $db_password = false; + $db_schema = false; + $content = ''; + $thisOption = ''; + $requestedView = 'contacts.html'; + $result = ''; + $resultData = array(); + $importResult = array( 'status' => false, 'exceptionTable' => false ); $templateData = array( - 'thisOption' => '', + 'thisOption' => '', ); if ($actionData) { @@ -139,14 +136,70 @@ class GlmMembersAdmin_management_contacts extends GlmDataContacts switch ($option) { + case 'migrate': + $requestedView = 'migrate.html'; + $option2 = isset( $_REQUEST['option2'] ) ? filter_var( $_REQUEST['option2'], FILTER_SANITIZE_STRING ): ''; + $result = ''; + $migrateCount = 0; + + echo '
$option2: ' . print_r( $option2, true ) . '
'; + + switch ( $option2 ) { + + case 'migrate': + // Update all contacts to move the address data from Contact Info to Organization + $updated = $this->wpdb->query( + "UPDATE " . GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . "contacts + SET business_addr1 = addr1, + business_addr2 = addr2, + business_city = city, + business_state = state, + business_zip = zip, + business_country = country" + ); + $result .= '

Updated: ' . $updated . '

'; + // Empty the Original Contact Info address fields + $cleared = $this->wpdb->query( + "UPDATE " . GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . "contacts + SET addr1 = '', + addr2 = '', + city = NULL, + state = '', + zip = '', + country = ''" + ); + $result .= '

cleared: ' . $cleared . '

'; + // Update the business_email and business_phone fields with the custom field data + $custom = $this->wpdb->query( + "UPDATE " . GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . "contacts C + SET business_email = ( + SELECT field_data + FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_data + WHERE field_id = 14 + AND entity_id = C.id + ), + business_phone = ( + SELECT field_data + FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_data + WHERE field_id = 16 + AND entity_id = C.id + )" + ); + $result .= '

custom: ' . $custom . '

'; + break; + + } + + break; + case 'clean': $requestedView = 'clean.html'; $option2 = isset( $_REQUEST['option2'] ) ? filter_var( $_REQUEST['option2'], FILTER_SANITIZE_STRING ): ''; $result = ''; $archiveCount = 0; - // $result = '
$option2: ' . print_r( $option2, true ) . '
'; switch ( $option2 ) { + case 'nomember': $sql = " SELECT id,email diff --git a/views/admin/management/contactHeader.html b/views/admin/management/contactHeader.html index 49d1769..a4bd067 100644 --- a/views/admin/management/contactHeader.html +++ b/views/admin/management/contactHeader.html @@ -1,5 +1,6 @@

Migrate Data from Contacts

+ +
+ + + + + +
+ + {if $result} + {$result} + {/if} + + + +{include file='admin/footer.html'} +