<?php
/*
收藏夹表：pre_home_favorite
*/
if($start <= 1) {
	truncatetable('home_favorite');
}

$maxuid = $xc->db['source']->result($xc->db['source']->query("SELECT max(uid) FROM {$source_tablepre}favors"), 0);
if($start < $maxuid) $converted = 1;

$query = $xc->db['source']->query("SELECT * FROM {$source_tablepre}favors WHERE uid >= $start AND uid < $start + $rpp") or dexit();
while ($favorite = $xc->db['source']->fetch_array($query)) {
	$favorite	=	daddslashes($favorite);
	
	//pre_home_favorite
	$uid	=	$favorite['uid'];
	$tids	=	explode(',', $favorite['tids']);
	$spaceuid	=	'';
	
	$query1 = "INSERT INTO {$discuz_tablepre}home_favorite (uid,id,spaceuid) VALUES ";
	$sqladd = $comma = '';
	foreach($tids AS $tid) {
		$tid = intval($tid);
		if($tid) {
			$spaceuid	=	$xc->db['discuz']->result($xc->db['discuz']->query("SELECT authorid FROM {$discuz_tablepre}forum_thread WHERE tid='$tid'"));
			$sqladd .= "$comma ('$uid', '$tid', '$spaceuid')";
			$comma = ',';
		}
	}

	if(!$sqladd) {
		continue;
	} else {
		$query1 = $query1.$sqladd;
	}

	if ($xc->db['discuz']->query($query1)) {
		$convertedrows ++;
	} else {
		reportlog("转换收藏夹出错，SQL：<br><textarea rows=\"3\" style=\"width: 100%;\">".$query1."</textarea>");
	}
	$converted = 1;
	$totalrows ++;
}
?>