<?php
/*
转换好友
pre_ucenter_friends
pre_home_friend
*/
if($start<=1){
	truncatetable('ucenter_friends');
	truncatetable('home_friend');
}

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

$query = $xc->db['source']->query("SELECT * FROM {$source_tablepre}friends  WHERE uid >= $start AND uid < $start + $rpp") or dexit();
while ($friends = $xc->db['source']->fetch_array($query)) {
	
	//pre_ucenter_friends
	$uid		=	$friends['uid'];
	$friendid	=	$friends['friendid'];
	$direction	=	0;
	$related	=	0;
	$delstatus	=	0;
	$comment	=	daddslashes($friends['descrip']);

	//pre_home_friend
	$fuid		=	$friendid;
	$fusername	=	getusername($fuid);
	$gid		=	1;
	$num		=	0;
	$dateline	=	$friends['joindate'];
	$note		=	'';

	$field1			=	array('uid', 'friendid', 'direction', 'version', 'delstatus', 'comment');
	$query1			=	getinsertsql("{$discuz_tablepre}ucenter_friends", $field1);

	$field2			=	array('uid','fuid','fusername','gid','num','dateline');
	$query2			=	getinsertsql("{$discuz_tablepre}home_friend", $field2);

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