|
...
|
...
|
@@ -41,14 +41,12 @@ class ProjectUpdateTemp extends Command |
|
|
|
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
while (true) {
|
|
|
|
$this->start_update();
|
|
|
|
}
|
|
|
|
$this->start_update();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function start_update()
|
|
|
|
{
|
|
|
|
$list = UpdateLog::where('api_type', 'category')->get();
|
|
|
|
$list = UpdateLog::where('api_type', 'post')->get();
|
|
|
|
|
|
|
|
foreach ($list as $task) {
|
|
|
|
|
|
...
|
...
|
@@ -62,45 +60,6 @@ class ProjectUpdateTemp extends Command |
|
|
|
|
|
|
|
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update start' . PHP_EOL;
|
|
|
|
|
|
|
|
$task->status = UpdateLog::STATUS_ING;//同步中
|
|
|
|
$task->save();
|
|
|
|
|
|
|
|
$domain_arr = parse_url($api_url);
|
|
|
|
//获取网站配置
|
|
|
|
$link_type = 0;
|
|
|
|
$web_url_domain = $domain_arr['host'];
|
|
|
|
$home_url = $domain_arr['host'];
|
|
|
|
$url_web_config = 'https://' . $domain_arr['host'] . '/wp-content/cache/user_config.text';
|
|
|
|
$data_config = curl_c($url_web_config);
|
|
|
|
if ($data_config) {
|
|
|
|
$link_type = $data_config['link_type'] ?? 0;
|
|
|
|
|
|
|
|
$web_url_arr = parse_url($data_config['web_url_domain'] ?? '');
|
|
|
|
if (isset($web_url_arr['host'])) {
|
|
|
|
$web_url_domain = $web_url_arr['host'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$home_url_arr = parse_url($data_config['home_url'] ?? '');
|
|
|
|
if (isset($home_url_arr['host'])) {
|
|
|
|
$home_url = $home_url_arr['host'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//获取所有语种
|
|
|
|
$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) {
|
|
|
|
$language_list = array_column($data_language, 'short');
|
|
|
|
}
|
|
|
|
//获取所有页面
|
|
|
|
$page_list = [];
|
|
|
|
$url_page = 'https://' . $domain_arr['host'] . '/wp-content/cache/pages_list.json';
|
|
|
|
$data_page = curl_c($url_page);
|
|
|
|
if ($data_page) {
|
|
|
|
$page_list = array_column($data_page, 'path');
|
|
|
|
}
|
|
|
|
|
|
|
|
$is_flush = 0;
|
|
|
|
//设置数据库
|
|
|
|
$project = ProjectServer::useProject($project_id);
|
|
|
|
if ($project) {
|
|
...
|
...
|
@@ -136,53 +95,7 @@ class ProjectUpdateTemp extends Command |
|
|
|
$route = $this->get_url_route($item['url'] ?? '');
|
|
|
|
if ($route) {
|
|
|
|
$product = $model->read(['route' => $route], 'id');
|
|
|
|
if (!$product) {
|
|
|
|
//图片
|
|
|
|
$gallery = [];
|
|
|
|
if ($item['images'] ?? []) {
|
|
|
|
foreach ($item['images'] as $k_img => $img) {
|
|
|
|
$gallery[] = ['alt' => '这是一张产品图', 'url' => $this->source_download($img, $project_id, $domain_arr['host'], $web_url_domain, $home_url)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//分类
|
|
|
|
$category_id = '';
|
|
|
|
if ($item['category'] ?? []) {
|
|
|
|
$category_arr = $category_model->list(['original_id' => ['in', array_column($item['category'], 'id')]]);
|
|
|
|
$category_id = $logic->getLastCategory(array_column($category_arr, 'id'));
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
$item['ttile'] = $this->special2str($item['ttile'] ?? '');
|
|
|
|
$id = $model->insertGetId([
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'title' => $item['ttile'],
|
|
|
|
'intro' => $item['short_description'] ?? '',
|
|
|
|
'content' => $item['content'] ?? '',
|
|
|
|
'category_id' => $category_id,
|
|
|
|
'thumb' => isset($gallery[0]) ? Arr::a2s($gallery[0]) : '',
|
|
|
|
'gallery' => Arr::a2s($gallery),
|
|
|
|
'seo_mate' => Arr::a2s([
|
|
|
|
'title' => $item['ttile'],
|
|
|
|
'keyword' => $item['keywords'] ?? '',
|
|
|
|
'description' => $item['description'] ?? ''
|
|
|
|
]),
|
|
|
|
'status' => Product::STATUS_ON,
|
|
|
|
'created_at' => $item['post_date'] ?? date('Y-m-d H:i:s'),
|
|
|
|
'updated_at' => $item['post_date'] ?? date('Y-m-d H:i:s'),
|
|
|
|
'sort' => $item['sort'] ?? 0,
|
|
|
|
'is_upgrade' => 1,
|
|
|
|
'six_read' => 1,
|
|
|
|
'route' => $route
|
|
|
|
]);
|
|
|
|
$this->set_map($route, RouteMap::SOURCE_PRODUCT, $id, $project_id);
|
|
|
|
|
|
|
|
CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT, $id, $link_type, $language_list, $page_list);
|
|
|
|
|
|
|
|
$is_flush = 1;
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($product) {
|
|
|
|
$category_id = '';
|
|
|
|
if ($item['category'] ?? []) {
|
|
|
|
$category_arr = $category_model->list(['original_id' => ['in', array_column($item['category'], 'id')]]);
|
|
...
|
...
|
@@ -203,12 +116,6 @@ class ProjectUpdateTemp extends Command |
|
|
|
//关闭数据库
|
|
|
|
DB::disconnect('custom_mysql');
|
|
|
|
|
|
|
|
$task->status = UpdateLog::STATUS_COM;//同步完成
|
|
|
|
if ($is_flush) {
|
|
|
|
$task->collect_status = UpdateLog::COLLECT_STATUS_UN;
|
|
|
|
}
|
|
|
|
$task->save();
|
|
|
|
|
|
|
|
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update end ' . PHP_EOL;
|
|
|
|
|
|
|
|
sleep(2);
|
|
...
|
...
|
@@ -315,45 +222,4 @@ class ProjectUpdateTemp extends Command |
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//资源下载
|
|
|
|
protected function source_download($url, $project_id, $domain, $web_url_domain, $home_url)
|
|
|
|
{
|
|
|
|
if (!$url) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$arr = parse_url($url);
|
|
|
|
$scheme = $arr['scheme'] ?? '';
|
|
|
|
$host = $arr['host'] ?? '';
|
|
|
|
$path = $arr['path'] ?? '';
|
|
|
|
|
|
|
|
$url_complete = ($scheme ?: 'https') . '://' . ($host ?: $domain) . $path;
|
|
|
|
|
|
|
|
if ((empty($host) || $host == $web_url_domain || $host == $home_url) && $path) {
|
|
|
|
|
|
|
|
$source = CollectSource::where('project_id', $project_id)->where('origin', $url)->first();
|
|
|
|
if (!$source) {
|
|
|
|
$new_url = CosService::uploadRemote($project_id, 'image_product', $url_complete);
|
|
|
|
|
|
|
|
if ($new_url) {
|
|
|
|
CollectSource::insert([
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'origin' => $url,
|
|
|
|
'target' => $new_url,
|
|
|
|
'created_at' => date('Y-m-d H:i:s'),
|
|
|
|
'updated_at' => date('Y-m-d H:i:s'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
return getImageUrl($new_url);
|
|
|
|
} else {
|
|
|
|
return $url_complete;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return getImageUrl($source['target']);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return $url_complete;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|