任务时间表(crontab)文件储存的指令被crond守护进程激活,守护进程在后台运行,并每一分钟检查是否有定期的作业需要执行。这类作业一般称为cron jobs。
install/data/install_data.sql 第59行:
INSERT INTO pre_common_cron VALUES ('19','1','system','统计今日热帖','cron_todayheats_daily.php','1269746623','1269792000','-1','-1','0','0');
source/include/cron/cron_todayheats_daily.php 全部代码:
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: cron_todayheats_daily.php 31913 2012-10-24 06:52:26Z zhengqingpeng $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
$yesterday = strtotime(dgmdate(TIMESTAMP, 'Y-m-d'))-86400;
$data = $tids = $fids = $hotnum = array();
$daystr = dgmdate($yesterday, 'Ymd');
foreach(C::t('forum_thread')->fetch_all_for_guide('hot', 0, array(), $_G['setting']['heatthread']['guidelimit'], $yesterday, 0, 0) as $thread) {
$data[$thread['tid']] = array(
'cid' => 0,
'fid' => $thread['fid'],
'tid' => $thread['tid']
);
$fids[$thread['fid']] = array('fid' => $thread['fid'], 'dateline' => $daystr, 'hotnum' => 0);
$tids[$thread['fid']][$thread['tid']] = $thread['tid'];
}
if($data) {
$cids = C::t('forum_threadcalendar')->fetch_all_by_fid_dateline(array_keys($fids), $daystr);
foreach($cids as $fid => $cinfo) {
$hotnum[$cinfo['cid']] = count($tids[$fid]);
foreach($tids[$fid] as $tid) {
$data[$tid]['cid'] = $cinfo['cid'];
}
unset($fids[$fid]);
}
if($fids) {
C::t('forum_threadcalendar')->insert_multiterm($fids);
foreach(C::t('forum_threadcalendar')->fetch_all_by_fid_dateline(array_keys($fids), $daystr) as $fid => $cinfo) {
$hotnum[$cinfo['cid']] = count($tids[$fid]);
foreach($tids[$fid] as $tid) {
$data[$tid]['cid'] = $cinfo['cid'];
}
}
}
C::t('forum_threadhot')->insert_multiterm($data);
foreach($hotnum as $cid => $num) {
C::t('forum_threadcalendar')->update($cid, array('hotnum' => $num));
}
}
?>
Discuz X3 database table structure:
表名 | 说明 | 字段 | 类型 | 默认 | 非空 | 递增 | 备注 |
forum_threadhot |
热帖日历数据表 |
fid |
mediumint(8) unsigned |
0 |
NO |
否 |
版块ID |
forum_threadhot |
热帖日历数据表 |
tid |
mediumint(8) unsigned |
0 |
NO |
否 |
主题ID |
source/class/table/table_forum_threadcalendar.php 全部代码:
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: table_forum_threadcalendar.php 31913 2012-10-24 06:52:26Z zhengqingpeng $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class table_forum_threadcalendar extends discuz_table {
public function __construct() {
$this->_table = 'forum_threadcalendar';
$this->_pk = 'cid';
parent::__construct();
}
public function fetch_by_fid_dateline($fid, $dateline = 0, $order = 'dateline', $sort = 'DESC') {
$parameter = array($this->_table);
$wherearr = array();
$wheresql = '';
if($fid) {
$wherearr[] = 'fid=%d';
$parameter[] = $fid;
}
if($dateline) {
$wherearr[] = 'dateline=%d';
$parameter[] = $dateline;
}
if($wherearr) {
$wheresql = ' WHERE '.implode(' AND ', $wherearr);
}
return DB::fetch_first('SELECT * FROM %t '.$wheresql.' ORDER BY '.DB::order($order, $sort), $parameter, $this->_pk);
}
public function fetch_all_by_dateline($dateline) {
$dateline = dintval($dateline);
if($dateline) {
return DB::fetch_all('SELECT * FROM %t WHERE dateline=%d', array($this->_table, $dateline), 'fid');
} else {
return array();
}
}
public function fetch_all_by_fid_dateline($fids, $dateline = 0) {
$parameter = array($this->_table);
$wherearr = array();
$wheresql = '';
$fids = dintval($fids, true);
if($fids) {
$wherearr[] = is_array($fids) ? 'fid IN(%n)' : 'fid=%d';
$parameter[] = $fids;
}
$dateline = dintval($dateline);
if($dateline) {
$wherearr[] = 'dateline=%d';
$parameter[] = $dateline;
}
if($wherearr) {
$wheresql = ' WHERE '.implode(' AND ', $wherearr);
}
return DB::fetch_all('SELECT * FROM %t '.$wheresql, $parameter, 'fid');
}
public function insert_multiterm($dataarr) {
$allkey = array('fid', 'dateline', 'hotnum');
$sql = array();
foreach($dataarr as $key => $value) {
if(is_array($value)) {
$fid = dintval($value['fid']);
$dateline = dintval($value['dateline']);
$hotnum = dintval($value['hotnum']);
$sql[] = "($fid, $dateline, $hotnum)";
}
}
if($sql) {
return DB::query('INSERT INTO '.DB::table($this->_table)." (`fid`, `dateline`, `hotnum`) VALUES ".implode(',', $sql), true);
}
return false;
}
}
?>
install/data/install.sql 第2902行:
DROP TABLE IF EXISTS pre_forum_threadcalendar;
CREATE TABLE pre_forum_threadcalendar (
cid mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
fid mediumint(8) unsigned NOT NULL DEFAULT '0',
dateline int(10) unsigned NOT NULL DEFAULT '0',
hotnum int(10) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (cid),
KEY fid (fid,dateline)
) TYPE=MyISAM;
|