作者 刘锟

升级项目采集功能更新

@@ -8,6 +8,7 @@ use App\Models\Collect\CollectSource; @@ -8,6 +8,7 @@ use App\Models\Collect\CollectSource;
8 use App\Models\Collect\CollectTask; 8 use App\Models\Collect\CollectTask;
9 use App\Models\Com\UpdateLog; 9 use App\Models\Com\UpdateLog;
10 use App\Models\Com\UpdateOldInfo; 10 use App\Models\Com\UpdateOldInfo;
  11 +use App\Models\CustomModule\CustomModule;
11 use App\Models\CustomModule\CustomModuleContent; 12 use App\Models\CustomModule\CustomModuleContent;
12 use App\Models\News\News; 13 use App\Models\News\News;
13 use App\Models\Product\Product; 14 use App\Models\Product\Product;
@@ -90,12 +91,42 @@ class HtmlCollect extends Command @@ -90,12 +91,42 @@ class HtmlCollect extends Command
90 //采集html页面,下载资源到本地并替换 91 //采集html页面,下载资源到本地并替换
91 try { 92 try {
92 $html = curl_c('https://' . $collect_info->domain . $collect_info->route, false); 93 $html = curl_c('https://' . $collect_info->domain . $collect_info->route, false);
93 - if ($html == '0' || strpos($html, '404 Not Found') !== false) { 94 + if (strlen($html) < 4) {
94 $collect_info->status = CollectTask::STATUS_FAIL; 95 $collect_info->status = CollectTask::STATUS_FAIL;
95 $collect_info->save(); 96 $collect_info->save();
96 97
97 - $error = $html == '0' ? 'no html' : '404 not found';  
98 - echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', collect_id: ' . $collect_id . ', error: ' . $error . PHP_EOL; 98 + if ($html == 404) {
  99 + //原数据页面404,需要将6.0数据存入草稿箱
  100 + switch ($collect_info->source) {
  101 + //产品
  102 + case RouteMap::SOURCE_PRODUCT:
  103 + $model = new Product();
  104 + $status_draft = Product::STATUS_DRAFT;
  105 + break;
  106 + //博客
  107 + case RouteMap::SOURCE_BLOG:
  108 + $model = new Blog();
  109 + $status_draft = Blog::STATUS_DRAFT;
  110 + break;
  111 + //新闻
  112 + case RouteMap::SOURCE_NEWS:
  113 + $model = new News();
  114 + $status_draft = News::STATUS_DRAFT;
  115 + break;
  116 + //自定义模块详情
  117 + case RouteMap::SOURCE_MODULE:
  118 + $model = new CustomModule();
  119 + $status_draft = CustomModule::STATUS_DRAFT;
  120 + break;
  121 + default:
  122 + //单页详情
  123 + $model = new BCustomTemplate();
  124 + $status_draft = BCustomTemplate::STATUS_DRAFT;
  125 + }
  126 + $model->edit(['status' => $status_draft], ['project_id' => $project_id, 'id' => $collect_info->source_id]);
  127 + }
  128 +
  129 + echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', collect_id: ' . $collect_id . ', error: ' . $html . PHP_EOL;
99 sleep(2); 130 sleep(2);
100 return true; 131 return true;
101 } 132 }
@@ -101,7 +101,7 @@ class ProjectUpdate extends Command @@ -101,7 +101,7 @@ class ProjectUpdate extends Command
101 $language_list = []; 101 $language_list = [];
102 $url_language = 'https://' . $domain_arr['host'] . '/wp-content/plugins/proofreading/json/user_language.json'; 102 $url_language = 'https://' . $domain_arr['host'] . '/wp-content/plugins/proofreading/json/user_language.json';
103 $data_language = curl_c($url_language); 103 $data_language = curl_c($url_language);
104 - if ($data_language) { 104 + if (is_array($data_language)) {
105 $language_list = array_column($data_language, 'short'); 105 $language_list = array_column($data_language, 'short');
106 } 106 }
107 107
@@ -109,7 +109,7 @@ class ProjectUpdate extends Command @@ -109,7 +109,7 @@ class ProjectUpdate extends Command
109 $page_list = []; 109 $page_list = [];
110 $url_page = 'https://' . $domain_arr['host'] . '/wp-content/cache/pages_list.json'; 110 $url_page = 'https://' . $domain_arr['host'] . '/wp-content/cache/pages_list.json';
111 $data_page = curl_c($url_page); 111 $data_page = curl_c($url_page);
112 - if ($data_page) { 112 + if (is_array($data_page)) {
113 $page_list = array_column($data_page, 'path'); 113 $page_list = array_column($data_page, 'path');
114 } 114 }
115 115
@@ -146,8 +146,14 @@ if (!function_exists('curl_c')) { @@ -146,8 +146,14 @@ if (!function_exists('curl_c')) {
146 curl_setopt($ch, CURLOPT_SSLVERSION, 'all'); 146 curl_setopt($ch, CURLOPT_SSLVERSION, 'all');
147 curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 147 curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
148 $content = curl_exec($ch); 148 $content = curl_exec($ch);
  149 + $http_code = curl_getinfo($ch,CURLINFO_HTTP_CODE);
149 curl_close($ch); 150 curl_close($ch);
150 - return $is_array ? json_decode($content, true) : $content; 151 +
  152 + if($http_code == 200){
  153 + return $is_array ? json_decode($content, true) : $content;
  154 + }else{
  155 + return $http_code;
  156 + }
151 } 157 }
152 } 158 }
153 159
@@ -7,6 +7,7 @@ use App\Models\User\User; @@ -7,6 +7,7 @@ use App\Models\User\User;
7 7
8 class Blog extends Base 8 class Blog extends Base
9 { 9 {
  10 + const STATUS_DRAFT = 0;
10 const STATUS_ONE = 1; 11 const STATUS_ONE = 1;
11 protected $table = 'gl_blog'; 12 protected $table = 'gl_blog';
12 //连接数据库 13 //连接数据库
@@ -14,6 +14,8 @@ use App\Models\Module\ModuleCategory; @@ -14,6 +14,8 @@ use App\Models\Module\ModuleCategory;
14 14
15 class CustomModule extends Base 15 class CustomModule extends Base
16 { 16 {
  17 + const STATUS_DRAFT = 1;
  18 +
17 protected $table = 'gl_custom_module'; 19 protected $table = 'gl_custom_module';
18 //连接数据库 20 //连接数据库
19 protected $connection = 'custom_mysql'; 21 protected $connection = 'custom_mysql';
@@ -7,6 +7,7 @@ use App\Models\Base; @@ -7,6 +7,7 @@ use App\Models\Base;
7 7
8 class News extends Base 8 class News extends Base
9 { 9 {
  10 + const STATUS_DRAFT = 0;
10 const STATUS_ONE = 1; 11 const STATUS_ONE = 1;
11 12
12 protected $table = 'gl_news'; 13 protected $table = 'gl_news';
@@ -13,4 +13,5 @@ class BCustomTemplate extends Base @@ -13,4 +13,5 @@ class BCustomTemplate extends Base
13 const NOT_FOUND_PAGE_URL = '404'; 13 const NOT_FOUND_PAGE_URL = '404';
14 14
15 const STATUS_ACTIVE = 1; 15 const STATUS_ACTIVE = 1;
  16 + const STATUS_DRAFT = 0;
16 } 17 }