作者 刘锟

升级项目采集功能更新

... ... @@ -8,6 +8,7 @@ use App\Models\Collect\CollectSource;
use App\Models\Collect\CollectTask;
use App\Models\Com\UpdateLog;
use App\Models\Com\UpdateOldInfo;
use App\Models\CustomModule\CustomModule;
use App\Models\CustomModule\CustomModuleContent;
use App\Models\News\News;
use App\Models\Product\Product;
... ... @@ -90,12 +91,42 @@ class HtmlCollect extends Command
//采集html页面,下载资源到本地并替换
try {
$html = curl_c('https://' . $collect_info->domain . $collect_info->route, false);
if ($html == '0' || strpos($html, '404 Not Found') !== false) {
if (strlen($html) < 4) {
$collect_info->status = CollectTask::STATUS_FAIL;
$collect_info->save();
$error = $html == '0' ? 'no html' : '404 not found';
echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', collect_id: ' . $collect_id . ', error: ' . $error . PHP_EOL;
if ($html == 404) {
//原数据页面404,需要将6.0数据存入草稿箱
switch ($collect_info->source) {
//产品
case RouteMap::SOURCE_PRODUCT:
$model = new Product();
$status_draft = Product::STATUS_DRAFT;
break;
//博客
case RouteMap::SOURCE_BLOG:
$model = new Blog();
$status_draft = Blog::STATUS_DRAFT;
break;
//新闻
case RouteMap::SOURCE_NEWS:
$model = new News();
$status_draft = News::STATUS_DRAFT;
break;
//自定义模块详情
case RouteMap::SOURCE_MODULE:
$model = new CustomModule();
$status_draft = CustomModule::STATUS_DRAFT;
break;
default:
//单页详情
$model = new BCustomTemplate();
$status_draft = BCustomTemplate::STATUS_DRAFT;
}
$model->edit(['status' => $status_draft], ['project_id' => $project_id, 'id' => $collect_info->source_id]);
}
echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', collect_id: ' . $collect_id . ', error: ' . $html . PHP_EOL;
sleep(2);
return true;
}
... ...
... ... @@ -101,7 +101,7 @@ class ProjectUpdate extends Command
$language_list = [];
$url_language = 'https://' . $domain_arr['host'] . '/wp-content/plugins/proofreading/json/user_language.json';
$data_language = curl_c($url_language);
if ($data_language) {
if (is_array($data_language)) {
$language_list = array_column($data_language, 'short');
}
... ... @@ -109,7 +109,7 @@ class ProjectUpdate extends Command
$page_list = [];
$url_page = 'https://' . $domain_arr['host'] . '/wp-content/cache/pages_list.json';
$data_page = curl_c($url_page);
if ($data_page) {
if (is_array($data_page)) {
$page_list = array_column($data_page, 'path');
}
... ...
... ... @@ -146,8 +146,14 @@ if (!function_exists('curl_c')) {
curl_setopt($ch, CURLOPT_SSLVERSION, 'all');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$content = curl_exec($ch);
$http_code = curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_close($ch);
return $is_array ? json_decode($content, true) : $content;
if($http_code == 200){
return $is_array ? json_decode($content, true) : $content;
}else{
return $http_code;
}
}
}
... ...
... ... @@ -7,6 +7,7 @@ use App\Models\User\User;
class Blog extends Base
{
const STATUS_DRAFT = 0;
const STATUS_ONE = 1;
protected $table = 'gl_blog';
//连接数据库
... ...
... ... @@ -14,6 +14,8 @@ use App\Models\Module\ModuleCategory;
class CustomModule extends Base
{
const STATUS_DRAFT = 1;
protected $table = 'gl_custom_module';
//连接数据库
protected $connection = 'custom_mysql';
... ...
... ... @@ -7,6 +7,7 @@ use App\Models\Base;
class News extends Base
{
const STATUS_DRAFT = 0;
const STATUS_ONE = 1;
protected $table = 'gl_news';
... ...
... ... @@ -13,4 +13,5 @@ class BCustomTemplate extends Base
const NOT_FOUND_PAGE_URL = '404';
const STATUS_ACTIVE = 1;
const STATUS_DRAFT = 0;
}
... ...