static function UpdateLevelsCount() { global $WishListMemberInstance; $levels = WishListMember_Level::GetAllLevels(true); $wpm_levels = $WishListMemberInstance->GetOption('wpm_levels'); foreach ($levels as $level) { $wpm_levels[$level->ID]['count'] = $level->CountMembers(); } $WishListMemberInstance->SaveOption('wpm_levels', $wpm_levels); }
/** * Retrieve Member IDs by Status * note: 'status=active' is only accurate for calls with single level * @global object $wpdb * @param string $status Any of cancelled, unconfirmed or forapproval * @param array (optional) $levels Level IDs * @param boolean $groupbylevel (optional) Whether to group the Member IDs by Level ID * @param boolean $countonly (optional) True to return only the number of IDs found * @return array */ function MemberIDsByStatus($status, $levels = null, $groupbylevel = null, $countonly = null) { global $wpdb; if (is_null($groupbylevel)) { $groupbylevel = false; } if (is_null($countonly)) { $countonly = false; } $status = trim(strtolower($status)); if (!in_array($status, array('cancelled', 'unconfirmed', 'forapproval', 'active'))) { return false; } if (!is_null($levels)) { $levels = (array) $levels; foreach ($levels as $k => $v) { $levels[$k] = (int) $v; } } else { $levels = WishListMember_Level::GetAllLevels(); } $levels_implode = "'" . implode("','", $levels) . "'"; $select = "DISTINCT `user_id`"; if ($countonly) { $select = "COUNT(DISTINCT `user_id`)"; } // Special handling for active if ($status == 'active') { $found = array(); foreach (array('cancelled', 'unconfirmed', 'forapproval') as $s) { foreach ($levels as $level) { $found = array_merge($found, $this->MemberIDsByStatus($s, $level, false, false)); } } $expired = $this->ExpiredMembersID(); foreach ($expired as $l => $v) { if (in_array($l, $levels)) { $found = array_merge($found, $v); } } $found = implode(', ', array_unique($found)); if (empty($found)) { $found = 0; } if ($groupbylevel == true) { $ids = array(); foreach ($levels as $level) { // $query = $wpdb->prepare("SELECT $select FROM `{$this->Tables->userlevels}` `ul` WHERE `ul`.`user_id` NOT IN (".$found.") AND `ul`.`level_id` IN (".$level.")"); $query = "SELECT {$select} FROM `{$this->Tables->userlevels}` `ul` WHERE `ul`.`user_id` NOT IN (" . $found . ") AND `ul`.`level_id` IN (" . $level . ")"; $ids[$level] = $wpdb->get_col($query); } } else { $query = $wpdb->prepare("SELECT {$select} FROM `{$this->Tables->userlevels}` `ul` WHERE `ul`.`user_id` NOT IN (" . $found . ") AND `ul`.`level_id` IN (" . implode(',', $levels) . ")"); $ids = $wpdb->get_col($query); } return $ids; } // if ($groupbylevel == true) { $ids = array(); foreach ($levels as $level) { $query = $wpdb->prepare("SELECT {$select} FROM `{$this->Tables->userlevels}` `ul` LEFT JOIN `{$this->Tables->userlevel_options}` `ulm` ON `ul`.`ID`=`ulm`.`userlevel_id` WHERE `ul`.`level_id` = %d AND `ulm`.`option_name`='%s' AND `ulm`.`option_value`='1' ORDER BY `ul`.`user_id`", $level, $status); $ids[$level] = $wpdb->get_col($query); } } else { $query = $wpdb->prepare("SELECT {$select} FROM `{$this->Tables->userlevels}` `ul` LEFT JOIN `{$this->Tables->userlevel_options}` `ulm` ON `ul`.`ID`=`ulm`.`userlevel_id` WHERE `ul`.`level_id` IN ({$levels_implode}) AND `ulm`.`option_name`='%s' AND `ulm`.`option_value`='1' ORDER BY `ul`.`user_id`", $status); $ids = $wpdb->get_col($query); } return $ids; }
/** * Migrate Level Information * @global object $wpdb */ function MigrateLevelData() { ignore_user_abort(true); global $wpdb; if ($this->DataMigrated != 1 || get_option($this->PluginOptionName . '_MigrateLevelData') == 1) { return; } $this->CreateWLMDBTables(); $userlevelsTable = $this->Tables->userlevels; $userlevelsTableOptions = $this->Tables->userlevel_options; $userTableOptions = $this->Tables->user_options; // user level data $memberLevels = (array) $this->GetOption('Members'); $cancelled = (array) $this->GetOption('Cancelled'); $unconfirmed = (array) $this->GetOption('UnConfirmed'); $forapproval = (array) $this->GetOption('Pending'); $levels = WishListMember_Level::GetAllLevels(); $allmembers = array(); foreach ($levels as $level) { $members = array_unique(explode(',', $memberLevels[$level])); $allmembers = array_merge($allmembers, $members); foreach ($members as $member) { /* Membership Level */ $data = array('user_id' => $member, 'level_id' => $level); if ($wpdb->insert($userlevelsTable, $data)) { $userlevel_id = $wpdb->insert_id; /* Transaction IDs */ $trans = get_usermeta($member, 'wlm_sctxns'); $data = array('userlevel_id' => $userlevel_id, 'option_name' => 'transaction_id', 'option_value' => maybe_serialize($trans[$level])); $wpdb->insert($userlevelsTableOptions, $data); /* Level Registration Dates */ $regdates = get_usermeta($member, 'wpm_leveltimestamp'); $this->UserLevelTimestamp($member, $level, $regdates[$level]); /* Cancelled Status */ $status = preg_match('/,(' . $member . ';[0-9]*),/', ',' . $cancelled[$level] . ',', $match) > 0; if ($status) { list($id, $date) = explode(';', $match[1]); $this->LevelCancelled($level, $member, true, $date); } /* Unconfirmed Status */ $status = preg_match('/,' . $member . ',/', ',' . $unconfirmed[$level] . ',') > 0; if ($status) { $this->LevelUnConfirmed($level, $member, true); } /* For Approval Status */ $status = preg_match('/,' . $member . ',/', ',' . $forapproval[$level] . ',') > 0; if ($status) { $this->LevelForApproval($level, $member, true); } } } } $allmembers = array_unique($allmembers); // per user data $nonseq = array_unique(explode(',', $memberLevels['nonsequential'])); foreach ($allmembers as $member) { // sequential upgrade $seq = in_array($member, $nonseq) ? 0 : 1; $data = array('user_id' => $member, 'option_name' => 'sequential', 'option_value' => maybe_serialize($seq)); $wpdb->insert($userTableOptions, $data); } // migrate all wpm_ and wlm_ data except wpm_leveltimestamp and wlm_sctxns $query = "INSERT INTO `{$userTableOptions}` (`user_id`,`option_name`,`option_value`)\n\t\t\t\tSELECT `user_id`,`meta_key`,`meta_value` FROM `{$wpdb->usermeta}`\n\t\t\t\t\tWHERE `meta_key`<>'wpm_leveltimestamp'\n\t\t\t\t\tAND `meta_key`<>'wlm_sctxns'\n\t\t\t\t\tAND (`meta_key` LIKE 'wlm%' OR `meta_key` LIKE 'wpm%')"; $wpdb->query($query); /* * remove old data format for membership levels, cancelled status, * unconfirmed status, and pending status from our options table */ $this->DeleteOption('Members'); $this->DeleteOption('Cancelled'); $this->DeleteOption('UnConfirmed'); $this->DeleteOption('Pending'); /* end of data migration */ update_option($this->PluginOptionName . '_MigrateLevelData', 1); }