<?php
/*
用户关系
pw_attention
pre_home_follow
*/

if($start <= 1){
	truncatetable('home_follow');
}

$maxcount	=	$xc->db['source']->result($xc->db['source']->query("SELECT count(*) FROM {$source_tablepre}attention"), 0);
if($start <= $maxcount) {
	$counted	=	1;
}

$query = $xc->db['source']->query("SELECT * FROM {$source_tablepre}attention ORDER BY uid ASC") or dexit();
while ($attentions = $xc->db['source']->fetch_array($query)) {
	$uid		=	$attentions['uid'];
	$username	=	getusername($attentions['uid']);
	$followuid	=	$attentions['friendid'];
	$fusername 	=	getusername($attentions['friendid']);
	$dateline	=	$attentions['joindate'];
	if($xc->db['discuz']->result($xc->db['discuz']->query("SELECT uid FROM {$discuz_tablepre}home_follow WHERE uid='{$followuid}' AND followuid='{$uid}' LIMIT 1"), 0)){
		$mutual = '1';
		$xc->db['discuz']->query("UPDATE {$discuz_tablepre}home_follow SET mutual='1' WHERE uid='{$followuid}' AND followuid='{$uid}' LIMIT 1");
	} else {
		$mutual = '0';
	}
	$field1			=	array('uid', 'username', 'followuid', 'fusername', 'dateline', 'mutual');
	$query1			=	getinsertsql("{$discuz_tablepre}home_follow", $field1);

	if ($xc->db['discuz']->query($query1)) {
		$convertedrows ++;
	} else {
		reportlog("无法转换微博关系数据 uid = '$uid', attentionid = '$friendid'");
	}
	$counted	=	1;
	$totalrows ++;
	$url = 'index.php?mod=dealdata&step='.$step.'&start='.($attentions['uid']+1).'&stay='.$stay.'&totalrows='.$totalrows.'&convertedrows='.$convertedrows.'&sqlfilenum='.$sqlfilenum;
	file_put_contents(XCONVERT_ROOT.'./cache/lock/progress_'.$step.".txt", $url);
}

?>