作者 刘锟

合并分支 'akun' 到 'master'

Akun



查看合并请求 !138
@@ -9,6 +9,7 @@ use App\Models\RouteMap\RouteMap; @@ -9,6 +9,7 @@ use App\Models\RouteMap\RouteMap;
9 use App\Services\CosService; 9 use App\Services\CosService;
10 use App\Services\ProjectServer; 10 use App\Services\ProjectServer;
11 use Illuminate\Console\Command; 11 use Illuminate\Console\Command;
  12 +use Illuminate\Support\Facades\Cache;
12 use Illuminate\Support\Facades\DB; 13 use Illuminate\Support\Facades\DB;
13 use Illuminate\Support\Facades\Redis; 14 use Illuminate\Support\Facades\Redis;
14 15
@@ -38,14 +39,15 @@ class HtmlCollect extends Command @@ -38,14 +39,15 @@ class HtmlCollect extends Command
38 39
39 public function handle() 40 public function handle()
40 { 41 {
41 - while (true) { 42 +// while (true) {
42 $this->start_collect(); 43 $this->start_collect();
43 - } 44 +// }
44 } 45 }
45 46
46 protected function start_collect() 47 protected function start_collect()
47 { 48 {
48 - $task_id = $this->get_task(); 49 +// $task_id = $this->get_task();
  50 + $task_id = '543_1';
49 if ($task_id === false) { 51 if ($task_id === false) {
50 //所有项目采集完成 52 //所有项目采集完成
51 sleep(60); 53 sleep(60);
@@ -76,26 +78,12 @@ class HtmlCollect extends Command @@ -76,26 +78,12 @@ class HtmlCollect extends Command
76 $collect_info->save(); 78 $collect_info->save();
77 79
78 //获取站点正式和测试域名 80 //获取站点正式和测试域名
79 - $web_url_domain = $collect_info->domain;  
80 - $home_url = $collect_info->domain;  
81 - $url_web_config = 'https://' . $collect_info->domain . '/wp-content/cache/user_config.text';  
82 - $data_config = curl_c($url_web_config);  
83 - if ($data_config) {  
84 - $web_url_arr = parse_url($data_config['web_url_domain'] ?? '');  
85 - if (isset($web_url_arr['host'])) {  
86 - $web_url_domain = $web_url_arr['host'];  
87 - }  
88 -  
89 - $home_url_arr = parse_url($data_config['home_url'] ?? '');  
90 - if (isset($home_url_arr['host'])) {  
91 - $home_url = $home_url_arr['host'];  
92 - }  
93 - } 81 + $old_info = $this->getOldDomain($project_id, $collect_info->domain);
94 82
95 //采集html页面,下载资源到本地并替换 83 //采集html页面,下载资源到本地并替换
96 try { 84 try {
97 $html = curl_c('https://' . $collect_info->domain . $collect_info->route, false); 85 $html = curl_c('https://' . $collect_info->domain . $collect_info->route, false);
98 - if($html == '0'){ 86 + if ($html == '0') {
99 $collect_info->status = CollectTask::STATUS_FAIL; 87 $collect_info->status = CollectTask::STATUS_FAIL;
100 $collect_info->save(); 88 $collect_info->save();
101 echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', collect_id: ' . $collect_id . ', error: no html' . PHP_EOL; 89 echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', collect_id: ' . $collect_id . ', error: no html' . PHP_EOL;
@@ -103,7 +91,7 @@ class HtmlCollect extends Command @@ -103,7 +91,7 @@ class HtmlCollect extends Command
103 return true; 91 return true;
104 } 92 }
105 93
106 - $source_list = $this->html_preg($html, $project_id, $collect_info->domain, $web_url_domain, $home_url); 94 + $source_list = $this->html_preg($html, $project_id, $collect_info->domain, $old_info['web_url_domain'], $old_info['home_url']);
107 95
108 if ($source_list) { 96 if ($source_list) {
109 $html = $this->upload_source($html, $source_list, $project_id); 97 $html = $this->upload_source($html, $source_list, $project_id);
@@ -187,6 +175,42 @@ class HtmlCollect extends Command @@ -187,6 +175,42 @@ class HtmlCollect extends Command
187 return $task_id; 175 return $task_id;
188 } 176 }
189 177
  178 + //获取站点老域名
  179 + protected function getOldDomain($project_id, $domain)
  180 + {
  181 + $key = 'project_collect_domain_' . $project_id;
  182 +
  183 + $data = Cache::get($key);
  184 +
  185 + if (!$data) {
  186 + $web_url_domain = $domain;
  187 + $home_url = $domain;
  188 +
  189 + $url_web_config = 'https://' . $domain . '/wp-content/cache/user_config.text';
  190 + $data_config = curl_c($url_web_config);
  191 + if ($data_config) {
  192 + $web_url_arr = parse_url($data_config['web_url_domain'] ?? '');
  193 + if (isset($web_url_arr['host'])) {
  194 + $web_url_domain = $web_url_arr['host'];
  195 + }
  196 +
  197 + $home_url_arr = parse_url($data_config['home_url'] ?? '');
  198 + if (isset($home_url_arr['host'])) {
  199 + $home_url = $home_url_arr['host'];
  200 + }
  201 + }
  202 +
  203 + $data = [
  204 + 'web_url_domain' => $web_url_domain,
  205 + 'home_url' => $home_url,
  206 + ];
  207 +
  208 + Cache::add($key, $data, 3600);//缓存1小时
  209 + }
  210 +
  211 + return $data;
  212 + }
  213 +
190 //正则匹配html资源 214 //正则匹配html资源
191 protected function html_preg($html, $project_id, $domain, $web_url_domain, $home_url) 215 protected function html_preg($html, $project_id, $domain, $web_url_domain, $home_url)
192 { 216 {
@@ -319,7 +343,7 @@ class HtmlCollect extends Command @@ -319,7 +343,7 @@ class HtmlCollect extends Command
319 continue; 343 continue;
320 } 344 }
321 $path_arr = explode('.', $vcs); 345 $path_arr = explode('.', $vcs);
322 - if(end($path_arr) == 'html'){ 346 + if (end($path_arr) == 'html') {
323 continue; 347 continue;
324 } 348 }
325 349