示例#1
0
文件: functions.php 项目: nakyau/pfff
/**
 * removes an affiliation for a user or object in three places: the home db
 * for the id, and the home db for the network, the groups network editor
 *
 * @param int   the user or object in question
 * @param int   the network they are becoming un-affiliated with
 * @param bool  if this is an account deactivation don't disable the
 *              network assocs, they will get disabled on their own
 */
function remove_affiliation_link($userid, $network_key, $is_deactivate = false)
{
    // 1. remove it from the user's db
    $conn_id_w = id_get_conn($userid, 'w');
    $conn_network_w = network_get_conn($network_key, 'w');
    $sql_remove = 'DELETE FROM affiliations WHERE id = %d AND network_key = %d';
    $cachekeys = affiliation_get_cachekeys_for_add_remove($userid, $network_key);
    queryf_memcache($conn_id_w, $cachekeys, $sql_remove, $userid, $network_key);
    // 2. remove it from the network's db
    //    unnecessary if a user's home db is the same as the network's
    if (id_to_db($userid) != network_to_db($network_key)) {
        queryf($conn_network_w, $sql_remove, $userid, $network_key);
    }
    hook_remove_affiliation($userid, $network_key);
    // 3. remove a group association as we transition over to groups
    // for deactivations we don't want to delete the group assocs as these
    // will be handled by the assoc deactivation code
    if (fbid_in_uid_range($userid) && !$is_deactivate) {
        if ($fbid = network_get_fbid($network_key)) {
            $viewer_context = ViewerContext::newAllPowerfulViewerContext();
            $profile = fbobj_get_profile($fbid);
            if (group_is_managed_tribe($fbid, $profile)) {
                id(new EntTribeEditor($viewer_context, $fbid))->removeMember($userid);
            } else {
                if (group_is_network($fbid, $profile)) {
                    id(new EntNetworkEditor($viewer_context, $network_key, $fbid))->removeMember($userid);
                } else {
                    FBLogger('networks')->mustfix('Trying to add member to network with wrong version type');
                }
            }
        } else {
            if (extract_network_type($network_key) != $GLOBALS['TYPE_GEO']) {
                FBLogger('networks')->mustfix('Failed to retrieve network FBID for key: %s', $network_key);
            }
        }
    }
}
示例#2
0
/**
 * Converts a single array of fbid into a nested array keyed on dbid.
 *
 * @param array
 * @return array
 */
function ids_to_dbmap($ids)
{
    $map = array();
    foreach ($ids as $id) {
        $map[id_to_db($id)][] = $id;
    }
    return $map;
}