*/
public function modelAction($actionData = false)
{
-
+
$option = 'importSetup';
$importResult = array(
'status' => false,
$content = '';
$thisOption = '';
$requestedView = 'contacts.html';
+ $result = '';
$templateData = array(
'thisOption' => '',
);
-
+
if ($actionData) {
$templateData = $actionData;
}
switch ($option) {
+ 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 'clear':
+ $sqlTotal = "
+ SELECT count(id)
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+ WHERE access = " . $this->config['access_numb']['Archived'];
+ $totalArchived = $this->wpdb->get_var( $sqlTotal );
+ $result .= '<p>Total Archived Members: ' . $totalArchived . '</p>';
+ $sql = "
+ SELECT id,name
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+ WHERE access = " . $this->config['access_numb']['Archived'];
+ $sql .= " ORDER BY id LIMIT 25 OFFSET 0 ";
+ $members = $this->wpdb->get_results(
+ $sql,
+ ARRAY_A
+ );
+ // $result .= '<pre>$members: ' . print_r( $members, true ) . '</pre>';
+ foreach ( $members as $member ) {
+ // $result .= '<pre>$member: ' . print_r( $member, true ) . '</pre>';
+ // Delete all contacts and users belonging to the archived members.
+ $member_contact = $this->wpdb->get_row(
+ $this->wpdb->prepare(
+ "SELECT id,email
+ FROM " . GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . "contacts
+ WHERE ref_dest = %d",
+ $member['id']
+ ),
+ ARRAY_A
+ );
+ // $result .= '<pre>$member_contact: ' . print_r( $member_contact, true ) . '</pre>';
+ if ( $member_contact['email'] ) {
+ $wpUser = get_user_by( 'email', $member_contact['email'] );
+ if ( $wpUser ) {
+ // $result .= '<pre>$wpUser: ' . print_r( $wpUser, true ) . '</pre>';
+ // Check for other roles assigned to this user and remove our roles
+ $userHasOtherRole = false;
+ foreach ($wpUser->roles as $r) {
+ if (!in_array($r, $this->config['contact_role_wordpress'])) {
+ // Apparently not, so we need to keep the Wordpress user
+ $userHasOtherRole = true;
+
+ //Otherwise, this is one of our roles so we should remove it just in case the Wordpress user isn't deleted
+ } else {
+ // Remove this role from our user
+ $wpUser->remove_role($r);
+ }
+ }
+ // If the user doesn't have a role other than our members contact roles
+ if (!$userHasOtherRole) {
+
+ // Delete the wordpress user
+ wp_delete_user($wpUser->ID);
+ $wpUserDeleted = true;
+
+ // Otherwise we need to drop the user meta data we added to the WP user.
+ } else {
+ delete_user_meta($wpUser->ID, 'glmMembersContactID');
+ delete_user_meta($wpUser->ID, 'glmMembersContactActive');
+ }
+ }
+ }
+
+ // Delete member_info records belonging to the archived members.
+ $this->wpdb->delete(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX . 'member_info',
+ array( 'member' => $member['id'] ),
+ array( '%d' )
+ );
+
+ // Delete archived members.
+ $this->wpdb->delete(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX . 'members',
+ array( 'id' => $member['id'] ),
+ array( '%d' )
+ );
+ $archiveCount++;
+ }
+ $result .= '<p>Removed ' . $archiveCount . ' Archived Members</p>';
+ break;
+
+ default:
+ break;
+
+ }
+
+ break;
+
case 'clearContacts':
'db_password' => $db_password,
'db_schema' => $db_schema,
'content' => $content,
- 'thisOption' => $thisOption
+ 'thisOption' => $thisOption,
+ 'result' => $result,
);
// Return status, suggested view, and data to controller
);
- }
+ }
/**
// Update the contact Email data
$rows = $this->wpdb->update(
- GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . 'contacts',
- array('email' => $memberContactEmail),
- array( 'id' => $contactData['id']),
- array('%s'),
- array( '%d' )
+ GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . 'contacts',
+ array('email' => $memberContactEmail),
+ array( 'id' => $contactData['id']),
+ array('%s'),
+ array( '%d' )
);
// Check for failure