定时任务脚本- <?php
- /**
- * cron_update_lastpost.php
- * @重建(论坛/群组)帖数 的计划任务脚本
- * @2013-03-25 by 小乐Andy
- *
- */
- if(!defined('IN_DISCUZ')) {
- exit('Access Denied');
- }
- $pertaskinit = 15; //默认每个循环更新数量
- $pertask = isset($_GET['pertask']) ? intval($_GET['pertask']) : $pertaskinit;
- $current = isset($_GET['current']) && $_GET['current'] > 0 ? intval($_GET['current']) : 0;
- $processed = 1;
- while ($processed) {
- $queryf = C::t('forum_forum')->fetch_all_fids(1, '', '', $current, $pertask);
- if($queryf[0]['fid']) {
- foreach($queryf as $forum) {
- $processed = 1;
- $threads = $posts = 0;
- $threadtables = array('0');
- $archive = 0;
- foreach(C::t('forum_forum_threadtable')->fetch_all_by_fid($forum['fid']) as $data) { //板块存档表
- if($data['threadtableid']) {
- $threadtables[] = $data['threadtableid'];
- }
- }
- $threadtables = array_unique($threadtables);
- foreach($threadtables as $tableid) {
- $data = C::t('forum_thread')->count_posts_by_fid($forum['fid'], $tableid);
- $threads += $data['threads'];
- $posts += $data['posts'];
- if($data['threads'] == 0 && $tableid != 0) {
- C::t('forum_forum_threadtable')->delete($forum['fid'], $tableid);
- }
- if($data['threads'] > 0 && $tableid != 0) {
- $archive = 1;
- }
- }
- C::t('forum_forum')->update($forum['fid'], array('archive' => $archive));
- $thread = C::t('forum_thread')->fetch_by_fid_displayorder($forum['fid']);
- $lastpost = "$thread[tid]\t$thread[subject]\t$thread[lastpost]\t$thread[lastposter]";
- C::t('forum_forum')->update($forum['fid'], array('threads' => $threads, 'posts' => $posts, 'lastpost' => $lastpost));
- }
- $current += $pertask;
- } else {
- C::t('forum_forum')->clear_forum_counter_for_group();
- $processed = 0;
- }
- }
- ?>
复制代码
|