Discuz教程网

discuz x“重建(论坛/群组)帖数”计划任务的脚本文件

[复制链接]
authicon dly 发表于 2015-10-13 12:28:48 | 显示全部楼层 |阅读模式
定时任务脚本
  1. <?php
  2. /**
  3. * cron_update_lastpost.php
  4. * @重建(论坛/群组)帖数 的计划任务脚本
  5. * @2013-03-25 by 小乐Andy
  6. *
  7. */

  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }

  11. $pertaskinit = 15; //默认每个循环更新数量
  12. $pertask = isset($_GET['pertask']) ? intval($_GET['pertask']) : $pertaskinit;
  13. $current = isset($_GET['current']) && $_GET['current'] > 0 ? intval($_GET['current']) : 0;
  14. $processed = 1;

  15. while ($processed) {
  16. $queryf = C::t('forum_forum')->fetch_all_fids(1, '', '', $current, $pertask);
  17. if($queryf[0]['fid']) {
  18. foreach($queryf as $forum) {
  19. $processed = 1;
  20. $threads = $posts = 0;
  21. $threadtables = array('0');
  22. $archive = 0;
  23. foreach(C::t('forum_forum_threadtable')->fetch_all_by_fid($forum['fid']) as $data) { //板块存档表
  24. if($data['threadtableid']) {
  25. $threadtables[] = $data['threadtableid'];
  26. }
  27. }
  28. $threadtables = array_unique($threadtables);
  29. foreach($threadtables as $tableid) {
  30. $data = C::t('forum_thread')->count_posts_by_fid($forum['fid'], $tableid);
  31. $threads += $data['threads'];
  32. $posts += $data['posts'];
  33. if($data['threads'] == 0 && $tableid != 0) {
  34. C::t('forum_forum_threadtable')->delete($forum['fid'], $tableid);
  35. }
  36. if($data['threads'] > 0 && $tableid != 0) {
  37. $archive = 1;
  38. }
  39. }
  40. C::t('forum_forum')->update($forum['fid'], array('archive' => $archive));

  41. $thread = C::t('forum_thread')->fetch_by_fid_displayorder($forum['fid']);
  42. $lastpost = "$thread[tid]\t$thread[subject]\t$thread[lastpost]\t$thread[lastposter]";

  43. C::t('forum_forum')->update($forum['fid'], array('threads' => $threads, 'posts' => $posts, 'lastpost' => $lastpost));
  44. }
  45. $current += $pertask;
  46. } else {
  47. C::t('forum_forum')->clear_forum_counter_for_group();
  48. $processed = 0;
  49. }
  50. }
  51. ?>
复制代码





上一篇:Discuz开启CC后,用这段代码,蜘蛛能正常爬进来
下一篇:一次将discuz x所有用户积分全部清零的方法
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2024-5-19 04:07

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表