From b38b7f937cecdd0adb443b1604cde95a0b2044d1 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 15 May 2018 16:03:05 -0400 Subject: [PATCH] Add the phone and fax for custom field updates. --- models/admin/migcsa/index.php | 83 +++++++++++++++++++++++++++++++++++ views/admin/migcsa/index.html | 2 + 2 files changed, 85 insertions(+) diff --git a/models/admin/migcsa/index.php b/models/admin/migcsa/index.php index a5a6cbf..b69c144 100644 --- a/models/admin/migcsa/index.php +++ b/models/admin/migcsa/index.php @@ -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 '
$ups: ' . print_r( $ups, true ) . '
'; } + 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 '
$contact_id: ' . print_r( $contact_id, true ) . '
'; + // 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 '
$count: ' . print_r( $count, true ) . '
'; + } + public function updateCustomFieldEmails() { diff --git a/views/admin/migcsa/index.html b/views/admin/migcsa/index.html index 3d87311..f599ff5 100644 --- a/views/admin/migcsa/index.html +++ b/views/admin/migcsa/index.html @@ -18,3 +18,5 @@ Update Custom field email
Check Member Accounts +
+Update Phone and Fax -- 2.17.1