<?php /* * 删除指定条件的资讯 * 此脚本使用时需谨慎使用,使用前备份门户表 * pre_portal_category pre_portal_article_title pre_portal_article_content pre_portal_article_count pre_portal_attachment * */ define('IN_DISCUZ', true); define('CHARSET', 'utf-8'); define('DISCUZ_ROOT', substr(dirname(__FILE__), 0, -6)) . '/'; require_once(DISCUZ_ROOT . 'config/config_global.php'); require_once(DISCUZ_ROOT . 'config/config_remake_imgsize.php'); require_once(DISCUZ_ROOT . 'source/class/class_upload.php'); require_once(DISCUZ_ROOT . 'source/class/class_image.php'); require_once(DISCUZ_ROOT . 'source/class/class_image_ext.php'); require_once(DISCUZ_ROOT . 'source/function/function_core.php'); require_once(DISCUZ_ROOT . '_TOOLS/function/function_getdata_common.php'); require_once(DISCUZ_ROOT . '_CLASS/_COMMON_CLASS/Mysql.class.php'); $dbconfig = $_config['db']['1']; $_G['tablepre'] = $dbconfig['tablepre']; $mysql = new mysql($dbconfig['dbhost'], $dbconfig['dbuser'], $dbconfig['dbpw'], $dbconfig['dbname'], $dbconfig['dbcharset'], $dbconfig['pconnect']); $_G['setting'] = unserialize($mysql->resultOne("SELECT data FROM " . $_G['tablepre'] . "common_syscache WHERE cname='setting'")); $logfilename = DISCUZ_ROOT . '/data/log/deleteArticles' . date('Ymd') . '.txt'; //日志文件 $showprogress = isset($argv[1]) && trim($argv[1]) == '1' ? true : 1; //是否显示过程信息 $where = ' WHERE uid=9832 and aid>1815'; // uid=10336 and aid>1815 just for yuanjun Editor $totalnum = $mysql->resultOne("SELECT count(*) FROM pre_portal_article_title $where"); echo 'Total: ' . $totalnum; //exit(); $pertask = 50; //每次从数据库中查询多少条数据,分批处理 $circletimes = ceil($totalnum / $pertask); if ($totalnum < $pertask) { $pertask = $totalnum; } for ($i = 0; $i < $circletimes; $i++) { $aidsArr = $mysql->fetchAll("SELECT aid, catid FROM pre_portal_article_title $where LIMIT $pertask"); $aids = array(); $catids = array(); foreach ($aidsArr as $arr) { $aids[] = $arr['aid']; $catids[$arr['catid']] = isset($catids[$arr['catid']]) ? $catids[$arr['catid']] + 1 : 1; } $idwhere = " WHERE aid in (" . implode(',', $aids) . ")"; //update pre_portal_category $catana = ''; foreach ($catids as $catid => $num) { $catana .= " catid: $catid => num:$num". " "; $mysql->increase($_G['tablepre'] . 'portal_category', array('articles' => -$num), array('catid' => $catid)); } //delete article from pre_portal_article_content; $mysql->query("DELETE FROM pre_portal_article_count $idwhere"); //delete article from pre_portal_article_content; $mysql->query("DELETE FROM pre_portal_article_content $idwhere"); //delete article from pre_portal_article_title $mysql->query("DELETE FROM pre_portal_article_title $idwhere"); // delete article from pre_portal_attachment $attaches = $mysql->fetchAll("SELECT * FROM pre_portal_attachment $idwhere"); if (!empty($attaches)) { foreach ($attaches as $attach) { $imgurl = $_G['setting']['attachdir'] . 'portal/' . $attach['attachment']; @unlink($imgurl); } } //增加日志 $fp = @fopen($logfilename, 'a+'); $fileadd = $catana. "Deleted articles aid is " . implode(',', $aids) . "(" . date("Y-m-d H:i:s", time()) . ")" . " "; @fwrite($fp, $fileadd); @fclose($fp); $showprogress && showprogress("$i/$circletimes articles has deleted"); }