<?php
/**
 * 清除緩存
 *
 * @version        $Id: sys_cache_up.php 1 16:22 2010年7月20日Z tianya $
 * @package        DedeCMS.Administrator
 * @copyright      Copyright (c) 2007 - 2010, DesDev, Inc.
 * @license        http://help.dedecms.com/usersguide/license.html
 * @link           http://www.dedecms.com
 */
require_once(dirname(__FILE__)."/config.php");
CheckPurview('sys_ArcBatch');
if(empty($dopost)) $dopost = '';
if(empty($step)) $step = 1;

if($dopost=="ok")
{
    if(empty($uparc)) $uparc = 0;
    if($step == -1)
    {
        if($uparc == 0) sleep(1);
        ShowMsg("成功更新所有緩存！","javascript:;");
        exit();
    }

    //更新欄目緩存
    else if($step == 1)
    {
        UpDateCatCache();
        ClearOptCache();
        ShowMsg("成功更新欄目緩存，及後台欄目選項,準備更新枚舉緩存...","sys_cache_up.php?dopost=ok&step=2&uparc=$uparc");
        exit();
    }

    //更新枚舉緩存
    else if($step == 2)
    {
        include_once(DEDEINC."/enums.func.php");
        WriteEnumsCache();
        //WriteAreaCache(); 已過期
        ShowMsg("成功更新枚舉緩存，準備更新調用緩存...", "sys_cache_up.php?dopost=ok&step=3&uparc=$uparc");
        exit();
    }

    //清理arclist調用緩存、過期會員訪問歷史、過期短信
    else if($step == 3)
    {
        echo '<meta http-equiv="Content-Type" content="text/html; charset='.$cfg_soft_lang.'">';
        $dsql->ExecuteNoneQuery("DELETE FROM `#@__arccache`");
        echo "\n成功更新arclist調用緩存，準備清理過期會員訪問歷史...<hr />";
        $oldtime = time() - (90 * 24 * 3600);
        $dsql->ExecuteNoneQuery("DELETE FROM `#@__member_vhistory` WHERE vtime<'$oldtime' ");
        echo "成功清理過期會員訪問歷史，準備清理過期短信...<hr />";
        $dsql->ExecuteNoneQuery("DELETE FROM `#@__member_pms` WHERE sendtime<'$oldtime' ");
        echo "成功清理過期短信，準備修正錯誤文檔，這可能要占較長的時間...";
        if($uparc == 1)
        {
            echo "<script language='javascript'>location='sys_cache_up.php?dopost=ok&step=9';</script>";
        }
        else
        {
            echo "<script language='javascript'>location='sys_cache_up.php?dopost=ok&step=-1&uparc=$uparc';</script>";
        }
        exit();
    }
    //修正錯誤文檔
    else if($step == 9)
    {
        ShowMsg('修正錯誤文檔操作已經取消，請在&lt;系統-&gt;系統錯誤修復[S]&gt;中操作...','sys_cache_up.php?dopost=ok&step=-1&uparc=1',0,5000);
      exit();
    }
}
include DedeInclude('templets/sys_cache_up.htm');