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.

115 lines
4.4 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 month ago
2 years ago
1 month ago
2 years 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 UpdateAll extends Command
  13. {
  14. protected function configure()
  15. {
  16. $this->setName('updateall')
  17. ->setDescription('the updateall 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_type') && config_get('bt_url') || config_get('bt_type')==1 && config_get('bt_surl')){
  24. $this->process_plugins($input, $output, 'Linux');
  25. }
  26. if(!config_get('wbt_type') && config_get('wbt_url') || config_get('wbt_type')==1 && config_get('wbt_surl')){
  27. $this->process_plugins($input, $output, 'Windows');
  28. }
  29. if(!config_get('enbt_type') && config_get('enbt_url') || config_get('enbt_type')==1 && config_get('enbt_surl')){
  30. $this->process_plugins($input, $output, 'en');
  31. }
  32. config_set('runtime', date('Y-m-d H:i:s'));
  33. }
  34. private function process_plugins(Input $input, Output $output, $os){
  35. //刷新插件列表
  36. if(!$this->refresh_plugin_list($input, $output, $os)){
  37. return;
  38. }
  39. $count = 0;
  40. if($os=='Windows'){
  41. $type = intval(config_get('updateall_type_win'));
  42. }elseif($os=='en'){
  43. $type = intval(config_get('updateall_type_en'));
  44. }else{
  45. $type = intval(config_get('updateall_type'));
  46. }
  47. $json_arr = Plugins::get_plugin_list($os);
  48. //循环下载缺少的插件
  49. foreach($json_arr['list'] as $plugin){
  50. if($type == 0 && ($plugin['type']==8 || $plugin['type']==12) || $type == 1 && $plugin['type']==12 || $plugin['type']==10 || $plugin['type']==5) continue;
  51. foreach($plugin['versions'] as $version){
  52. $ver = $version['m_version'].'.'.$version['version'];
  53. if(isset($version['download'])){
  54. if(!file_exists(get_data_dir().'plugins/other/'.$version['download'])){
  55. if(!$this->download_plugin($input, $output, $plugin['name'], $ver, $os)){
  56. sleep(1);
  57. $this->download_plugin($input, $output, $plugin['name'], $ver, $os);
  58. }
  59. sleep(1);
  60. $count++;
  61. }
  62. }else{
  63. if(!file_exists(get_data_dir($os).'plugins/package/'.$plugin['name'].'-'.$ver.'.zip')){
  64. if(!$this->download_plugin($input, $output, $plugin['name'], $ver, $os)){
  65. sleep(1);
  66. $this->download_plugin($input, $output, $plugin['name'], $ver, $os);
  67. }
  68. sleep(1);
  69. $count++;
  70. }
  71. }
  72. }
  73. }
  74. $output->writeln($os.'本次成功下载'.$count.'个插件');
  75. }
  76. private function refresh_plugin_list(Input $input, Output $output, $os){
  77. try{
  78. Plugins::refresh_plugin_list($os);
  79. Db::name('log')->insert(['uid' => 1, 'action' => '刷新插件列表', 'data' => '刷新'.$os.'插件列表成功', 'addtime' => date("Y-m-d H:i:s")]);
  80. $output->writeln('刷新'.$os.'插件列表成功');
  81. return true;
  82. }catch(\Exception $e){
  83. $output->writeln($e->getMessage());
  84. errorlog($e->getMessage());
  85. return false;
  86. }
  87. }
  88. private function download_plugin(Input $input, Output $output, $plugin_name, $version, $os){
  89. $fullname = $plugin_name.'-'.$version;
  90. try{
  91. Plugins::download_plugin($plugin_name, $version, $os);
  92. Db::name('log')->insert(['uid' => 1, 'action' => '下载插件', 'data' => $fullname.' os:'.$os, 'addtime' => date("Y-m-d H:i:s")]);
  93. $output->writeln('下载'.$os.'插件: '.$fullname.' 成功');
  94. return true;
  95. }catch(\Exception $e){
  96. $output->writeln($fullname.' '.$e->getMessage());
  97. errorlog($fullname.' '.$e->getMessage());
  98. return false;
  99. }
  100. }
  101. }