181 lines
4.8 KiB
PHP
181 lines
4.8 KiB
PHP
<?php
|
|
defined('IN_MET') or exit ('No permission');
|
|
|
|
load::sys_func('file');
|
|
|
|
class uninstall
|
|
{
|
|
|
|
private $appno; //应用NO值
|
|
private $m_name; //应用文件夹
|
|
private $del_dirs = []; //需要删除的文件夹,以根目录为准
|
|
|
|
public function __construct()
|
|
{
|
|
global $_M;
|
|
|
|
$this->appno = $_M['form']['no']; //获取NO
|
|
|
|
//需要删除的文件名
|
|
$this->del_dirs[] = self::firstsql();
|
|
$this->del_dirs[] = $this->m_name ? 'app/app/' . $this->m_name : '';
|
|
|
|
//判断是否允许卸载
|
|
if (file_exists(PATH_ALL_APP . $this->m_name . "/config/uninstall.lock")) {
|
|
turnover("{$_M['url']['own_form']}a=doindex", "禁止卸载");
|
|
}
|
|
|
|
}
|
|
|
|
public function dodel()
|
|
{
|
|
global $_M;
|
|
//删除一些提前删除的内容
|
|
|
|
//删除自定义表
|
|
self::zdysql();
|
|
|
|
//删除固定的app表
|
|
self::appsql();
|
|
|
|
//删除应用文件
|
|
// $this->delfile();
|
|
}
|
|
|
|
//优先执行代码[推荐]
|
|
private function firstsql()
|
|
{
|
|
global $_M;
|
|
//查询应用的文件夹
|
|
$mname = self::sqlone('applist');
|
|
$this->m_name = $mname['m_name'];
|
|
//查询应用是否使用栏目
|
|
$file = self::sqlone('column', " module='{$this->appno}' ");
|
|
return $file['foldername'];
|
|
}
|
|
|
|
//删除自定义表
|
|
private function zdysql()
|
|
{
|
|
global $_M;
|
|
//公用表
|
|
$cloud = ['cloud_config'];
|
|
//自定义表
|
|
$table = file_get_contents(PATH_ALL_APP . $this->m_name . '/config/table');
|
|
$table = stringto_array($table, ',');
|
|
//自定义表删除
|
|
$zdy = array_diff($table, $cloud);
|
|
$zdys = [];
|
|
foreach ($zdy as $val) {
|
|
$zdys[] = $this->m_name . '_' . $val;
|
|
}
|
|
//删除公用表对应应用数据,并查询是否符合删除表的要求
|
|
foreach ($cloud as $val) {
|
|
//判断是否要删除
|
|
if (in_array($val, $table)) $zdys[] = self::cloud($val);
|
|
}
|
|
//删除表
|
|
foreach ($zdys as $val) {
|
|
self::deltablesql($val);
|
|
}
|
|
//删除配置文件
|
|
del_table(arrayto_string($zdys, '|'));
|
|
}
|
|
|
|
//删除固定的app表
|
|
private function appsql()
|
|
{
|
|
global $_M;
|
|
//删除栏目接口表
|
|
self::delsql('ifcolumn');
|
|
|
|
//删除应用生成文件所调用事件的信息表
|
|
self::delsql('ifcolumn_addfile');
|
|
|
|
//删除会员侧导航信息表
|
|
self::delsql('ifmember_left');
|
|
|
|
//删除应用插件表
|
|
self::delsql('app_plugin');
|
|
|
|
//删除网站后台栏目信息表
|
|
$where = "field='{$this->appno}'";
|
|
self::delsql('admin_column', $where);
|
|
|
|
//删除网站栏目信息表
|
|
$where = "module='{$this->appno}'";
|
|
self::delsql('column', $where);
|
|
|
|
//删除语言表
|
|
$where = "app='{$this->appno}'";
|
|
self::delsql('language', $where);
|
|
|
|
//删除应用注册表
|
|
self::delsql('applist');
|
|
}
|
|
|
|
//删除应用文件夹
|
|
private function delfile()
|
|
{
|
|
foreach ($this->del_dirs as $dir) {
|
|
if (file_exists(PATH_WEB . $dir) && $dir != null) deldir(PATH_WEB . $dir);
|
|
}
|
|
}
|
|
|
|
//对公用配置表卸载处理
|
|
private function cloud($tname)
|
|
{
|
|
global $_M;
|
|
$where = "m_name='{$this->m_name}'";
|
|
if (self::sqlcounter($tname, $where) > 0) {
|
|
self::delsql($tname, $where);
|
|
}
|
|
if (self::sqlcounter($tname) == 0) {
|
|
return $tname;
|
|
}
|
|
}
|
|
|
|
//公共查询方法
|
|
private function sqlone($tname, $where = '')
|
|
{
|
|
global $_M;
|
|
$table = $_M['table'][ $tname ];
|
|
if (!$where) {
|
|
$where = "no='{$this->appno}'";
|
|
}
|
|
return DB::get_one("select * from {$table} where {$where}");
|
|
}
|
|
|
|
//公共查询方法
|
|
private function sqlcounter($tname, $where = '')
|
|
{
|
|
global $_M;
|
|
$table = $_M['table'][ $tname ];
|
|
if ($where) {
|
|
$where = 'WHERE ' . $where;
|
|
}
|
|
return DB::counter("{$table} {$where}");
|
|
}
|
|
|
|
//公共删除数据
|
|
private function delsql($tname, $where = '')
|
|
{
|
|
global $_M;
|
|
$table = $_M['table'][ $tname ];
|
|
if (!$where) {
|
|
$where = "no='{$this->appno}'";
|
|
}
|
|
DB::query("DELETE FROM {$table} WHERE {$where}");
|
|
}
|
|
|
|
//公共删除表
|
|
private function deltablesql($tname)
|
|
{
|
|
global $_M;
|
|
$table = $_M['table'][ $tname ];
|
|
DB::query("DROP TABLE `{$table}`");
|
|
}
|
|
|
|
}
|
|
|
|
?>
|