Script for migrating the migcsa data from contact info to organization.
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 9 Aug 2018 15:35:03 +0000 (11:35 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 9 Aug 2018 15:35:03 +0000 (11:35 -0400)
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.

models/admin/management/contacts.php
views/admin/management/contactHeader.html
views/admin/management/migrate.html [new file with mode: 0644]

index f66c714..1656e90 100644 (file)
@@ -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 '<pre>$option2: ' . print_r( $option2, true ) . '</pre>';
+
+            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 .= '<p>Updated: ' . $updated . '</p>';
+                // 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 .= '<p>cleared: ' . $cleared . '</p>';
+                // 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 .= '<p>custom: ' . $custom . '</p>';
+                break;
+
+            }
+
+            break;
+
         case 'clean':
             $requestedView = 'clean.html';
             $option2       = isset( $_REQUEST['option2'] ) ? filter_var( $_REQUEST['option2'], FILTER_SANITIZE_STRING ): '';
             $result        = '';
             $archiveCount  = 0;
-            // $result = '<pre>$option2: ' . print_r( $option2, true ) . '</pre>';
 
             switch ( $option2 ) {
+
             case 'nomember':
                 $sql = "
                 SELECT id,email
index 49d1769..a4bd067 100644 (file)
@@ -1,5 +1,6 @@
 <h2 class="nav-tab-wrapper">
     <a href="{$thisUrl}?page={$thisPage}&glm_action=contacts" class="nav-tab{if $thisOption == ''} nav-tab-active{/if}">Contact Options</a>
+    <a href="{$thisUrl}?page={$thisPage}&glm_action=contacts&option=migrate" class="nav-tab{if $thisOption == 'migrate'} nav-tab-active{/if}">Migrate Contact Data</a>
     {if apply_filters( 'glm-members-customfields-active', false )}
         <a href="{$thisUrl}?page={$thisPage}&glm_action=contacts&option=customfields" class="nav-tab{if $thisOption == 'customfields'} nav-tab-active{/if}">Custom Fields</a>
     {/if}
diff --git a/views/admin/management/migrate.html b/views/admin/management/migrate.html
new file mode 100644 (file)
index 0000000..6aeced9
--- /dev/null
@@ -0,0 +1,22 @@
+{include file='admin/management/header.html'}
+{include file='admin/management/contactHeader.html'}
+
+    <h2>Migrate Data from Contacts</h2>
+
+    <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+        <input type="hidden" name="page" value="{$thisPage}" />
+        <input type="hidden" name="glm_action" value="contacts" />
+        <input type="hidden" name="option" value="migrate" />
+        <input type="hidden" name="option2" value="migrate" />
+        <input type="submit" value="Migrate Data" />
+    </form>
+
+    {if $result}
+        {$result}
+    {/if}
+
+    <script>
+    </script>
+
+{include file='admin/footer.html'}
+