You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.4 KiB

3 months ago
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\command;
  4. use think\console\Command;
  5. use think\console\Input;
  6. use think\console\input\Argument;
  7. use think\console\input\Option;
  8. use think\console\Output;
  9. use think\facade\Db;
  10. use think\facade\Config;
  11. use app\lib\Plugins;
  12. class Clean extends Command
  13. {
  14. protected function configure()
  15. {
  16. $this->setName('clean')
  17. ->setDescription('the clean command');
  18. }
  19. protected function execute(Input $input, Output $output)
  20. {
  21. $res = Db::name('config')->cache('configs',0)->column('value','key');
  22. Config::set($res, 'sys');
  23. if(config_get('bt_url')){
  24. $this->clean_plugins($input, $output, 'Linux');
  25. }
  26. if(config_get('wbt_url')){
  27. $this->clean_plugins($input, $output, 'Windows');
  28. }
  29. config_set('cleantime', date('Y-m-d H:i:s'));
  30. }
  31. private function clean_plugins(Input $input, Output $output, $os){
  32. $data_dir = get_data_dir($os) . 'plugins/';
  33. $file_list = [];
  34. $json_arr = Plugins::get_plugin_list($os);
  35. if(count($json_arr['list']) == 0) return;
  36. foreach($json_arr['list'] as $plugin){
  37. foreach($plugin['versions'] as $version){
  38. $ver = $version['m_version'].'.'.$version['version'];
  39. if(!isset($version['download'])){
  40. $file_list[] = $plugin['name'].'-'.$ver;
  41. }
  42. }
  43. }
  44. $count = 0;
  45. $dir = opendir($data_dir.'package');
  46. while(false !== ( $file = readdir($dir)) ) {
  47. if($file == '.' || $file == '..') continue;
  48. $name = str_replace('.zip', '', $file);
  49. if(!in_array($name, $file_list)){
  50. $filepath = $data_dir . 'package/' . $file;
  51. unlink($filepath);
  52. $count++;
  53. }
  54. }
  55. $output->writeln($os.'成功清理'.$count.'个历史版本插件包');
  56. $count = 0;
  57. $dir = opendir($data_dir.'folder');
  58. while(false !== ( $file = readdir($dir)) ) {
  59. if($file == '.' || $file == '..') continue;
  60. if(!in_array($file, $file_list)){
  61. $filepath = $data_dir . 'folder/' . $file;
  62. deleteDir($filepath);
  63. $count++;
  64. }
  65. }
  66. $output->writeln($os.'成功清理'.$count.'个历史版本插件目录');
  67. }
  68. }