consist.php
来自「eGroupWare is a multi-user, web-based gr」· PHP 代码 · 共 689 行 · 第 1/2 页
PHP
689 行
<?php/**************************************************************************** copyright : (C) 2001-2003 Advanced Internet Designs Inc.* email : forum@prohost.org* $Id: consist.php,v 1.4 2004/07/08 14:25:47 iliaa Exp $** This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or * (at your option) any later version.***************************************************************************/ @set_time_limit(600); @ini_set("memory_limit", "100M"); define('back_to_main', 1); require('./GLOBALS.php'); fud_egw(); fud_use('adm.inc', true); fud_use('glob.inc', true); fud_use('widgets.inc', true); fud_use('ext.inc', true); fud_use('ipfilter.inc', true); fud_use('login_filter.inc', true); fud_use('email_filter.inc', true); fud_use('customtags.inc', true); fud_use('groups_adm.inc', true); fud_use('cat.inc', true); fud_use('imsg.inc'); fud_use('imsg_edt.inc'); fud_use('err.inc'); fud_use('private.inc'); fud_use('th.inc'); fud_use('ipoll.inc'); fud_use('attach.inc'); fud_use('groups.inc'); fud_use('th_adm.inc'); fud_use('users_reg.inc');function draw_stat($text){ echo '<b>'.htmlspecialchars($text).'</b><br />' . "\n"; flush();}function draw_info($cnt){ draw_stat(($cnt < 1 ? 'OK' : $cnt . ' entries unmatched, deleted'));}function delete_zero($tbl, $q){ $cnt = 0; $c = q($q); while ($r = db_rowarr($c)) { $a[] = $r[0]; ++$cnt; } if ($cnt) { q('DELETE FROM '.$tbl.' WHERE id IN ('.implode(',', $a).')'); } unset($c); draw_info($cnt);} include($WWW_ROOT_DISK . 'adm/admpanel.php'); if (!isset($_POST['conf']) && !isset($_GET['enable_forum']) && !isset($_GET['opt'])) {?><form method="post" action="consist.php"><div class="alert">Consistency check is a complex process which may take several minutes to run, while it is running yourforum will be disabled.</div><h2>Do you wish to proceed?</h2><input type="submit" name="cancel" value="No"> <input type="submit" name="conf" value="Yes"><?php echo _hs; ?></form><?php require($WWW_ROOT_DISK . 'adm/admclose.php'); exit; } if ($FUD_OPT_1 & 1) { draw_stat('Disabling the forum for the duration of maintenance run'); maintenance_status('Undergoing maintenance, please come back later.', 1); } if (isset($_GET['opt'])) { draw_stat('Optimizing forum\'s SQL tables'); optimize_tables(); draw_stat('Done: Optimizing forum\'s SQL tables'); if ($FUD_OPT_1 & 1 || isset($_GET['enable_forum'])) { draw_stat('Re-enabling the forum.'); maintenance_status($DISABLED_REASON, 0); } else { echo '<font size="+1" color="red">Your forum is currently disabled, to re-enable it go to the <a href="admglobal.php?'._rsid.'">Global Settings Manager</a> and re-enable it.</font><br>'; } require($WWW_ROOT_DISK . 'adm/admclose.php'); exit; }?><script language="Javascript1.2"> var intervalID; function scrolldown() { window.scroll(0, 30000); } intervalID = setInterval('scrolldown()', 100);</script><?php $tbl = $DBHOST_TBL_PREFIX; draw_stat('Locking the database for checking'); if (__dbtype__ == 'mysql') { q('DROP TABLE IF EXISTS '.$tbl.'tmp_consist'); q('CREATE TABLE '.$tbl.'tmp_consist (p INT, ps INT UNSIGNED, c INT)'); } $tbls = get_fud_table_list(); // add the various table aliases array_push($tbls, $tbl.'users u', $tbl.'forum f', $tbl.'thread t', $tbl.'poll p', $tbl.'poll_opt po', $tbl.'poll_opt_track pot', $tbl.'msg m', $tbl.'pmsg pm', $tbl.'mod mm', $tbl.'thread_rate_track trt', $tbl.'msg_report mr', $tbl.'cat c', $tbl.'forum_notify fn', $tbl.'thread_notify tn', $tbl.'buddy b', $tbl.'user_ignore i', $tbl.'msg m1', $tbl.'msg m2', $tbl.'users u1', $tbl.'users u2', $tbl.'attach a', $tbl.'thr_exchange te', $tbl.'read r', $tbl.'mime mi', $tbl.'group_members gm', $tbl.'group_resources gr', $tbl.'groups g', $tbl.'group_members gm1', $tbl.'group_members gm2', $tbl.'themes thm'); db_lock(implode(' WRITE, ', $tbls).' WRITE'); draw_stat('Locked!'); draw_stat('Validating category order'); $i = 1; $c = q('SELECT id, view_order FROM '.$tbl.'cat ORDER BY view_order, id'); while ($r = db_rowarr($c)) { if ($r[1] != $i) { q('UPDATE '.$tbl.'cat SET view_order='.$i.' WHERE id='.$id); } ++$i; } unset($r); draw_stat('Done: Validating category order'); draw_stat('Checking if moderator and users table match'); delete_zero($tbl.'mod', 'SELECT mm.id FROM '.$tbl.'mod mm LEFT JOIN '.$tbl.'users u ON mm.user_id=u.id LEFT JOIN '.$tbl.'forum f ON f.id=mm.forum_id WHERE u.id IS NULL OR f.id IS NULL'); draw_stat('Rebuilding moderators'); rebuildmodlist(); draw_stat('Done: Rebuilding moderators'); draw_stat('Checking if all private messages have users'); $c = uq('SELECT pm.id FROM '.$tbl.'pmsg pm LEFT JOIN '.$tbl.'users u ON u.id=pm.ouser_id WHERE (pm.pmsg_opt & 16)=0 AND u.id IS NULL'); while ($r = db_rowarr($c)) { $dpm[] = $r[0]; } $c = uq('SELECT pm.id FROM '.$tbl.'pmsg pm LEFT JOIN '.$tbl.'users u ON u.id=pm.duser_id WHERE ((pm.pmsg_opt & 16) > 0 AND pm.pmsg_opt>=16) AND u.id IS NULL'); while ($r = db_rowarr($c)) { $dpm[] = $r[0]; } if (isset($dpm)) { $cnt = count($dpm); foreach ($dpm as $v) { pmsg_del($v, 5); } } else { $cnt = 0; } draw_info($cnt); draw_stat('Checking messages against users & threads'); delete_zero($tbl.'msg', 'SELECT m.id FROM '.$tbl.'msg m LEFT JOIN '.$tbl.'users u ON u.id=m.poster_id LEFT JOIN '.$tbl.'thread t ON t.id=m.thread_id LEFT JOIN '.$tbl.'forum f ON f.id=t.forum_id WHERE (m.poster_id!=0 AND u.id IS NULL) OR t.id IS NULL OR f.id IS NULL'); draw_stat('Checking threads against forums'); delete_zero($tbl.'thread', 'SELECT t.id FROM '.$tbl.'thread t LEFT JOIN '.$tbl.'forum f ON f.id=t.forum_id WHERE f.id IS NULL'); draw_stat('Checking message approvals'); $m = array(); $c = uq('SELECT m.id FROM '.$tbl.'msg m INNER JOIN '.$tbl.'thread t ON m.thread_id=t.id INNER JOIN '.$tbl.'forum f ON t.forum_id=f.id WHERE m.apr=0 AND (f.forum_opt & 2) > 0'); while ($r = db_rowarr($c)) { $m[] = $r[0]; } if (count($m)) { q('UPDATE '.$tbl.'msg SET apr=1 WHERE id IN('.implode(',', $m).')'); unset($m); } draw_stat('Done: Checking message approvals'); $cnt = 0; $del = $tr = array(); draw_stat('Checking threads against messages'); q('UPDATE '.$tbl.'thread SET replies=0'); $c = uq('SELECT m.thread_id, t.id, count(*) as cnt FROM '.$tbl.'thread t LEFT JOIN '.$tbl.'msg m ON t.id=m.thread_id WHERE m.apr=1 GROUP BY m.thread_id,t.id ORDER BY cnt'); while ($r = db_rowarr($c)) { if (!$r[0]) { $del[] = $r[1]; ++$cnt; } else { $tr[$r[2] - 1][] = $r[1]; } } if (count($del)) { q('DELETE FROM '.$tbl.'thread WHERE id='.implode(',', $del)); } unset($tr[0]); foreach ($tr as $k => $v) { q('UPDATE '.$tbl.'thread SET replies='.$k.' WHERE id IN('.implode(',', $v).')'); } unset($tr, $del); draw_info($cnt); draw_stat('Checking thread last & first post ids'); $c = q('SELECT m1.id, m2.id, t.id FROM '.$tbl.'thread t LEFT JOIN '.$tbl.'msg m1 ON t.root_msg_id=m1.id LEFT JOIN '.$tbl.'msg m2 ON t.last_post_id=m2.id WHERE m1.id IS NULL or m2.id IS NULL'); while ($r = db_rowarr($c)) { if (!$r[0]) { if (!($root = q_singleval('SELECT id FROM '.$tbl.'msg WHERE thread_id='.$r[2].' ORDER BY post_stamp LIMIT 1'))) { q('DELETE FROM '.$tbl.'thread WHERE id='.$r[2]); } else { q('UPDATE '.$tbl.'thread SET root_msg_id='.$root.' WHERE id='.$r[2]); } } else { $r2 = db_saq('SELECT id, post_stamp FROM '.$tbl.'msg WHERE thread_id='.$r[2].' ORDER BY post_stamp DESC LIMIT 1'); if (!$r2) { q('DELETE FROM '.$tbl.'thread WHERE id='.$r[2]); } else { q('UPDATE '.$tbl.'thread SET last_post_id='.$r2[0].', last_post_date='.$r2[1].' WHERE id='.$r[2]); } } } draw_stat('Done: Checking thread last & first post ids'); draw_stat('Checking forum & topic relations'); $c = q('SELECT id FROM '.$tbl.'forum'); while ($f = db_rowarr($c)) { $r = db_saq('select SUM(replies), COUNT(*) FROM '.$tbl.'thread t INNER JOIN '.$tbl.'msg m ON t.root_msg_id=m.id AND m.apr=1 WHERE t.forum_id='.$f[0]); if (!$r[1]) { q('UPDATE '.$tbl.'forum SET thread_count=0, post_count=0, last_post_id=0 WHERE id='.$f[0]); } else { $lpi = q_singleval('SELECT MAX(last_post_id) FROM '.$tbl.'thread WHERE forum_id='.$f[0].' AND moved_to=0'); q('UPDATE '.$tbl.'forum SET thread_count='.$r[1].', post_count='.($r[0] + $r[1]).', last_post_id='.(int)$lpi.' WHERE id='.$f[0]); } } unset($c); draw_stat('Done: Checking forum & topic relations'); draw_stat('Validating Forum Order'); $cat = 0; $c = q('SELECT id, cat_id, view_order FROM '.$tbl.'forum WHERE cat_id>0 ORDER BY cat_id, view_order'); while ($f = db_rowarr($c)) { if ($cat != $f[1]) { $i = 0; $cat = $f[1]; } ++$i; if ($i != $f[2]) { q('UPDATE '.$tbl.'forum SET view_order='.$i.' WHERE id='.$f[0]); } } draw_stat('Done: Validating Forum Order'); draw_stat('Checking thread_exchange'); delete_zero($tbl.'thr_exchange', 'SELECT te.id FROM '.$tbl.'thr_exchange te LEFT JOIN '.$tbl.'thread t ON t.id=te.th LEFT JOIN '.$tbl.'forum f ON f.id=te.frm WHERE t.id IS NULL or f.id IS NULL'); draw_stat('Checking read table against users & threads'); delete_zero($tbl.'read', 'SELECT r.id FROM '.$tbl.'read r LEFT JOIN '.$tbl.'users u ON r.user_id=u.id LEFT JOIN '.$tbl.'thread t ON r.thread_id=t.id WHERE t.id IS NULL OR u.id IS NULL'); draw_stat('Checking file attachments against messages'); $arm = array(); $c = uq('SELECT a.id FROM '.$tbl.'attach a LEFT JOIN '.$tbl.'msg m ON a.message_id=m.id WHERE m.id IS NULL AND attach_opt=0'); while ($r = db_rowarr($c)) { $arm[] = $r[0]; } $c = uq('SELECT a.id FROM '.$tbl.'attach a LEFT JOIN '.$tbl.'pmsg pm ON a.message_id=pm.id WHERE pm.id IS NULL AND attach_opt=1'); while ($r = db_rowarr($c)) { $arm[] = $r[0]; } if (($cnt = count($arm))) { foreach ($arm as $a) { @unlink($FILE_STORE . $a . 'atch'); } q('DELETE FROM '.$tbl.'attach WHERE id IN('.implode(',', $arm).')'); } draw_info($cnt); draw_stat('Rebuild attachment cache for regular messages'); $oldm = ''; $atr = array(); q('UPDATE '.$tbl.'msg SET attach_cnt=0, attach_cache=NULL'); $c = q('SELECT a.id, a.original_name, a.fsize, a.dlcount, CASE WHEN mi.icon IS NULL THEN \'unknown.gif\' ELSE mi.icon END, a.message_id FROM '.$tbl.'attach a LEFT JOIN '.$tbl.'mime mi ON a.mime_type=mi.id WHERE attach_opt=0'); while ($r = db_rowarr($c)) { if ($oldm != $r[5]) { if ($oldm) { q('UPDATE '.$tbl.'msg SET attach_cnt='.count($atr).', attach_cache='.strnull(addslashes(@serialize($atr))).' WHERE id='.$oldm); $atr = array(); } $oldm = $r[5]; } unset($r[5]); $atr[] = $r; } unset($c); if (count($atr)) { q('UPDATE '.$tbl.'msg SET attach_cnt='.count($atr).', attach_cache='.strnull(addslashes(@serialize($atr))).' WHERE id='.$oldm); } draw_stat('Done: Rebuild attachment cache for regular messages'); draw_stat('Rebuild attachment cache for private messages'); q('UPDATE '.$tbl.'pmsg SET attach_cnt=0'); $c = q('SELECT count(*), message_id FROM '.$tbl.'attach WHERE attach_opt=1 GROUP BY message_id'); while ($r = db_rowarr($c)) { q('UPDATE '.$tbl.'pmsg SET attach_cnt='.$r[0].' WHERE id='.$r[1]); } unset($c); draw_stat('Done: Rebuild attachment cache for private messages'); draw_stat('Checking message reports'); delete_zero($tbl.'msg_report', 'SELECT mr.id FROM '.$tbl.'msg_report mr LEFT JOIN '.$tbl.'msg m ON mr.msg_id=m.id WHERE m.id IS NULL'); draw_stat('Checking polls against messages'); $cnt = 0; $c = q('SELECT p.id, m.id FROM '.$tbl.'poll p LEFT JOIN '.$tbl.'msg m ON p.id=m.poll_id WHERE m.id IS NULL OR p.id IS NULL'); while ($r = db_rowarr($c)) { if ($r[0]) { q('DELETE FROM '.$tbl.'poll WHERE id='.$r[0]); ++$cnt; } else { q('UPDATE '.$tbl.'msg SET poll_id=0, poll_cache=NULL WHERE id='.$r[1]); } } unset($c); draw_info($cnt); draw_stat('Checking polls options against polls'); delete_zero($tbl.'poll_opt', 'SELECT po.id FROM '.$tbl.'poll_opt po LEFT JOIN '.$tbl.'poll p ON p.id=po.poll_id WHERE p.id IS NULL'); draw_stat('Checking polls votes'); delete_zero($tbl.'poll_opt_track', 'SELECT pot.id FROM '.$tbl.'poll_opt_track pot LEFT JOIN '.$tbl.'poll p ON p.id=pot.poll_id LEFT JOIN '.$tbl.'poll_opt po ON po.id=pot.poll_opt LEFT JOIN '.$tbl.'users u ON u.id=pot.user_id WHERE u.id IS NULL OR po.id IS NULL OR p.id IS NULL'); draw_stat('Rebuilding poll cache'); // first we validate to vote counts for each option q('UPDATE '.$tbl.'poll_opt SET count=0'); $c = q('SELECT poll_opt, count(*) FROM '.$tbl.'poll_opt_track GROUP BY poll_opt'); while ($r = db_rowarr($c)) { q('UPDATE '.$tbl.'poll_opt SET count='.(int)$r[1].' WHERE id='.$r[0]); } unset($c);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?