}
switch( $option ) {
+ case 'updateUsernames':
+ $view = 'memberTypes';
+ $response = $this->updateUsernames();
+ break;
case 'updateMemberTypes':
$view = 'memberTypes';
$response = $this->updateMemberTypes();
}
+ public function updateUsernames()
+ {
+ $contact_ids = array( 725, 1123, 904, 1308, 974, 1099, 534, 1019, 1077, 907, 773, 851, 1113, 1011, 17, 1213, 724, 225, 719, 687, 709, 882, 989, 648, 768, 1210, 1176, 659, 1080, 402, 817, 1300, 934);
+ $ref_dest_ids = array();
+ $old_member_ids = array();
+
+ // echo '<pre>$contact_ids: ' . print_r( $contact_ids, true ) . '</pre>';
+
+ // Get ref_dest from a contact id
+ foreach ( $contact_ids as $c ) {
+ $ref_dest_ids[$c] = $this->getRefDestFromContactId( $c );
+ }
+ // echo '<pre>$ref_dest_ids: ' . print_r( $ref_dest_ids, true ) . '</pre>';
+
+ foreach ( $ref_dest_ids as $r ) {
+ $old_member_ids[$r] = $this->getOldMemberId( $r );
+ }
+
+ // echo '<pre>$old_member_ids: ' . print_r( $old_member_ids, true ) . '</pre>';
+
+ $sql = "
+ SELECT member_id,member_name,member_login,process_email
+ FROM member
+ WHERE member_id IN ( " . implode( ',', $old_member_ids ) . ")";
+ $stmt = $this->dbh->query( $sql );
+ $members = $stmt->fetchAll();
+
+ // echo '<pre>$members: ' . print_r( $members, true ) . '</pre>';
+
+ foreach ( $members as $m ) {
+ echo '<pre>$m: ' . print_r( $m, true ) . '</pre>';
+ // For each member get the contact id based on the old_member_ids array
+ $ref_dest = array_search( $m['member_id'], $old_member_ids );
+ echo '<pre>$ref_dest: ' . print_r( $ref_dest, true ) . '</pre>';
+ // Now with the ref_dest find the right contact id
+ $contactId = array_search( $ref_dest, $ref_dest_ids );
+ echo '<pre>$contactId: ' . print_r( $contactId, true ) . '</pre>';
+ // Now update the member contact's username
+ $this->wpdb->update(
+ GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . 'contacts',
+ array( 'username' => $m['member_login'] ),
+ array( 'id' => $contactId )
+ );
+ // See if there's any user with new username
+ // $wpUser = get_user_by( 'username', $m['member_login'] );
+ // echo '<pre>$wpUser: ' . print_r( $wpUser, true ) . '</pre>';
+ // Grab there user_id
+ $user_id = $this->wpdb->get_var(
+ "SELECT user_id
+ FROM " . $this->wpdb->prefix . "usermeta
+ WHERE meta_key = 'glmMembersContactID'
+ AND meta_value = '$contactId'"
+ );
+ echo '<pre>$user_id: ' . print_r( $user_id, true ) . '</pre>';
+ $this->wpdb->update(
+ $this->wpdb->prefix . 'users',
+ array( 'user_login' => $m['member_login'] ),
+ array( 'ID' => $user_id )
+ );
+ }
+ }
+
+ public function getRefDestFromContactId( $contact_id )
+ {
+ return $this->wpdb->get_var(
+ $this->wpdb->prepare(
+ "SELECT ref_dest
+ FROM " . GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . "contacts
+ WHERE id = %d",
+ $contact_id
+ )
+ );
+ }
+
+ public function getOldMemberId( $ref_dest )
+ {
+ return $this->wpdb->get_var(
+ $this->wpdb->prepare(
+ "SELECT old_member_id
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+ WHERE id = %d",
+ $ref_dest
+ )
+ );
+ }
+
public function updateMemberContacts()
{
$sql = "
SELECT M.*,S.state_abb
FROM member M LEFT OUTER JOIN state S ON (S.state_id = M.mailing_state_id)
WHERE M.member_id NOT IN (" . implode( ',', $old_members ) . ")
- AND M.member_id NOT IN (7608,7613,7628,7629,7638,7639,7640,7647)
+ AND M.member_id NOT IN (7608,7613,7628,7629,7638,7639,7640,7647)
ORDER BY M.member_id";
$stmt = $this->dbh->query( $sql );
$members = $stmt->fetchAll();
update_user_meta($wpUserID, 'glmMembersContactActive', true);
echo '<pre>$wpUserID: ' . print_r( $wpUserID, true ) . '</pre>';
} else if ( is_wp_error( $wpUserID ) ) {
- $messages[] = '<pre>' . print_r( $contact, true) . '</pre>';
+ $messages[] = '<pre>' . print_r( $contact, true) . '</pre>';
$error = true;
$messages[] = '<span style="color:red;">An error occurred! ' . $wpUserID->get_error_message() . '</span>';
} else {