<?php
/*
转换广播回复
pre_forum_post
*/

if($start <= 1) {
	$sqlfilenum = 0;
}

$sqlfilenum ++;
$extrastr = '&sqlfilenum='.$sqlfilenum;

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

$query = $xc->db['source']->query("SELECT * FROM {$source_tablepre}weibo_comment WHERE cid >= $start AND cid < $start + $rpp") or dexit();
while ($pwcomment = $xc->db['source']->fetch_array($query)) {
	$pwcomment			=	daddslashes($pwcomment);
	$mid			=	$pwcomment['mid'];
	$cid			=	$pwcomment['cid'];
	$fid			=	$pwcomment['fid'];
	$tid = $xc->db['discuz']->result($xc->db['discuz']->query("SELECT tid FROM {$discuz_tablepre}m_tids WHERE mid='{$mid}' LIMIT 1"), 0);
	$first			=	0;
	$authorid		=	$pwcomment['uid'];
	$author			=	getusername($authorid);
	$subject		=	'';
	$dateline		=	$pwcomment['postdate'];
	$message		=	daddslashes(convertbbcode($pwcomment['content']));
	$useip			=	'';
	$invisible		=	0;
	$attachment		=	0;
	$rate			=	0;
	$ratetimes		=	0;
	$status			=	'';
	$tags			=	'';
	$comment		=	0;

	$field1 = array('pid');
	$query1 = getinsertsql("{$discuz_tablepre}forum_post_tableid", $field1);

	if($xc->db['discuz']->query($query1)) {
		$pid = $xc->db['discuz']->insert_id();
		$field2 = array('pid','fid','tid','first','author','authorid','subject','dateline','message','invisible','anonymous','usesig','htmlon','bbcodeoff','smileyoff','parseurloff','attachment','rate','ratetimes','status','tags','comment', 'replycredit');
		$query2 = getinsertsql("{$discuz_tablepre}forum_post", $field2);
		if($xc->config['info']['convert_type'] == 'file') {
			writesql('forum_post', $sqlfilenum, $query2);
			$convertedrows++;
		} else {
			if ($xc->db['discuz']->query($query2)) {
				$convertedrows++;
			} else {
				$xc->db['discuz']->query("DELETE FROM {$discuz_tablepre}forum_post_tableid WHERE pid='$pid'");
				reportlog("无法转换广播回复 cid = $cid subject = '$subject'");
			}
		}
	} else {
		reportlog("无法转换广播回复 cid=$cid");
	}

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

?>