RefreshCacheController.class.php
2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
* 系统设置-更新缓存
* 鲜彤 2016年08月02日18:10:25
*
* @update 2016-10-12 zhuxun37 修改调用方法;
* @update 2017-07-18 Deepseath 更改请求应用更新缓存的方式,旧的方法改名为 _Index()
*/
namespace Apicp\Controller\SysSetting;
use Com\Rpc;
use VcySDK\Service;
use VcySDK\EnterprisePlugin;
class RefreshCacheController extends AbstractController
{
public function Index()
{
// 按应用目录来获取
$handle = opendir(CODE_ROOT);
if (!$handle) {
return false;
}
while (false !== ($file = readdir($handle))) {
if ($file == '.' || $file == '..' || !is_dir(CODE_ROOT . DIRECTORY_SEPARATOR . $file)) {
// 忽略 “.”、“..”以及文件
continue;
}
// 构造应用对应的缓存清理文件
$clearCacheRpcFile = CODE_ROOT;
$clearCacheRpcFile .= DIRECTORY_SEPARATOR . $file;
$clearCacheRpcFile .= DIRECTORY_SEPARATOR . 'Rpc';
$clearCacheRpcFile .= DIRECTORY_SEPARATOR . 'Controller';
$clearCacheRpcFile .= DIRECTORY_SEPARATOR . 'Cache';
$clearCacheRpcFile .= DIRECTORY_SEPARATOR . 'ClearController.class.php';
if (!is_file($clearCacheRpcFile)) {
// 如果执行文件不存在,则忽略
continue;
}
$url = rpcUrl("/{$file}/Rpc/Cache/Clear");
// 请求对应 RPC
$rpc = Rpc::phprpc($url);
call_user_func(array($rpc, 'Index'));
}
closedir($handle);
return true;
}
/**
* 旧的(HR)缓存更新方式
* 备份
*/
protected function _Index()
{
// 获取安装的应用列表
$pluginSDK = new EnterprisePlugin(Service::instance());
$pluginList = $pluginSDK->listAll();
// RPC通知应用清除缓存
foreach ($pluginList as $_plugin) {
// 已安装的才清缓存
if ($pluginSDK->isInstall($_plugin['allowStatus'])) {
continue;
}
$identifier = ucfirst($_plugin['plIdentifier']);
$rpc = Rpc::phprpc($_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . '/' . QY_DOMAIN . '/' . $identifier . '/' . 'Rpc/Cache/Clear');
call_user_func(array($rpc, 'Index'));
}
return true;
}
}