Exemplo n.º 1
0
 /**
  * Merge two users
  *
  * @param integer $sourceuserid
  * @param integer $destuserid
  */
 public function merge($sourceuserid, $destuserid)
 {
     $this->checkHasAdminPermission('canadminusers');
     $assertor = vB::getDbAssertor();
     if (!($sourceinfo = $assertor->getRow('user_fetchwithtextfield', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_STORED, 'userid' => $sourceuserid)))) {
         throw new vB_Exception_Api('invalid_source_username_specified');
     }
     if (!($destinfo = $assertor->getRow('user_fetchwithtextfield', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_STORED, 'userid' => $destuserid)))) {
         throw new vB_Exception_Api('invalid_destination_username_specified');
     }
     /*
     		// Update Subscribed Forums
     		$assertor->assertQuery('userInsertSubscribeforum', array(
     			vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_METHOD,
     			'sourceuserid' => $sourceinfo['userid'],
     			'destuserid' => $destinfo['userid'],
     		));
     
     		$assertor->assertQuery('user_updatesubscribethread', array(
     			'userid' => $destinfo['userid'],
     		));
     
     		$assertor->assertQuery('userInsertSubscribethread', array(
     			vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_METHOD,
     			'sourceuserid' => $sourceinfo['userid'],
     			'destuserid' => $destinfo['userid'],
     		));
     
     		require_once(DIR . '/includes/functions_databuild.php');
     		update_subscriptions(array('userids' => array($destinfo['userid'])));
     */
     // Update Subscribed Events
     $assertor->assertQuery('userInsertSubscribeevent', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_METHOD, 'sourceuserid' => $sourceinfo['userid'], 'destuserid' => $destinfo['userid']));
     /*
     REPLACE INTO
     */
     // Merge relevant data in the user table
     // It is ok to have duplicate ids in the buddy/ignore lists
     $userdm = new vB_Datamanager_User(vB_DataManager_Constants::ERRTYPE_SILENT);
     $userdm->set_existing($destinfo);
     $options = vB::getDatastore()->getValue('options');
     $userdm->set('posts', "posts + {$sourceinfo['posts']}", false);
     $userdm->set_ladder_usertitle_relative($sourceinfo['posts']);
     $userdm->set('reputation', "reputation + {$sourceinfo['reputation']} - " . $options['reputationdefault'], false);
     $userdm->set('lastvisit', "IF(lastvisit < {$sourceinfo['lastvisit']}, {$sourceinfo['lastvisit']}, lastvisit)", false);
     $userdm->set('lastactivity', "IF(lastactivity < {$sourceinfo['lastactivity']}, {$sourceinfo['lastactivity']}, lastactivity)", false);
     $userdm->set('lastpost', "IF(lastpost < {$sourceinfo['lastpost']}, {$sourceinfo['lastpost']}, lastpost)", false);
     $userdm->set('pmtotal', "pmtotal + {$sourceinfo['pmtotal']}", false);
     $userdm->set('pmunread', "pmunread + {$sourceinfo['pmunread']}", false);
     $userdm->set('gmmoderatedcount', "gmmoderatedcount + {$sourceinfo['gmmoderatedcount']}", false);
     if ($sourceinfo['joindate'] > 0) {
         // get the older join date, but only if we actually have a date
         $userdm->set('joindate', "IF(joindate > {$sourceinfo['joindate']}, {$sourceinfo['joindate']}, joindate)", false);
     }
     $userdm->set('ipoints', "ipoints + " . intval($sourceinfo['ipoints']), false);
     $userdm->set('warnings', "warnings + " . intval($sourceinfo['warnings']), false);
     $userdm->set('infractions', "infractions + " . intval($sourceinfo['infractions']), false);
     $assertor->assertQuery('user_insertuserlist', array('sourceuserid' => $sourceinfo['userid'], 'destuserid' => $destinfo['userid']));
     $assertor->assertQuery('user_updateuserlist', array('sourceuserid' => $sourceinfo['userid'], 'destuserid' => $destinfo['userid']));
     $myfriendcount = $assertor->getField('user_fetchuserlistcount', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_STORED, 'userid' => $destinfo['userid']));
     $userdm->set('friendcount', $myfriendcount);
     $userdm->save();
     unset($userdm);
     require_once DIR . '/includes/functions_databuild.php';
     build_userlist($destinfo['userid']);
     // if the source user has infractions, then we need to update the infraction groups on the dest
     // easier to do it this way to make sure we get fresh info about the destination user
     if ($sourceinfo['ipoints']) {
         unset($usercache["{$destinfo['userid']}"]);
         $new_user = vB_User::fetchUserInfo($destinfo['userid']);
         $infractiongroups = array();
         $groups = $assertor->assertQuery('user_fetchinfractiongroup', array());
         foreach ($groups as $group) {
             $infractiongroups["{$group['usergroupid']}"]["{$group['pointlevel']}"][] = array('orusergroupid' => $group['orusergroupid'], 'override' => $group['override']);
         }
         $userdm = new vB_Datamanager_User(vB_DataManager_Constants::ERRTYPE_SILENT);
         $userdm->set_existing($new_user);
         $infractioninfo = vB_Library::instance('Content_Infraction')->fetchInfractionGroups($infractiongroups, $new_user['userid'], $new_user['ipoints'], $new_user['usergroupid']);
         $userdm->set('infractiongroupids', $infractioninfo['infractiongroupids']);
         $userdm->set('infractiongroupid', $infractioninfo['infractiongroupid']);
         $userdm->save();
         unset($userdm);
     }
     // Update announcements
     $assertor->assertQuery('user_updateannouncement', array('sourceuserid' => $sourceinfo['userid'], 'destuserid' => $destinfo['userid']));
     // Update Read Announcements
     $assertor->assertQuery('userInsertAnnouncementread', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_METHOD, 'sourceuserid' => $sourceinfo['userid'], 'destuserid' => $destinfo['userid']));
     // Update Deletion Log
     $assertor->assertQuery('user_updatedeletionlog', array('sourceuserid' => $sourceinfo['userid'], 'destuserid' => $destinfo['userid'], 'destusername' => $destinfo['username']));
     // Update Edit Log
     $assertor->assertQuery('user_updateeditlog', array('sourceuserid' => $sourceinfo['userid'], 'destuserid' => $destinfo['userid'], 'destusername' => $destinfo['username']));
     // Update Edit Log
     $assertor->assertQuery('user_updatepostedithistory', array('sourceuserid' => $sourceinfo['userid'], 'destuserid' => $destinfo['userid'], 'destusername' => $destinfo['username']));
     // Update Poll Votes - find any poll where we both voted
     // we need to remove the source user's vote
     $pollconflicts = array();
     $polls = $assertor->assertQuery('user_fetchpollvote', array('sourceuserid' => $sourceinfo['userid'], 'destuserid' => $destinfo['userid']));
     foreach ($polls as $poll) {
         $pollconflicts["{$poll['nodeid']}"] = $poll;
     }
     $assertor->assertQuery('user_updatepollvote', array('sourceuserid' => $sourceinfo['userid'], 'destuserid' => $destinfo['userid']));
     if (!empty($pollconflicts)) {
         $assertor->assertQuery('user_deletepollvote', array('userid' => $sourceinfo['userid']));
         // Polls that need to be rebuilt now
         foreach ($pollconflicts as $pollconflict) {
             vB_Api::instanceInternal('poll')->updatePollCache($pollconflict['nodeid']);
             $pollvotes = $assertor->assertQuery('user_fetchpollvote2', array('nodeid' => $pollconflict['nodeid']));
             $lastvote = 0;
             foreach ($pollvotes as $pollvote) {
                 if ($pollvote['votedate'] > $lastvote) {
                     $lastvote = $pollvote['votedate'];
                 }
             }
             // It appears that pollvote.votedate wasn't always set in the past so we could have votes with no datetime, hence the check on lastvote below
             $assertor->assertQuery('userUpdatePoll', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_METHOD, 'nodeid' => $pollconflict['nodeid'], 'lastvote' => $lastvote));
         }
     }
     // Update User Notes
     $assertor->assertQuery('user_updateusernote', array('sourceuserid' => $sourceinfo['userid'], 'destuserid' => $destinfo['userid']));
     $assertor->assertQuery('user_updateusernote2', array('sourceuserid' => $sourceinfo['userid'], 'destuserid' => $destinfo['userid']));
     // Update Calendar Events
     $assertor->assertQuery('user_updateevent', array('sourceuserid' => $sourceinfo['userid'], 'destuserid' => $destinfo['userid']));
     // Update Reputation Details
     $assertor->assertQuery('user_updatereputation', array('sourceuserid' => $sourceinfo['userid'], 'destuserid' => $destinfo['userid']));
     $assertor->assertQuery('user_updatereputation2', array('sourceuserid' => $sourceinfo['userid'], 'destuserid' => $destinfo['userid']));
     // Update infractions
     $assertor->assertQuery('user_updateinfraction', array('sourceuserid' => $sourceinfo['userid'], 'destuserid' => $destinfo['userid']));
     $assertor->assertQuery('user_updateinfraction2', array('sourceuserid' => $sourceinfo['userid'], 'destuserid' => $destinfo['userid']));
     // Update tags
     require_once DIR . '/includes/class_taggablecontent.php';
     vB_Taggable_Content_Item::merge_users($sourceinfo['userid'], $destinfo['userid']);
     // Clear Group Transfers
     //		$assertor->assertQuery('user_updatesocialgroup', array(
     //			'userid' => $sourceinfo['userid'],
     //		));
     // Delete requests if the dest user already has them
     $assertor->assertQuery('userDeleteUsergrouprequest', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_METHOD, 'sourceuserid' => $sourceinfo['userid'], 'destusergroupid' => $destinfo['usergroupid'], 'destmembergroupids' => $destinfo['membergroupids']));
     // Convert remaining requests to dest user.
     $assertor->assertQuery('user_updateusergrouprequest', array('sourceuserid' => $sourceinfo['userid'], 'destuserid' => $destinfo['userid']));
     // Paid Subscriptions
     $assertor->assertQuery('user_updatepaymentinfo', array('sourceuserid' => $sourceinfo['userid'], 'destuserid' => $destinfo['userid']));
     // Move subscriptions over
     $assertor->assertQuery('user_updatesubscriptionlog', array('sourceuserid' => $sourceinfo['userid'], 'destuserid' => $destinfo['userid']));
     $list = $remove = $update = array();
     // Combine active subscriptions
     $subs = $assertor->assertQuery('user_fetchsubscriptionlog', array('userid' => $destinfo['userid']));
     foreach ($subs as $sub) {
         $subscriptionid = $sub['subscriptionid'];
         $existing = $list[$subscriptionid];
         if ($existing) {
             if ($sub['expirydate'] > $existing['expirydate']) {
                 $remove[] = $existing['subscriptionlogid'];
                 unset($update[$existing['subscriptionlogid']]);
                 $list[$subscriptionid] = $sub;
                 $update[$sub['subscriptionlogid']] = $sub['expirydate'];
             } else {
                 $remove[] = $sub['subscriptionlogid'];
             }
         } else {
             $list[$subscriptionid] = $sub;
         }
     }
     if (!empty($remove)) {
         $assertor->assertQuery('user_deletesubscriptionlog', array('ids' => $remove));
     }
     foreach ($update as $subscriptionlogid => $expirydate) {
         $assertor->assertQuery('user_updatesubscriptionlog2', array('expirydate' => $expirydate, 'subscriptionlogid' => $subscriptionlogid));
     }
     //fix the names on any nodes that the user may be attached to.
     $assertor->assertQuery('vBForum:node', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_UPDATE, vB_dB_Query::CONDITIONS_KEY => array('userid' => $sourceinfo['userid']), 'authorname' => $destinfo['username'], 'userid' => $destinfo['userid']));
     $assertor->assertQuery('vBForum:node', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_UPDATE, vB_dB_Query::CONDITIONS_KEY => array('lastauthorid' => $sourceinfo['userid']), 'lastcontentauthor' => $destinfo['username'], 'lastauthorid' => $destinfo['userid']));
     // Remove remnants of source user
     $userdm = new vB_Datamanager_User(vB_DataManager_Constants::ERRTYPE_SILENT);
     $userdm->set_existing($sourceinfo);
     $userdm->delete();
     unset($userdm);
     return true;
 }
Exemplo n.º 2
0
            } else {
                if ($status == -1) {
                    // deleted
                    if ($vbulletin->GPC['send_deleted']) {
                        if (!isset($evalemail_deleted["{$user['languageid']}"])) {
                            //note that we pass the "all languages" flag as true all the time because if the function does
                            //caching internally and is not smart enough to check if the language requested the second time
                            //was cached on the first pass -- so we make sure that we load and cache all language version
                            //in case the second user has a different language from the first
                            $evalemail_deleted["{$user['languageid']}"] = vB_Api::instanceInternal('phrase')->fetchEmailPhrases('moderation_deleted', array($username, $vboptions['bbtitle']), array($vboptions['bbtitle']), $chosenlanguage);
                        }
                        vB_Mail::vbmail($user['email'], $evalemail_deleted["{$user['languageid']}"]['subject'], $evalemail_deleted["{$user['languageid']}"]['message'], true);
                    }
                    $userdm = new vB_Datamanager_User($vbulletin, vB_DataManager_Constants::ERRTYPE_SILENT);
                    $userdm->set_existing($user);
                    $userdm->delete();
                    unset($userdm);
                }
            }
            // else, do nothing
        }
        // rebuild stats so new user displays on forum home
        require_once DIR . '/includes/functions_databuild.php';
        build_user_statistics();
        print_stop_message2('user_accounts_validated', 'index', array('do' => 'home'));
    }
}
// ############################# do prune/move users (step 1) #########################
if ($_POST['do'] == 'dopruneusers') {
    $vbulletin->input->clean_array_gpc('p', array('users' => vB_Cleaner::TYPE_ARRAY_INT, 'dowhat' => vB_Cleaner::TYPE_STR, 'movegroup' => vB_Cleaner::TYPE_INT));
    if (!empty($vbulletin->GPC['users'])) {