<?php
/*
pre_ucenter_friends
pre_home_friend
*/
if($start <= 1) {
	truncatetable('ucenter_friends');
	truncatetable('home_friend');
	validid('f_id', 'friend');
}
$query = $xc->db['source']->query("SELECT max(F_id) FROM {$source_tablepre}Friend");
$maxid = $xc->db['source']->fetch_array($query);

$query = $xc->db['source']->query("SELECT * FROM {$source_tablepre}Friend WHERE F_id BETWEEN $start AND $end");
while($friend = $xc->db['source']->fetch_assoc($query)) {
	$friend = array_change_key_case(daddslashes($friend));

	//pre_ucenter_friends
	$uid = $friend['f_userid'];
	if($friendid = getuid($friend['f_friend'])) {
		$direction	= 0;
		$related	= 0;
		$delstatus	= 0;
		$comment	= '';

		//pre_home_friend
		//$uid		=	$friends['uid'];
		$fuid		=	$friendid;
		$fusername	=	trim($friend['f_friend']);
		$gid		=	1;
		$num		=	0;
		$dateline	=	0;
		$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) && $xc->db['discuz']->query($query2)) {
			$convertedrows ++;
		} else {
			reportlog("无法转换好友数据 uid = $uid, friendid = $friendid");
		}

		$totalrows ++;
	}
	$url = 'index.php?mod=dealdata&step='.$step.'&start='.($friend['F_id']+1).'&stay='.$stay.'&totalrows='.$totalrows.'&convertedrows='.$convertedrows.'&sqlfilenum='.$sqlfilenum;
	file_put_contents(XCONVERT_ROOT.'./cache/lock/progress_'.$step.".txt", $url);
}
$end < $maxid ? $converted =1 : '';

?>