Add the phone and fax develop
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 15 May 2018 20:03:05 +0000 (16:03 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 15 May 2018 20:03:05 +0000 (16:03 -0400)
for custom field updates.

models/admin/migcsa/index.php
views/admin/migcsa/index.html

index a5a6cbf..b69c144 100644 (file)
@@ -148,6 +148,10 @@ class GlmMembersAdmin_migcsa_index
             $view     = 'memberTypes';
             $response = $this->updateCustomFieldEmails();
             break;
+        case 'updatePhone':
+            $view     = 'memberTypes';
+            $response = $this->updateCFPhone();
+            break;
         case 'archive':
             $view     = 'memberTypes';
             $response = $this->archive();
@@ -232,6 +236,85 @@ class GlmMembersAdmin_migcsa_index
         return '<pre>$ups: ' . print_r( $ups, true ) . '</pre>';
     }
 
+    public function updateCFPhone()
+    {
+
+         $sql = "
+        SELECT member_id,phone,fax
+          FROM member
+         WHERE member_id IN (SELECT member_id
+                               FROM member_category
+                              WHERE category_id IN (40,42))";
+        $stmt    = $this->dbh->query( $sql );
+        $members = $stmt->fetchAll();
+
+        $count = count( $members );
+
+        $this->wpdb->query('START TRANSACTION');
+        foreach ( $members as $m ) {
+            // First get the ref_dest for this member.
+            $ref_dest = $this->wpdb->get_var(
+                $this->wpdb->prepare(
+                    "SELECT id
+                       FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX  . "members
+                      WHERE old_member_id = %d",
+                    $m['member_id']
+                )
+            );
+            if ( $ref_dest ) {
+                $contact_id = $this->wpdb->get_var(
+                    $this->wpdb->prepare(
+                        "SELECT id
+                           FROM " . GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX  . "contacts
+                          WHERE ref_dest = %d",
+                        $ref_dest
+                    )
+                );
+                // echo '<pre>$contact_id: ' . print_r( $contact_id, true ) . '</pre>';
+                // see if there's an email set
+                // $cf_email_id = $this->wpdb->get_var(
+                //     $this->wpdb->prepare(
+                //         "SELECT id
+                //            FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX  . "custom_field_data
+                //           WHERE field_id = %d
+                //             AND entity_id = %d",
+                //         14,
+                //         $contact_id
+                //     )
+                // );
+
+                // Add phone
+                if ( $m['phone'] ) {
+                    $this->wpdb->insert(
+                        GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . 'custom_field_data',
+                        array(
+                            'field_data' => $m['phone'],
+                            'field_id'   => 16,
+                            'entity_id'  => $contact_id
+                        )
+                    );
+                }
+
+                // Add fax
+                if ( $m['fax'] ) {
+                    $this->wpdb->insert(
+                        GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . 'custom_field_data',
+                        array(
+                            'field_data' => $m['fax'],
+                            'field_id'   => 17,
+                            'entity_id'  => $contact_id
+                        )
+                    );
+                }
+            }
+
+        }
+        // $this->wpdb->query('ROLLBACK');
+        $this->wpdb->query('COMMIT');
+
+        return '<pre>$count: ' . print_r( $count, true ) . '</pre>';
+    }
+
     public function updateCustomFieldEmails()
     {
 
index 3d87311..f599ff5 100644 (file)
@@ -18,3 +18,5 @@
 <a href="{$thisUrl}?page={$thisPage}&option=updateEmail">Update Custom field email</a>
 <br />
 <a href="{$thisUrl}?page={$thisPage}&option=checkMembers">Check Member Accounts</a>
+<br />
+<a href="{$thisUrl}?page={$thisPage}&option=updatePhone">Update Phone and Fax</a>