diff --git a/application/admin/controller/Ajax.php b/application/admin/controller/Ajax.php index dd58cf11..7a3d6e77 100644 --- a/application/admin/controller/Ajax.php +++ b/application/admin/controller/Ajax.php @@ -112,7 +112,6 @@ class Ajax extends Backend $this->success(__('Uploaded successful'), '', ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]); } - } /** @@ -187,25 +186,57 @@ class Ajax extends Backend */ public function wipecache() { - $type = $this->request->request("type"); - switch ($type) { - case 'all': - case 'content': - rmdirs(CACHE_PATH, false); - Cache::clear(); - if ($type == 'content') { - break; - } - case 'template': - rmdirs(TEMP_PATH, false); - if ($type == 'template') { - break; - } - case 'addons': - Service::refresh(); - if ($type == 'addons') { - break; - } + try { + $type = $this->request->request("type"); + switch ($type) { + case 'all': + // no break + case 'content': + //内容缓存 + rmdirs(CACHE_PATH, false); + Cache::clear(); + if ($type == 'content') { + break; + } + case 'template': + // 模板缓存 + rmdirs(TEMP_PATH, false); + if ($type == 'template') { + break; + } + case 'addons': + // 插件缓存 + Service::refresh(); + if ($type == 'addons') { + break; + } + case 'browser': + // 浏览器缓存 + // 只有生产环境下才修改 + if (1 || !config('app_debug')) { + $version = config('site.name'); + $version = '1.0.1'; + $newversion = preg_replace_callback("/(.*)\.([0-9]+)\$/", function ($match) { + return $match[1] . '.' . ($match[2] + 1); + }, $version); + if ($newversion && $newversion != $version) { + Db::startTrans(); + try { + \app\common\model\Config::where('name', 'version')->update(['value' => $newversion]); + \app\common\model\Config::refreshFile(); + Db::commit(); + } catch (\Exception $e) { + Db::rollback(); + exception($e->getMessage()); + } + } + } + if ($type == 'browser') { + break; + } + } + } catch (\Exception $e) { + $this->error($e->getMessage()); } \think\Hook::listen("wipecache_after"); diff --git a/application/admin/controller/general/Config.php b/application/admin/controller/general/Config.php index 8fd89441..f4b93e2a 100644 --- a/application/admin/controller/general/Config.php +++ b/application/admin/controller/general/Config.php @@ -99,7 +99,7 @@ class Config extends Backend } if ($result !== false) { try { - $this->refreshFile(); + ConfigModel::refreshFile(); } catch (Exception $e) { $this->error($e->getMessage()); } @@ -142,7 +142,7 @@ class Config extends Backend $this->error($e->getMessage()); } try { - $this->refreshFile(); + ConfigModel::refreshFile(); } catch (Exception $e) { $this->error($e->getMessage()); } @@ -163,7 +163,7 @@ class Config extends Backend if ($name && $config) { try { $config->delete(); - $this->refreshFile(); + ConfigModel::refreshFile(); } catch (Exception $e) { $this->error($e->getMessage()); } @@ -173,28 +173,6 @@ class Config extends Backend } } - /** - * 刷新配置文件 - */ - protected function refreshFile() - { - $config = []; - foreach ($this->model->all() as $k => $v) { - $value = $v->toArray(); - if (in_array($value['type'], ['selects', 'checkbox', 'images', 'files'])) { - $value['value'] = explode(',', $value['value']); - } - if ($value['type'] == 'array') { - $value['value'] = (array)json_decode($value['value'], true); - } - $config[$value['name']] = $value['value']; - } - file_put_contents( - CONF_PATH . 'extra' . DS . 'site.php', - ' '清除缓存失败', 'Wipe cache' => '清空缓存', 'Wipe all cache' => '一键清除缓存', - 'Wipe content cache' => '清空内容缓存', + 'Wipe content cache' => '清除内容缓存', 'Wipe template cache' => '清除模板缓存', 'Wipe addons cache' => '清除插件缓存', + 'Wipe browser cache' => '清除浏览器缓存', 'Check for updates' => '检测更新', 'Discover new version' => '发现新版本', 'Go to download' => '去下载更新', diff --git a/application/admin/view/common/header.html b/application/admin/view/common/header.html index a0ca7d66..aa3b3e33 100755 --- a/application/admin/view/common/header.html +++ b/application/admin/view/common/header.html @@ -39,6 +39,7 @@