<?php
/*
推荐主题表：pre_forum_forumrecommend
*/

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

$maxfid = $xc->db['source']->result($xc->db['source']->query("SELECT max(fid) FROM {$source_tablepre}forumsextra"), 0);

if($start < $maxfid) $converted = 1;

$query		= $xc->db['source']->query("SELECT * FROM {$source_tablepre}forumsextra WHERE fid >= $start AND fid < $start + $rpp") or dexit();
while($f 	= $xc->db['source']->fetch_array($query)) {

	$fset 			= unserialize($f['forumset']);
	$forumrecommend = unserialize($f['commend']);
	$fid			= $f['fid'];
	$modrecommendnew = array(
		'open'		=> intval($fset['commend']),
		'sort'		=> ($fset['autocommend'] > 0 ? 2 : 0),
		'orderby'	=> ($fset['autocommend'] > 1 ? intval($fset['autocommend'] - 1) : 0),
		'num'		=> ($fset['commendnum'] ? intval($fset['commendnum']) : 10),
		'maxlength' => ($fset['commendlength'] ? intval($fset['commendlength']) : 0),
		'cachelife' => ($fset['commendtime'] ? intval($fset['commendtime']) : 0),
		'dateline'	=> 0
	);

	$modrecommendnew = $modrecommendnew && is_array($modrecommendnew) ? addslashes(serialize($modrecommendnew)) : '';

	$xc->db['discuz']->query("UPDATE {$discuz_tablepre}forum_forumfield SET modrecommend = '$modrecommendnew' WHERE fid = '$fid'");
	
	//没有开启版主推荐功能
	if(empty($forumrecommend)){
		continue;
	}
	foreach ($forumrecommend as $rc) {
		//pre_forum_forumrecommend
		//$fid = $f['fid'];
		$tid			=	$rc['tid'];
		$typeid			=	'';
		$displayorder 	=	0;
		$subject		=	addslashes(cutstr($rc['subject'], 80));
		$author			=	addslashes($rc['author']);
		$authorid		=	$rc['authorid'];
		$moderatorid	=	0;
		$expiration		=	$timestamp + 31536000;
		$position		=	'';
		$highlight		=	'';
		$aid			=	'';
		$filename		=	'';

		$field1			=	array('fid','tid','typeid','displayorder','subject','author','authorid','moderatorid','expiration','position','highlight','aid','filename');
		$query1			=	getinsertsql("{$discuz_tablepre}forum_forumrecommend", $field1);
		
		if($xc->db['discuz']->query($query1)) {
			$convertedrows ++;
		} else {
			reportlog("插入 版主推荐主题 数据出错, 标题 = $subject , tid = $tid");
		}
		$totalrows ++;
	}
	$url = 'index.php?mod=dealdata&step='.$step.'&start='.($f['fid']+1).'&stay='.$stay.'&totalrows='.$totalrows.'&convertedrows='.$convertedrows.'&sqlfilenum='.$sqlfilenum;
	file_put_contents(XCONVERT_ROOT.'./cache/lock/progress_'.$step.".txt", $url);
}
?>