ComposerUpdate

This commit is contained in:
Anyon 2019-11-01 18:13:53 +08:00
parent 28ae83eb43
commit bf6efadd19
3 changed files with 21 additions and 9 deletions

View File

@ -30,11 +30,13 @@ class Update extends Controller
*/ */
public function tree() public function tree()
{ {
$this->success('获取当前文件列表成功!', PlugsExtend::instance($this->app)->buildFileList([ $modules = PlugsExtend::instance($this->app)->buildFileList([
'think', 'app/admin', 'public/static', 'think', 'app/admin', 'public/static',
], [ ]);
dump($modules);
$this->success('获取当前文件列表成功!', $modules, [
'public/static/self' 'public/static/self'
])); ]);
} }
/** /**

View File

@ -147,13 +147,22 @@ class PlugsExtend
* 获取文件差异数据 * 获取文件差异数据
* @return array * @return array
*/ */
public function grenerateDifference($modules = []) public function grenerateDifference($modules = [], $data = [])
{ {
$this->modules = $modules; $this->modules = $modules;
$result = json_decode(HttpExtend::get("{$this->uri}?s=/admin/api.update/tree"), true); $result = json_decode(HttpExtend::get("{$this->uri}?s=/admin/api.update/tree"), true);
if (empty($result['code'])) return []; if (empty($result['code'])) return [];
$new = $this->buildFileList($result['data']['paths'], $result['data']['ignores']); $new = $this->buildFileList($result['data']['paths'], $result['data']['ignores']);
return $this->grenerateDifferenceContrast($result['data']['list'], $new['list']); foreach ($this->grenerateDifferenceContrast($result['data']['list'], $new['list']) as $file) {
if (in_array($file['type'], ['add', 'del', 'mod'])) {
foreach ($this->modules as $module) {
if (stripos($file['name'], $module) === 0) {
$data[] = $file;
}
}
}
}
return $data;
} }
/** /**
@ -194,7 +203,7 @@ class PlugsExtend
{ {
// 扫描规则文件 // 扫描规则文件
foreach ($paths as $key => $path) { foreach ($paths as $key => $path) {
$data = array_merge($data, $this->getFileList("{$this->path}{$path}")); $data = array_merge($data, $this->scanFileList(strtr("{$this->path}{$path}", '\\', '/')));
} }
// 清除忽略文件 // 清除忽略文件
foreach ($data as $key => $map) foreach ($ignores as $ingore) { foreach ($data as $key => $map) foreach ($ignores as $ingore) {
@ -209,11 +218,11 @@ class PlugsExtend
* @param array $data 扫描结果 * @param array $data 扫描结果
* @return array * @return array
*/ */
private function getFileList($path, $data = []) private function scanFileList($path, $data = [])
{ {
if (file_exists($path)) if (is_dir($path)) foreach (scandir($path) as $sub) { if (file_exists($path)) if (is_dir($path)) foreach (scandir($path) as $sub) {
if (strpos($sub, '.') !== 0) if (is_dir($temp = "{$path}/{$sub}")) { if (strpos($sub, '.') !== 0) if (is_dir($temp = "{$path}/{$sub}")) {
$data = array_merge($data, $this->getFileList($temp)); $data = array_merge($data, $this->scanFileList($temp));
} else { } else {
array_push($data, $this->getFileInfo($temp)); array_push($data, $this->getFileInfo($temp));
} }
@ -231,8 +240,8 @@ class PlugsExtend
private function getFileInfo($filename) private function getFileInfo($filename)
{ {
return [ return [
'name' => str_replace($this->path, '', $filename),
'hash' => md5(preg_replace('/\s+/', '', file_get_contents($filename))), 'hash' => md5(preg_replace('/\s+/', '', file_get_contents($filename))),
'name' => strtr(strtr(realpath($filename), '\\', '/'), $this->path, ''),
]; ];
} }
} }

View File

@ -33,6 +33,7 @@ class Plugs extends Command
} }
} }
} }
dump($data);
if (empty($data)) { if (empty($data)) {
$output->info('--- 本地文件与线上文件一致,无需更新文件'); $output->info('--- 本地文件与线上文件一致,无需更新文件');
} else { } else {