Files
2021-03-13 18:42:01 +08:00

219 lines
8.6 KiB
PHP

<?php
namespace Admin\Controller;
use Think\Controller;
class UpdateController extends AdminController{
public function __construct(){
parent::__construct();
$this->table=new \Admin\Model\UpdateModel();
//是否刷新首页
$this->isUpdateHome=C('setting.indexType')=='static'?1:0;
//不刷新首页,删除
if(!$this->isUpdateHome){
unlink("./".C("setting.indexFileName"));
}
}
//刷新入口页同
public function index(){
//缓存选项
$updateInc=array(
array("taskName"=>"updateCatCache","group"=>1,"task_index"=>1,"name"=>"栏目缓存","icon"=>"&#xe63e;","color"=>"color1","num"=>1),
array("taskName"=>"updateModelCache","group"=>1,"task_index"=>2,"name"=>"模型缓存","icon"=>"&#xe613;","color"=>"color2","num"=>1),
array("taskName"=>"updateModel","group"=>1,"task_index"=>3,"name"=>"模型表单缓存","icon"=>"&#xe63e;","color"=>"color3","num"=>$this->table->fileNum("./Application/Data/modelTemp")),
array("taskName"=>"updateTemplate","group"=>1,"task_index"=>4,"name"=>"模板缓存","icon"=>"&#xe62d;","color"=>"color4","num"=>M("template")->count()),
array("taskName"=>"updatePageTemplate","group"=>1,"task_index"=>5,"name"=>"单页缓存","icon"=>"&#xe62d;","color"=>"color5","num"=>M("page")->count()),
array("taskName"=>"updateFeedbackModel","group"=>1,"task_index"=>6,"name"=>"反馈表单缓存","icon"=>"&#xe63a;","color"=>"color6","num"=>$this->table->fileNum("./Application/Data/feedbackTemp")),
array("taskName"=>"del_runtime","group"=>1,"task_index"=>7,"name"=>"缓存文件夹","icon"=>"&#xe638;","color"=>"color7","num"=>"4"),
//首页,栏目等刷新
array("taskName"=>"updateHome","group"=>2,"task_index"=>8,"name"=>"刷新首页","icon"=>"&#xe608;","color"=>"color5","num"=>$this->isUpdateHome),
array("taskName"=>"updatePage","group"=>2,"task_index"=>9,"name"=>"刷新自定义页","icon"=>"&#xe607;","color"=>"color3","num"=>$this->getPageNum()),
array("taskName"=>"updatePages","group"=>2,"task_index"=>10,"name"=>"刷新自定义列表页","icon"=>"&#xe661;","color"=>"color4","num"=>$this->getPagesNum(),"ids"=>$this->getPagesids()),
array("taskName"=>"updateCat","group"=>2,"task_index"=>11,"name"=>"刷新栏目页","icon"=>"&#xe84a;","color"=>"color6","num"=>$this->getCatPage(),"ids"=>$this->getCatids()),
);
//内容刷新
$table=M("table")->select() ;
foreach($table as $v){
$updateInc[]=array(
"taskName"=>"updateDetai",
"group"=>3,
"task_index"=>12,
"name"=>$v["name"],
"icon"=>"&#xe88d;",
"color"=>"color3",
"num"=>M("cms_".$v["table_name"])->where("checked=1")->count(),
"table"=>"cms_".$v["table_name"]
);
}
$this->updateInc=$updateInc;
if(IS_POST){
$taskNameArr=$_POST["taskName"];
foreach($taskNameArr as $v){
$updateInc[$v]["alreadyNum"]=0;
$updateInc[$v]["selfPerent"]=0;
$updateInc[$v]["ids_key"]=0;//用于栏目和自定义列表,存放栏目id对应的数组下标
$updateInc[$v]["className"]="";
$obj[$v]=$updateInc[$v];
}
$obj=array_values($obj);//数组重新编号
$this->data= json_encode($obj);
$this->display("Refreshing");
}else{
$this->display("Refresh");
}
}
//获取要刷新的栏目id,返回的是数组
public function getCatids(){
$data=M("cat")->where(array(
"statue"=>1,
"list_type"=>"static",
))->order("catid asc")->getField("catid",true);
return $data;
}
//获取自定义列表id,返回的是数组
public function getPagesids(){
$data=M("pages")->where("path_type='static'")->getField("pages_id",true);
return $data;
}
//获取所有栏目下的分页数量总和
public function getCatPage(){
$data=M("cat")->field("catid,infonum,lencord")->where(array(
"statue"=>1,
"list_type"=>"static",
))->select();
$count=0;
foreach($data as $v){
$total=ceil($v[infonum]/$v[lencord]);
$total=$total?$total:1;
$count=$count+$total;
}
return $count;
}
//获取自定义页数量
public function getPageNum(){
return M("page")->where("path_type='static'")->count();
}
//获取自定义列表页数量
public function getPagesNum(){
$data=M("pages")->where("path_type='static'")->select();
$count=0;
$Model = new \Think\Model;
foreach($data as $v){
$query=$Model->query($v[count_sql]);
$total=$query[0][total];
$count=$count+(ceil($total/$v[lencord]));
}
return $count;
}
//
//更新栏目缓存
public function updateCatCache(){
//记住,等下信息数量也要更新
$Model=new \Admin\Model\CatModel();
$Model->updateCache();
$this->success(array(
"complete"=>1,
"num"=>1,
));
}
//更新模型缓存
public function updateModelCache(){
$Model=new \Admin\Model\ModelModel();
$Model->updateCache();
$this->success(array(
"complete"=>1,
"num"=>1,
));
}
//更新所有模型表单缓存
public function updateModel(){
$rs=M("model")->field("modelid")->select();
$Model=new \Admin\Model\ModelModel();
delDirAndFile(APP_PATH.$Model::modelTempPath);//清空文件夹
foreach($rs as $v){
$Model->updateModelTemp($v["modelid"]);//后台
$Model->updateCatModelTemp($v["modelid"]);//栏目模型字段
$Model->updateModelTempMember($v["modelid"]);//投稿
}
$this->success(array(
"complete"=>1,
"num"=>$this->table->fileNum("./Application/Data/modelTemp"),
));
}
//更新所有模板缓存
public function updateTemplate(){
$rs=M("template")->field("template_id")->select();
$Model=new \Admin\Model\TemplateModel();
delDirAndFile(C("CMS_TEMP_PATH"));//清空文件夹
foreach($rs as $v){
$Model->makeTemplateFile($v["template_id"]);
}
$this->success(array(
"complete"=>1,
"num"=>M("template")->count(),
));
}
//更新单页模板缓存
public function updatePageTemplate(){
$rs=M("page")->field("page_id,pagemod")->select();
$PageModel=new \Admin\Model\PageModel();
foreach($rs as $v){
if($v[pagemod]==1){
$PageModel->makePageTemplateFile($v[page_id]);
}else{
//如果不是页面式,删除模板文件
$PageModel->deletePageTemplateFile($v[page_id]);
}
}
$this->success(array(
"complete"=>1,
"num"=>M("page")->count(),
));
}
//更新留言反馈缓存
public function updateFeedbackModel(){
$cat=M("feedback_cat")->select();
$ModelModel=new \Admin\Model\FeedbackCatModel();
foreach($cat as $v){
$ModelModel->updateModelTemp($v["catid"]);
}
$this->success(array(
"complete"=>1,
"num"=>$this->table->fileNum("./Application/Data/feedbackTemp"),
));
}
//删除runtime文件夹
public function del_runtime() {
$dir = "./Application/Runtime/";
$this->del_dir($dir);
$this->success(array(
"complete"=>1,
"num"=>4,
));
}
protected function del_dir($dir){
$dh=opendir($dir);
while ($file=readdir($dh)) {
if($file!="." && $file!="..") {
$fullpath=$dir."/".$file;
if(!is_dir($fullpath)) {
@unlink($fullpath);
} else {
$this->del_dir($fullpath);
}
}
}
closedir($dh);
if(rmdir($dir)){
return true;
} else {
return false;
}
}
//写入文件
public function saveFile($filePath,$content){
\Think\Storage::put($filePath,$content,'html');
return
$fp = fopen($filePath,"w");
fwrite($fp,$content);
fclose($fp);
}
}